public async Task OnGetAsync_WhenTestScenariosSearchResultsFoundThenTestCoverageIsCalculated_ThenSuccessfullyShown()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

            Provider provider = CreateProvider();

            IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") };

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            specsClient.GetFundingPeriods()
            .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods));

            resultsApiClient.GetSpecificationIdsForProvider(Arg.Any <string>())
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));

            resultsApiClient.GetProviderByProviderId(Arg.Any <string>())
            .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider));

            IList <TestScenarioSearchResultItemViewModel> testScenarioSearchResultItems = GetTestScenarioSearchResults();
            TestScenarioSearchResultItemViewModel         ignoredItem = new TestScenarioSearchResultItemViewModel()
            {
                Id = "3",
                LastUpdatedDate        = new DateTime(12, 01, 23),
                ProviderId             = "1",
                ProviderName           = "Provider 1",
                SpecificationId        = "2",
                SpecificationName      = "Spec 02",
                TestResult             = "Ignored",
                TestScenarioId         = "2",
                TestScenarioName       = "Test Scenario 02",
                LastUpdatedDateDisplay = "1",
            };

            testScenarioSearchResultItems.Add(ignoredItem);

            TestScenarioSearchResultItemViewModel failedItem = new TestScenarioSearchResultItemViewModel()
            {
                Id = "4",
                LastUpdatedDate        = new DateTime(12, 01, 23),
                ProviderId             = "1",
                ProviderName           = "Provider 1",
                SpecificationId        = "2",
                SpecificationName      = "Spec 02",
                TestResult             = "Failed",
                TestScenarioId         = "2",
                TestScenarioName       = "Test Scenario 02",
                LastUpdatedDateDisplay = "1",
            };

            testScenarioSearchResultItems.Add(failedItem);

            string specificationId = "2";

            TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel()
            {
                TestScenarios = testScenarioSearchResultItems,
                TotalResults  = 4,
                CurrentPage   = 1,
            };

            SearchRequestViewModel searchRequest = CreateSearchRequest();

            searchRequest.Filters["specificationId"][0] = specificationId;

            searchService.PerformSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(results);

            specsClient
            .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >())
            .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>()));

            ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient);

            //Act
            IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("1", 1, "", "1819", specificationId);

            // Assert
            actionResult
            .Should()
            .BeOfType <PageResult>();

            providerScenarioResultsPageModel.Passed.Should().Be(2);
            providerScenarioResultsPageModel.Failed.Should().Be(1);
            providerScenarioResultsPageModel.Ignored.Should().Be(1);
            providerScenarioResultsPageModel.TestCoverage.Should().Be(75);
        }
        public async Task OnGetAsync_WhenTestScenariosSearchResultsFound_ThenSuccessfullyShown()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

            Provider provider = CreateProvider();

            IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") };

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            specsClient.GetFundingPeriods()
            .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods));

            resultsApiClient.GetSpecificationIdsForProvider(Arg.Any <string>())
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));

            resultsApiClient.GetProviderByProviderId(Arg.Any <string>())
            .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider));

            specsClient
            .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >())
            .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>()));

            IList <TestScenarioSearchResultItemViewModel> testScenarioSearchResultItems = GetTestScenarioSearchResults();

            string specificationId = "2";

            TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel()
            {
                TestScenarios = testScenarioSearchResultItems,
                TotalResults  = 2,
                CurrentPage   = 1,
            };

            SearchRequestViewModel searchRequest = CreateSearchRequest();

            searchRequest.Filters["specificationId"][0] = specificationId;

            searchService.PerformSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(results);

            ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient);

            //Act
            IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("1", 1, "", "1819", specificationId);

            // Assert
            actionResult
            .Should()
            .BeOfType <PageResult>();

            providerScenarioResultsPageModel.TestScenarioSearchResults.Should().NotBeNull();
            providerScenarioResultsPageModel.FundingPeriods.Count().Should().Be(3);

            await searchService.Received(1).PerformSearch(Arg.Is <SearchRequestViewModel>(r =>
                                                                                          r.PageNumber == searchRequest.PageNumber &&
                                                                                          r.IncludeFacets == searchRequest.IncludeFacets &&
                                                                                          r.SearchTerm == searchRequest.SearchTerm &&
                                                                                          r.Filters["providerId"][0] == searchRequest.Filters["providerId"][0] &&
                                                                                          r.Filters["specificationId"][0] == searchRequest.Filters["specificationId"][0]
                                                                                          ));
        }
