public async Task PerformSearch_FirstSearchResultReturnedCorrectly() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); IFeatureToggle featureToggle = CreateFeatureToggle(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger, featureToggle); int numberOfItems = 25; PagedResult <CalculationSearchResultItem> itemResult = GeneratePagedResult(numberOfItems); calcsClient .FindCalculations(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel(); // Act CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request); // Assert CalculationSearchResultItemViewModel first = results.Calculations.First(); first.Should().NotBeNull(); first.Id.Should().Be("10"); first.SpecificationName.Should().Be("Spec Name"); first.Status.Should().Be("Unknown"); first.FundingPeriodName.Should().Be("Test Period"); first.Name.Should().Be("Calculation 1"); }
public async Task PerformSearch_SearchResultsReturnedCorrectly() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger); int numberOfItems = 25; ApiResponse <SearchResults <CalculationSearchResult> > itemResult = GeneratePagedResult(numberOfItems); calcsClient .FindCalculations(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel(); // Act CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request); // Assert CalculationSearchResultItemViewModel[] calcs = results.Calculations.ToArray(); for (int i = 0; i < calcs.Length; i++) { calcs[i].Id.Should().Be((i + 10).ToString()); calcs[i].Name.Should().Be($"Calculation {i + 1}"); } }
public async Task PerformSearch_StartAndEndItemsNumbersDisplayedCorrectlyOnSecondPageOfItemsWithMorePagesAvailable() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger); int numberOfItems = 50; var itemResult = GeneratePagedResult(numberOfItems); itemResult.Content.TotalCount = 175; calcsClient .FindCalculations(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel() { PageNumber = 2, }; // Act CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request); // Assert results.StartItemNumber.Should().Be(51); results.EndItemNumber.Should().Be(100); }
public async Task PerformSearch_StartAndEndItemsNumbersDisplayedCorrectlyOnSecondPageOfItemsWithLessThanPageSize() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); IFeatureToggle featureToggle = CreateFeatureToggle(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger, featureToggle); int numberOfItems = 25; PagedResult <CalculationSearchResultItem> itemResult = GeneratePagedResult(numberOfItems); itemResult.PageNumber = 2; itemResult.PageSize = 50; itemResult.TotalItems = 75; calcsClient .FindCalculations(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel() { PageNumber = 2, }; // Act CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request); // Assert results.StartItemNumber.Should().Be(51); results.EndItemNumber.Should().Be(75); }
public void PerformSearch_WhenFindCalculationsServiceUnavailable_ThenHttpExceptionThrown() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); IFeatureToggle featureToggle = CreateFeatureToggle(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger, featureToggle); calcsClient .When(a => a.FindCalculations(Arg.Any <SearchFilterRequest>())) .Do(x => { throw new HttpRequestException(); }); SearchRequestViewModel request = new SearchRequestViewModel(); // Act Action pageAction = new Action(() => { CalculationSearchResultViewModel result = calculationSearchService.PerformSearch(request).Result; }); // Assert pageAction.Should().Throw <HttpRequestException>(); }
public async Task PerformSearch_WhenFindCalculationsServiceReturnsNotFound_ThenNullReturned() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger); ApiResponse <SearchResults <CalculationSearchResult> > expectedServiceResult = null; calcsClient .FindCalculations(Arg.Any <SearchFilterRequest>()) .Returns(expectedServiceResult); SearchRequestViewModel request = new SearchRequestViewModel(); // Act CalculationSearchResultViewModel result = await calculationSearchService.PerformSearch(request); // Assert result.Should().BeNull(); }
public async Task PerformSearch_GivenIsSearchModeAllEnabledFeatureToggleIsSwitchedOn_SearchModeIsAll() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); IFeatureToggle featureToggle = CreateFeatureToggle(true); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger, featureToggle); SearchRequestViewModel request = new SearchRequestViewModel() { PageNumber = 2, }; // Act CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request); // Assert await calcsClient .FindCalculations(Arg.Is <SearchFilterRequest>(m => m.SearchMode == SearchMode.All)); }
public async Task PerformSearch_FirstSearchResultWithFacets_EnsuresFacetsLoadedCorrectly() { // Arrange ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, 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 } } } }; var itemResult = GeneratePagedResult(numberOfItems, facets); calcsClient .FindCalculations(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel(); // Act CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request); // Assert CalculationSearchResultItemViewModel[] calcs = results.Calculations.ToArray(); for (int i = 0; i < calcs.Length; i++) { calcs[i].Id.Should().Be((i + 10).ToString()); calcs[i].Name.Should().Be($"Calculation {i + 1}"); } results.Facets.Count().Should().Be(facets.Count()); 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 ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>(); ILogger logger = Substitute.For <ILogger>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); IFeatureToggle featureToggle = CreateFeatureToggle(); ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger, featureToggle); 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 <CalculationSearchResultItem> itemResult = GeneratePagedResult(numberOfItems, facets); calcsClient .FindCalculations(Arg.Any <SearchFilterRequest>()) .Returns(itemResult); SearchRequestViewModel request = new SearchRequestViewModel(); // Act CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request); // Assert CalculationSearchResultItemViewModel first = results.Calculations.First(); first.Should().NotBeNull(); first.Id.Should().Be("10"); first.SpecificationName.Should().Be("Spec Name"); first.Status.Should().Be("Unknown"); first.FundingPeriodName.Should().Be("Test Period"); first.Name.Should().Be("Calculation 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); }