Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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);
        }