Example #3
0
 private static ProviderCalcsResultsPageModel CreatePageModel(IResultsApiClient resultsApiClient, ISpecsApiClient specsApiClient, IMapper mapper, ILogger logger, IFeatureToggle featureToggle)
 {
     return(new ProviderCalcsResultsPageModel(resultsApiClient, specsApiClient, mapper, logger, featureToggle));
 }
Example #4
0
 private static ProviderAllocationLinePageModel CreatePageModel(IResultsApiClient resultsApiClient, ISpecsApiClient specsApiClient, IMapper mapper, ILogger logger)
 {
     return(new ProviderAllocationLinePageModel(resultsApiClient, mapper, specsApiClient, logger));
 }
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();


            builder.AddSingleton <IConfiguration>(config);
            builder.AddCaching(config);

            // These registrations of the functions themselves are just for the DebugQueue. Ideally we don't want these registered in production
            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                builder.AddScoped <OnCalcsGenerateAllocationResults>();
                builder.AddScoped <OnCalculationGenerateFailure>();
            }

            builder.AddScoped <ICalculationEngineService, CalculationEngineService>();
            builder.AddScoped <ICalculationEngine, CalculationEngine>();
            builder.AddScoped <IAllocationFactory, AllocationFactory>();
            builder.AddScoped <IDeadletterService, DeadletterService>();
            builder.AddScoped <IJobManagement, JobManagement>();
            builder.AddSingleton <IProviderSourceDatasetVersionKeyProvider, ProviderSourceDatasetVersionKeyProvider>();
            builder.AddSingleton <IFileSystemAccess, FileSystemAccess>();

            builder.AddSingleton <IAssemblyService, AssemblyService>();
            builder.AddSingleton <ICalculationAggregationService, CalculationAggregationService>();
            builder.AddScoped <ICalculationEnginePreviewService, CalculationEnginePreviewService>();

            builder.AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>();
            builder.AddSingleton <IFileSystemCache, FileSystemCache>();

            builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>((ctx) =>
            {
                CosmosDbSettings providerSourceDatasetsCosmosSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", providerSourceDatasetsCosmosSettings);

                providerSourceDatasetsCosmosSettings.ContainerName = "providerdatasets";

                CosmosRepository calcsCosmosRepository = new CosmosRepository(providerSourceDatasetsCosmosSettings, new CosmosClientOptions()
                {
                    ConnectionMode = ConnectionMode.Direct,
                    RequestTimeout = new TimeSpan(0, 0, 15),
                    MaxRequestsPerTcpConnection  = 8,
                    MaxTcpConnectionsPerEndpoint = 4,
                    ConsistencyLevel             = ConsistencyLevel.Eventual,
                    AllowBulkExecution           = true,
                    // MaxRetryAttemptsOnRateLimitedRequests = 1,
                    // MaxRetryWaitTimeOnRateLimitedRequests = new TimeSpan(0, 0, 30),
                });

                ICalculatorResiliencePolicies calculatorResiliencePolicies = ctx.GetService <ICalculatorResiliencePolicies>();

                return(new ProviderSourceDatasetsRepository(calcsCosmosRepository, calculatorResiliencePolicies));
            });

            builder.AddSingleton <IProviderResultCalculationsHashProvider, ProviderResultCalculationsHashProvider>();

            builder.AddSingleton <IProviderResultsRepository, ProviderResultsRepository>((ctx) =>
            {
                CosmosDbSettings calcResultsDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", calcResultsDbSettings);

                calcResultsDbSettings.ContainerName = "calculationresults";

                CosmosRepository calcsCosmosRepostory = new CosmosRepository(calcResultsDbSettings, new CosmosClientOptions()
                {
                    ConnectionMode = ConnectionMode.Direct,
                    RequestTimeout = new TimeSpan(0, 0, 15),
                    MaxRequestsPerTcpConnection  = 8,
                    MaxTcpConnectionsPerEndpoint = 2,
                    // MaxRetryWaitTimeOnRateLimitedRequests = new TimeSpan(0, 0, 30),
                    AllowBulkExecution = true,
                });

                ILogger logger = ctx.GetService <ILogger>();

                IProviderResultCalculationsHashProvider calculationsHashProvider = ctx.GetService <IProviderResultCalculationsHashProvider>();

                ICalculatorResiliencePolicies calculatorResiliencePolicies = ctx.GetService <ICalculatorResiliencePolicies>();

                IResultsApiClient resultsApiClient = ctx.GetService <IResultsApiClient>();

                IJobManagement jobManagement = ctx.GetService <IJobManagement>();

                return(new ProviderResultsRepository(
                           calcsCosmosRepostory,
                           logger,
                           calculationsHashProvider,
                           calculatorResiliencePolicies,
                           resultsApiClient,
                           jobManagement));
            });

            builder.AddSingleton <ISourceFileRepository, SourceFileRepository>((ctx) =>
            {
                BlobStorageOptions blobStorageOptions = new BlobStorageOptions();

                config.Bind("AzureStorageSettings", blobStorageOptions);

                blobStorageOptions.ContainerName = "source";

                IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(blobStorageOptions);
                return(new SourceFileRepository(blobContainerRepository));
            });

            builder
            .AddSingleton <Services.CalcEngine.Interfaces.ICalculationsRepository, Services.CalcEngine.CalculationsRepository>();

            builder
            .AddSingleton <IDatasetAggregationsRepository, DatasetAggregationsRepository>();

            builder
            .AddSingleton <ICancellationTokenProvider, InactiveCancellationTokenProvider>();

            builder
            .AddSingleton <ISourceCodeService, SourceCodeService>();

            MapperConfiguration calculationsConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <CalculationsMappingProfile>();
                c.AddProfile <CalcEngineMappingProfile>();
            });

            builder
            .AddSingleton(calculationsConfig.CreateMapper());

            builder.AddScoped <IUserProfileProvider, UserProfileProvider>();

            builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddResultsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddDatasetsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);

            builder.AddEngineSettings(config);

            builder.AddServiceBus(config, "calcengine");

            builder.AddCaching(config);

            builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.CalcEngine");
            builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.CalcEngine");

            builder.AddLogging("CalculateFunding.Functions.CalcEngine", config);

            builder.AddTelemetry();

            builder.AddSearch(config);
            builder
            .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >();

            builder.AddFeatureToggling(config);

            PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config);
            CalculatorResiliencePolicies calcResiliencePolicies = CreateResiliencePolicies(policySettings);

            builder.AddSingleton <ICalculatorResiliencePolicies>(calcResiliencePolicies);
            builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => new JobManagementResiliencePolicies()
            {
                JobsApiClient = calcResiliencePolicies.JobsApiClient
            });

            builder.AddSingleton <IValidator <ICalculatorResiliencePolicies>, CalculatorResiliencePoliciesValidator>();
            builder.AddSingleton <ICalculationEngineServiceValidator, CalculationEngineServiceValidator>();
            builder.AddSingleton <ISpecificationAssemblyProvider, SpecificationAssemblyProvider>();
            builder.AddSingleton <IBlobClient>(ctx =>
            {
                BlobStorageOptions options = new BlobStorageOptions();

                config.Bind("AzureStorageSettings", options);

                options.ContainerName = "source";

                IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(options);
                return(new BlobClient(blobContainerRepository));
            });

            ServicePointManager.DefaultConnectionLimit = 200;

            return(builder.BuildServiceProvider());
        }
Example #6
0
 public ResultsApi(IBitmovinApiClientFactory apiClientFactory)
 {
     _apiClient  = apiClientFactory.CreateClient <IResultsApiClient>();
     ByTimestamp = new ByTimestampApi(apiClientFactory);
 }