Exemple #1
0
        public async Task InvalidCasing_MatchesAreNotCaseSensitive_ReturnsMatches()
        {
            // Given
            var mockDataReadModel = Substitute.For <IDataReadModel>();

            mockDataReadModel.GetData().Returns(new List <string>
            {
                "London", "Londonderry"
            });

            var citySearch = new CitySearch(mockDataReadModel, new CityCharacterValidator(), new Trie());
            await citySearch.Initialise();

            var expectedResult = new CityResult
            {
                NextCities  = new[] { "London", "Londonderry" },
                NextLetters = new[] { "d" }
            };

            // When
            var results = citySearch.Search("lon");

            // Then
            results.ShouldBeEquivalentTo(expectedResult);
        }
Exemple #2
0
        public async Task NextLetter_HyphenReturned_AsValidNextLetter()
        {
            // Given
            var mockDataReadModel = Substitute.For <IDataReadModel>();

            mockDataReadModel.GetData().Returns(new List <string>
            {
                "Stockton-on-Tees"
            });

            var citySearch = new CitySearch(mockDataReadModel, new CityCharacterValidator(), new Trie());
            await citySearch.Initialise();

            var expectedResult = new CityResult
            {
                NextCities  = new[] { "Stockton-on-Tees" },
                NextLetters = new[] { "-" }
            };

            // When
            var results = citySearch.Search("Stockton");

            // Then
            results.ShouldBeEquivalentTo(expectedResult);
        }
        public async Task GivenZE_ResultsShouldMatchExpectations()
        {
            //Given
            var mockDataReadModel = Substitute.For <IDataReadModel>();

            mockDataReadModel.GetData().Returns(new List <string>
            {
                "ZARIA", "ZHUGHAI", "ZIBO"
            });

            var citySearch = new CitySearch(mockDataReadModel, new CityCharacterValidator(), new Trie());
            await citySearch.Initialise();

            var expectedResult = new CityResult
            {
                NextCities  = new string[0],
                NextLetters = new string[0]
            };

            //When
            var results = citySearch.Search("ZE");

            //Then
            results.ShouldBeEquivalentTo(expectedResult);
        }
Exemple #4
0
        public async Task InvalidCharactersInSet_OnlyCitiesWithValidCharactersReturned()
        {
            //Given
            var mockDataReadModel = Substitute.For <IDataReadModel>();

            mockDataReadModel.GetData().Returns(new List <string>
            {
                "Valid", "In%Valid", "In3Valid", "Val*id"
            });

            var citySearch = new CitySearch(mockDataReadModel, new CityCharacterValidator(), new Trie());
            await citySearch.Initialise();

            var expectedResult = new CityResult
            {
                NextCities  = new[] { "Valid" },
                NextLetters = new[] { "a" }
            };

            //When
            var results = citySearch.Search("V");

            //Then
            results.ShouldBeEquivalentTo(expectedResult);
        }
        public async Task GivenLA_ResultsShouldMatchExpectations()
        {
            //Given
            var mockDataReadModel = Substitute.For <IDataReadModel>();

            mockDataReadModel.GetData().Returns(new List <string>
            {
                "LA PAZ", "LA PLATA", "LAGOS", "LEEDS"
            });

            var citySearch = new CitySearch(mockDataReadModel, new CityCharacterValidator(), new Trie());
            await citySearch.Initialise();

            var expectedResult = new CityResult
            {
                NextCities  = new[] { "LA PAZ", "LA PLATA", "LAGOS" },
                NextLetters = new[] { " ", "G" }
            };

            //When
            var results = citySearch.Search("LA");

            //Then
            results.ShouldBeEquivalentTo(expectedResult);
        }
Exemple #6
0
        public void ReturnSuccess_WhenFoundCityWithInsensitiveCase()
        {
            // Assign
            CitySearch citySearch = new CitySearch();

            // Act
            List <string> result = citySearch.Search("une");

            // Assert
            Assert.AreEqual("Pune", result[0]);
        }
Exemple #7
0
        public void ReturnSuccess_WhenFoundCity()
        {
            // Assign
            CitySearch citySearch = new CitySearch();

            // Act
            List <string> result = citySearch.Search("umb");

            // Assert
            Assert.AreEqual("Mumbai", result[0]);
        }
Exemple #8
0
        public void ReturnSuccess_WhenNoCityFound()
        {
            // Assign
            CitySearch citySearch = new CitySearch();

            // Act
            var result = citySearch.Search("test");

            // Assert
            Assert.AreEqual(0, result.Count);
        }
Exemple #9
0
        public void ReturnSuccess_WhenShortQuery()
        {
            // Assign
            CitySearch citySearch = new CitySearch();


            // Act
            List <string> result = citySearch.Search("um");


            // Assert
            Assert.AreEqual(0, result.Count);
        }
Exemple #10
0
        public void ReturnSuccess_WhenFoundCityWithMulitpleResult()
        {
            // Assign
            CitySearch citySearch = new CitySearch();


            // Act
            List <string> result = citySearch.Search("elh");


            // Assert
            Assert.AreEqual(2, result.Count);
        }
        public async Task GivenBang_ResultsShouldMatchExpectations()
        {
            var mockDataReadModel = Substitute.For <IDataReadModel>();

            mockDataReadModel.GetData().Returns(new List <string>
            {
                "BANDUNG", "BANGUI", "BANGKOK", "BANGALORE"
            });

            var citySearch = new CitySearch(mockDataReadModel, new CityCharacterValidator(), new Trie());
            await citySearch.Initialise();

            var expectedResult = new CityResult
            {
                NextCities  = new[] { "BANGUI", "BANGKOK", "BANGALORE" },
                NextLetters = new[] { "U", "K", "A" }
            };

            var results = citySearch.Search("BANG");

            results.ShouldBeEquivalentTo(expectedResult);
        }