public async Task AddOrUpdatePerson_GivenPerson_ShouldReturnPersonCorrectly() { // Arrange using (PeopleSearchDbContext testContext = GetTestContext()) { Person expected = TestData.TestPerson1(); PersonRepository repository = new PersonRepository(testContext); // Act Person actual = await repository.AddOrUpdatePerson(expected); // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); } }
public async Task GetByIdAsync_GivenNoPeopleExist_ShouldReturnNull() { // Arrange using (PeopleSearchDbContext testContext = GetTestContext()) { PersonRepository repository = new PersonRepository(testContext); Person expected = null; // Act Person actual = await repository.GetByIdAsync(0); // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); } }
public async Task PostAsync_GivenRepositoryReturnsNull_ShouldReturnNull() { // Arrange Person matching = null; Person expected = null; Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Loose); mockPersonRepository.Setup(r => r.AddPersonAsync(It.IsAny <Person>())).ReturnsAsync(matching); PeopleController controller = new PeopleController(mockPersonRepository.Object); // Act Person actual = (await controller.PostAsync(TestData.TestPerson1())).Value; // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); }
public async Task PutAsync_GivenPersonExists_ShouldReturnPersonCorrectly() { // Arrange Person person = TestData.TestPerson1(); Person matching = person; Person expected = person; Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Loose); mockPersonRepository.Setup(r => r.AddOrUpdatePerson(It.IsAny <Person>())).ReturnsAsync(matching); PeopleController controller = new PeopleController(mockPersonRepository.Object); // Act Person actual = (await controller.PutAsync(matching)).Value; // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); }
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_GivenNonMatchingId_ShouldReturnNull() { // Arrange using (PeopleSearchDbContext testContext = GetTestContext()) { Person expected = null; testContext.People.Add(TestData.TestPerson1()); testContext.People.Add(TestData.TestPerson2()); await testContext.SaveChangesAsync(); PersonRepository repository = new PersonRepository(testContext); // Act Person actual = await repository.GetByIdAsync(123); // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); } }
public async Task GetByIdAsync_GivenPersonExists_ShouldReturnPersonCorrectly() { // Arrange using (PeopleSearchDbContext testContext = GetTestContext()) { Person added = TestData.TestPerson1(); Person expected = added; testContext.People.Add(added); await testContext.SaveChangesAsync(); PersonRepository repository = new PersonRepository(testContext); // Act Person actual = await repository.GetByIdAsync(expected.Id); // Assert ModelComparisonHelper.AssertPeopleAreEqual(expected, actual); } }