Exemple #1
0
        public async Task GetAsync_GivenMatchingSearchString_ShouldReturnPeopleCorrectly()
        {
            // Arrange
            Person        person1  = TestData.TestPerson1();
            Person        person2  = TestData.TestPerson2();
            List <Person> matching = new List <Person> {
                person1, person2
            };
            List <Person> expected = new List <Person> {
                person1, person2
            };

            Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Loose);

            mockPersonRepository.Setup(r => r.SearchPeopleAsync(It.IsAny <string>())).ReturnsAsync(matching);

            Mock <ILatencySimulator> mockLatencySimulator = new Mock <ILatencySimulator>(MockBehavior.Loose);

            PeopleController controller = new PeopleController(mockPersonRepository.Object);

            // Act
            List <Person> actual = (await controller.GetAsync("someString")).Value.ToList();

            // Assert
            ModelComparisonHelper.AssertPersonListsAreEqual(expected, actual);
        }
Exemple #2
0
        public async Task GetAsync_GivenNoPeopleExist_ShouldReturnEmptyList()
        {
            // Arrange
            List <Person> matching = new List <Person>();
            List <Person> expected = new List <Person>();

            Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Loose);

            mockPersonRepository.Setup(r => r.SearchPeopleAsync(It.IsAny <string>())).ReturnsAsync(matching);

            PeopleController controller = new PeopleController(mockPersonRepository.Object);

            // Act
            List <Person> actual = (await controller.GetAsync(null)).Value.ToList();

            // Assert
            ModelComparisonHelper.AssertPersonListsAreEqual(expected, actual);
        }
Exemple #3
0
        public async Task GetAsync_GivenWhitespaceSearchString_ShouldCallRepositoryCorrectly()
        {
            // Arrange
            List <Person> matching = new List <Person>();
            string        expected = " ";

            Mock <IPersonRepository> mockPersonRepository = new Mock <IPersonRepository>(MockBehavior.Strict);

            mockPersonRepository.Setup(r => r.SearchPeopleAsync(expected)).ReturnsAsync(matching);

            PeopleController controller = new PeopleController(mockPersonRepository.Object);

            // Act
            await controller.GetAsync(expected);

            // Assert
            mockPersonRepository.VerifyAll();
        }