public void WhenGetCalled_ThenReturnsSuperPerson() { // Arrange var superPerson = new SuperPerson() { Id = 1, Name = "Name1" }; // Note: Moq example of an mocking a method that takes an argument and returns a value // Note: Castle-proxy is under each mock => requires interface or virtual var mockContext = new Mock <ISuperDatabaseContext>(); mockContext.Setup(x => x.SuperPeople.Find(1)).Returns(superPerson); ISuperDatabaseContext context = mockContext.Object; SuperRepository target = new SuperRepository(context); // Act var actual = target.Get(1); // Assert Assert.AreSame(superPerson, actual); mockContext.Verify(x => x.SuperPeople.Find(1), Times.Once()); }
public void WhenGetCalledWithIdLessThanOne_ThenThrows() { // Arrange var mockContext = new Mock <ISuperDatabaseContext>(); ISuperDatabaseContext context = mockContext.Object; SuperRepository target = new SuperRepository(context); // Act target.Get(0); // Assert }