public async Task GetByIdAsync_GivenId_ShouldCallRepositoryCorrectly() { // Arrange Person matching = new Person(); long expected = 0; Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Strict); mockPersonRepository.Setup(r => r.GetByIdAsync(expected)).ReturnsAsync(matching); PeopleController controller = new PeopleController(mockPersonRepository.Object); // Act await controller.GetByIdAsync(expected); // Assert mockPersonRepository.VerifyAll(); }
public async Task GetByIdAsync_GivenPersonDoesNotExist_ShouldReturnNull() { // Arrange Person matching = null; Person expected = null; long id = 0; Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Loose); mockPersonRepository.Setup(r => r.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(matching); PeopleController controller = new PeopleController(mockPersonRepository.Object); // Act Person actual = (await controller.GetByIdAsync(id)).Value; // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); }
public async Task GetByIdAsync_GivenPersonExists_ShouldReturnPersonCorrectly() { // Arrange Person person = TestData.TestPerson1(); Person matching = person; Person expected = person; long id = 0; Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Loose); mockPersonRepository.Setup(r => r.GetByIdAsync(It.IsAny <long>())).ReturnsAsync(matching); PeopleController controller = new PeopleController(mockPersonRepository.Object); // Act Person actual = (await controller.GetByIdAsync(id)).Value; // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); }