Exemple #1
0
        public async Task GivenPerformQueryIsCalledMultipleTimes_WithDifferentQueries_AndThereAreMultipleValidQueryResults_WhenGetResultIsCalled_ThenThereWillBeMultipleQueriesWithTheCorrectAmountOfResults(int expectedQueriesAmount, int expectedResultsAmount)
        {
            //arrange
            const string query = "Test";

            for (var i = 0; i < expectedResultsAmount; i++)
            {
                var expectedQueryResult = new SearchEngineQueryResultBuilderParameters {
                    ResultLink = $"TestLink{i}", ResultText = $"ResultText{i}", SearchEngineType = $"TestEngine{i}"
                };
                _searchQueryResultReturn.Add(expectedQueryResult);
            }
            _searchMock.Setup(e => e.PerformSearch(It.IsAny <string>())).Returns(_searchQueryResultReturn);

            for (var i = 0; i < expectedQueriesAmount; i++)
            {
                //act
                await _controller.PerformQuery($"{query}{i}").ConfigureAwait(false);

                //assert
                var result = await _controller.GetResult($"{query}{i}").ConfigureAwait(false);

                Assert.Equal(expectedResultsAmount, result.QueryResults.Count);
            }
        }
Exemple #2
0
        public async Task GivenPerformQueryIsCalled_AndThereIsOneInvalidQueryResult_WhenPerformQueryIsCalled_ThenAValidationExceptionWillBeThrown()
        {
            //arrange
            const string query = "Test";
            var          expectedQueryResult = new SearchEngineQueryResultBuilderParameters {
                ResultLink = "", ResultText = "", SearchEngineType = ""
            };

            _searchQueryResultReturn.Add(expectedQueryResult);
            _searchMock.Setup(e => e.PerformSearch(It.IsAny <string>())).Returns(_searchQueryResultReturn);

            //act
            await Assert.ThrowsAsync <ValidationException>(async() => await _controller.PerformQuery(query).ConfigureAwait(false)).ConfigureAwait(false);
        }
Exemple #3
0
        public async Task GivenPerformQueryIsCalled_AndThereIsOneValidQueryResult_WhenGetResultIsCalled_ThenThereWillBeOneQueryWithASingleQueryResult()
        {
            //arrange
            const string query = "Test";
            var          expectedQueryResult = new SearchEngineQueryResultBuilderParameters {
                ResultLink = "TestLink", ResultText = "ResultText", SearchEngineType = "TestEngine"
            };

            _searchQueryResultReturn.Add(expectedQueryResult);
            _searchMock.Setup(e => e.PerformSearch(It.IsAny <string>())).Returns(_searchQueryResultReturn);

            //act
            await _controller.PerformQuery(query).ConfigureAwait(false);

            var result = await _controller.GetResult(query).ConfigureAwait(false);

            //assert
            Assert.Single(result.QueryResults);
            AssertQueryResultMatch(expectedQueryResult, result.QueryResults[0]);
        }
Exemple #4
0
 private static void AssertQueryResultMatch(SearchEngineQueryResultBuilderParameters expected, SearchEngineQueryResult result)
 {
     Assert.Equal(expected.ResultLink, result.ResultLink);
     Assert.Equal(expected.ResultText, result.ResultText);
     Assert.Equal(expected.SearchEngineType, result.SearchEngineType);
 }