public async Task PerformSearch_GivenFirstSearchResultReturnedCorrectly_EnsuresResult() { // Arrange int numberOfItems = 25; CalculationProviderResultSearchResults itemResult = GenerateSearchResults(numberOfItems); _resultsClient .SearchCalculationProviderResults(Arg.Any <SearchModel>()) .Returns(new ApiResponse <CalculationProviderResultSearchResults>(HttpStatusCode.OK, itemResult)); SearchRequestViewModel request = new SearchRequestViewModel(); AndCalculationExistsForCalcId("calcId"); // Act CalculationProviderResultSearchResultViewModel results = await _resultsSearchService.PerformSearch(request); // Assert CalculationProviderResultSearchResultItemViewModel first = results.CalculationProviderResults.First(); first .Should() .NotBeNull(); first .Id .Should() .Be("10"); first .ProviderName .Should() .Be("prov-1"); first .CalculationResult .Should() .Be(1); CalculationProviderResultSearchResultItemViewModel last = results.CalculationProviderResults.Last(); last .CalculationExceptionType .Should() .Be("Exception"); last .CalculationExceptionMessage .Should() .Be("An exception has occurred"); }
public async Task PerformSearch_GivenFirstSearchResultReturnedCorrectly_EnsuresResult() { // Arrange IResultsApiClient resultClient = Substitute.For <IResultsApiClient>(); ILogger logger = CreateLogger(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); CalculationProviderResultsSearchService resultsSearchService = CreateSearchService(resultClient, mapper, logger); int numberOfItems = 25; PagedResult <CalculationProviderResultSearchResultItem> itemResult = GeneratePagedResult(numberOfItems); resultClient .FindCalculationProviderResults(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel(); // Act CalculationProviderResultSearchResultViewModel results = await resultsSearchService.PerformSearch(request); // Assert CalculationProviderResultSearchResultItemViewModel first = results.CalculationProviderResults.First(); first .Should() .NotBeNull(); first .Id .Should() .Be("10"); first .CalculationType .Should() .Be(CalculationSpecificationType.Number); first .Name .Should() .Be("prov-1"); first .CalculationResult .Should() .Be(1); CalculationProviderResultSearchResultItemViewModel last = results.CalculationProviderResults.Last(); last .CalculationExceptionType .Should() .Be("Exception"); last .CalculationExceptionMessage .Should() .Be("An exception has occurred"); }
public async Task PerformSearch_FirstSearchResultWithFacets_EnsuresFacetsLoadedCorrectly() { // Arrange int numberOfItems = 25; IEnumerable <Facet> facets = new[] { new Facet { Name = "facet 1", FacetValues = new[] { new FacetValue { Name = "f1", Count = 5 } } }, new Facet { Name = "facet 2", FacetValues = new[] { new FacetValue { Name = "f2", Count = 11 }, new FacetValue { Name = "f3", Count = 1 } } } }; CalculationProviderResultSearchResults itemResult = GenerateSearchResults(numberOfItems, facets); _resultsClient .SearchCalculationProviderResults(Arg.Any <SearchModel>()) .Returns(new ApiResponse <CalculationProviderResultSearchResults>(HttpStatusCode.OK, itemResult)); SearchRequestViewModel request = new SearchRequestViewModel(); AndCalculationExistsForCalcId("calcId"); // Act CalculationProviderResultSearchResultViewModel results = await _resultsSearchService.PerformSearch(request); // Assert CalculationProviderResultSearchResultItemViewModel first = results.CalculationProviderResults.First(); first .Should() .NotBeNull(); first .Id .Should() .Be("10"); first .ProviderName .Should() .Be("prov-1"); first .CalculationResult .Should() .Be(1); results.Facets.Count().Should().Be(2); results.Facets.First().Name.Should().Be("facet 1"); results.Facets.First().FacetValues.Count().Should().Be(1); results.Facets.First().FacetValues.First().Name.Should().Be("f1"); results.Facets.First().FacetValues.First().Count.Should().Be(5); results.Facets.Last().Name.Should().Be("facet 2"); results.Facets.Last().FacetValues.Count().Should().Be(2); results.Facets.Last().FacetValues.First().Name.Should().Be("f2"); results.Facets.Last().FacetValues.First().Count.Should().Be(11); results.Facets.Last().FacetValues.Last().Name.Should().Be("f3"); results.Facets.Last().FacetValues.Last().Count.Should().Be(1); }
public async Task PerformSearch_FirstSearchResultWithFacets_EnsuresFacetsLoadedCorrectly() { // Arrange IResultsApiClient resultClient = Substitute.For <IResultsApiClient>(); ILogger logger = CreateLogger(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); CalculationProviderResultsSearchService resultsSearchService = CreateSearchService(resultClient, mapper, logger); int numberOfItems = 25; IEnumerable <SearchFacet> facets = new[] { new SearchFacet { Name = "facet 1", FacetValues = new[] { new SearchFacetValue { Name = "f1", Count = 5 } } }, new SearchFacet { Name = "facet 2", FacetValues = new[] { new SearchFacetValue { Name = "f2", Count = 11 }, new SearchFacetValue { Name = "f3", Count = 1 } } } }; PagedResult <CalculationProviderResultSearchResultItem> itemResult = GeneratePagedResult(numberOfItems, facets); resultClient .FindCalculationProviderResults(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel(); // Act CalculationProviderResultSearchResultViewModel results = await resultsSearchService.PerformSearch(request); // Assert CalculationProviderResultSearchResultItemViewModel first = results.CalculationProviderResults.First(); first .Should() .NotBeNull(); first .Id .Should() .Be("10"); first .CalculationType .Should() .Be(CalculationSpecificationType.Number); first .Name .Should() .Be("prov-1"); first .CalculationResult .Should() .Be(1); results.Facets.Count().Should().Be(2); results.Facets.First().Name.Should().Be("facet 1"); results.Facets.First().FacetValues.Count().Should().Be(1); results.Facets.First().FacetValues.First().Name.Should().Be("f1"); results.Facets.First().FacetValues.First().Count.Should().Be(5); results.Facets.Last().Name.Should().Be("facet 2"); results.Facets.Last().FacetValues.Count().Should().Be(2); results.Facets.Last().FacetValues.First().Name.Should().Be("f2"); results.Facets.Last().FacetValues.First().Count.Should().Be(11); results.Facets.Last().FacetValues.Last().Name.Should().Be("f3"); results.Facets.Last().FacetValues.Last().Count.Should().Be(1); }