public CalculationProviderResultsPageModel( ICalculationProviderResultsSearchService resultsSearchService, ICalculationsApiClient calculationsApiClient, ISpecsApiClient specsApiClient, IMapper mapper, IDatasetsApiClient datasetsClient, ILogger logger, IJobsApiClient jobsApiClient, IFeatureToggle featureToggle) { Guard.ArgumentNotNull(resultsSearchService, nameof(resultsSearchService)); Guard.ArgumentNotNull(calculationsApiClient, nameof(calculationsApiClient)); Guard.ArgumentNotNull(specsApiClient, nameof(specsApiClient)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(datasetsClient, nameof(datasetsClient)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(jobsApiClient, nameof(jobsApiClient)); Guard.ArgumentNotNull(featureToggle, nameof(featureToggle)); _mapper = mapper; _resultsSearchService = resultsSearchService; _calculationsApiClient = calculationsApiClient; _specsClient = specsApiClient; _datasetsClient = datasetsClient; _jobsClient = jobsApiClient; _logger = logger; ShowExceptionCountAndFacet = featureToggle.IsExceptionMessagesEnabled(); }
public async Task SearchCalculationProviderResults_GivenNullResultsReturnedFromSearch_ReturnsStatusCode500() { // Arrange SearchRequestViewModel requestModel = new SearchRequestViewModel(); ICalculationProviderResultsSearchService searchService = CreateCalculationProviderResultsSearchService(); searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns((CalculationProviderResultSearchResultViewModel)null); ProviderSearchController controller = CreateController(calculationProviderResultsSearchService: searchService); // Act IActionResult actionResult = await controller.SearchCalculationProviderResults(requestModel); // Asserts actionResult .Should() .BeOfType <StatusCodeResult>(); StatusCodeResult statusCodeResult = actionResult as StatusCodeResult; statusCodeResult .StatusCode .Should() .Be(500); }
public async Task GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId_CallsCorrectly( string providerId, string specificationId, string fundingStreamId) { IResultsService resultsService = Substitute.For <IResultsService>(); IResultsSearchService resultsSearchService = Substitute.For <IResultsSearchService>(); ICalculationProviderResultsSearchService calculationProviderResultsSearchService = Substitute.For <ICalculationProviderResultsSearchService>(); IPublishedResultsService publishedResultsService = Substitute.For <IPublishedResultsService>(); IProviderCalculationResultsSearchService providerCalculationsResultsSearchService = Substitute.For <IProviderCalculationResultsSearchService>(); IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>(); IProviderCalculationResultsReIndexerService providerCalculationResultsReIndexerService = Substitute.For <IProviderCalculationResultsReIndexerService>(); ResultsController controller = new ResultsController( resultsService, resultsSearchService, calculationProviderResultsSearchService, publishedResultsService, providerCalculationsResultsSearchService, featureToggle, providerCalculationResultsReIndexerService); await controller.GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId); await publishedResultsService .Received(1) .GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId); //Moq has a .VerifyNoOtherCalls method which would be really useful here to confirm the others weren't called. }
public ResultsController( IResultsService resultsService, IResultsSearchService resultsSearchService, ICalculationProviderResultsSearchService calculationProviderResultsSearchService, IPublishedResultsService publishedResultsService, IProviderCalculationResultsSearchService providerCalculationResultsSearchService, IFeatureToggle featureToggle, IProviderCalculationResultsReIndexerService providerCalculationResultsReIndexerService) { Guard.ArgumentNotNull(resultsSearchService, nameof(resultsSearchService)); Guard.ArgumentNotNull(resultsService, nameof(resultsService)); Guard.ArgumentNotNull(calculationProviderResultsSearchService, nameof(calculationProviderResultsSearchService)); Guard.ArgumentNotNull(publishedResultsService, nameof(publishedResultsService)); Guard.ArgumentNotNull(providerCalculationResultsSearchService, nameof(providerCalculationResultsSearchService)); Guard.ArgumentNotNull(featureToggle, nameof(featureToggle)); Guard.ArgumentNotNull(providerCalculationResultsReIndexerService, nameof(providerCalculationResultsReIndexerService)); _resultsSearchService = resultsSearchService; _calculationProviderResultsSearchService = calculationProviderResultsSearchService; _publishedResultsService = publishedResultsService; _resultsService = resultsService; _providerCalculationResultsSearchService = providerCalculationResultsSearchService; _featureToggle = featureToggle; _providerCalculationResultsReIndexerService = providerCalculationResultsReIndexerService; }
private static ProviderSearchController CreateController( IProviderSearchService searchService = null, ICalculationProviderResultsSearchService calculationProviderResultsSearchService = null) { return(new ProviderSearchController( searchService ?? CreateSearchService(), calculationProviderResultsSearchService ?? CreateCalculationProviderResultsSearchService())); }
public ProviderSearchController( IProviderSearchService providerSearchService, ICalculationProviderResultsSearchService calculationProviderResultsSearchService) { Guard.ArgumentNotNull(providerSearchService, nameof(providerSearchService)); Guard.ArgumentNotNull(calculationProviderResultsSearchService, nameof(calculationProviderResultsSearchService)); _providerSearchService = providerSearchService; _calculationProviderResultsSearchService = calculationProviderResultsSearchService; }
private static CalculationProviderResultsPageModel CreatePageModel( ICalculationProviderResultsSearchService resultsSearchService = null, ICalculationsApiClient calculationsApiClient = null, ISpecsApiClient specsApiClient = null, IMapper mapper = null, IDatasetsApiClient datasetsApiClient = null, ILogger logger = null, IJobsApiClient jobsApiClient = null) { IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>(); featureToggle.IsExceptionMessagesEnabled().Returns(true); return(new CalculationProviderResultsPageModel( resultsSearchService ?? CreateResultsSearchService(), calculationsApiClient ?? CreateCalculationsApiClient(), specsApiClient ?? CreateSpecsApiClient(), mapper ?? CreateMapper(), datasetsApiClient ?? CreateDatasetsApiClient(), logger ?? Createlogger(), jobsApiClient ?? CreateJobsApiClient(), featureToggle)); }
public async Task SearchCalculationProviderResults_GivenResultsReturnedFromSearch_ReturnsOK() { // Arrange SearchRequestViewModel requestModel = new SearchRequestViewModel(); CalculationProviderResultSearchResultViewModel results = new CalculationProviderResultSearchResultViewModel(); ICalculationProviderResultsSearchService searchService = CreateCalculationProviderResultsSearchService(); searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(results); ProviderSearchController controller = CreateController(calculationProviderResultsSearchService: searchService); // Act IActionResult actionResult = await controller.SearchCalculationProviderResults(requestModel); // Asserts actionResult .Should() .BeOfType <OkObjectResult>(); }
public async Task OnPostAsync_GivenCalculationFoundButGettingAssignedSchemasForSpecRetunsOKWithNullContent_ReturnsStatusCode500() { const string calculationId = "calc-id"; const string specificationId = "spec-id"; Calculation calculation = new Calculation { Id = calculationId, SpecificationId = specificationId }; CalculationViewModel calculationViewModel = new CalculationViewModel { Id = calculationId, SpecificationId = specificationId }; ApiResponse <Calculation> CalculationResponse = new ApiResponse <Calculation>(HttpStatusCode.OK, calculation); ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient(); calculationsApiClient .GetCalculationById(Arg.Is(calculationId)) .Returns(CalculationResponse); IMapper mapper = CreateMapper(); mapper .Map <CalculationViewModel>(Arg.Is(calculation)) .Returns(calculationViewModel); ICalculationProviderResultsSearchService calculationProviderResultsSearchService = CreateResultsSearchService(); IEnumerable <DatasetSchemasAssigned> datasetSchemasAssignedList = new[] { new DatasetSchemasAssigned { IsSetAsProviderData = true } }; ApiResponse <IEnumerable <DatasetSchemasAssigned> > datasetSchemaResponse = new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(Arg.Is(specificationId)) .Returns(datasetSchemaResponse); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); specsApiClient.GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, Enumerable.Empty <Clients.SpecsClient.Models.SpecificationSummary>())); Clients.SpecsClient.Models.SpecificationSummary specificationSummary = new Clients.SpecsClient.Models.SpecificationSummary() { Id = specificationId, }; specsApiClient .GetSpecificationSummary(Arg.Is(specificationId)) .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, specificationSummary)); CalculationProviderResultsPageModel pageModel = CreatePageModel( calculationProviderResultsSearchService, calculationsApiClient, mapper: mapper, datasetsApiClient: datasetsApiClient, specsApiClient: specsApiClient); //Act IActionResult result = await pageModel.OnPostAsync(calculationId, null, ""); //Assert result .Should() .BeOfType <StatusCodeResult>(); StatusCodeResult statusCodeResult = result as StatusCodeResult; statusCodeResult .StatusCode .Should() .Be(500); }
public async Task OnGetAsync_GivenCalculationFoundWithEmptySearchResults_ReturnsPage() { //Arrange const string calculationId = "calc-id"; const string specificationId = "spec-id"; Calculation calculation = new Calculation { Id = calculationId, SpecificationId = specificationId }; CalculationViewModel calculationViewModel = new CalculationViewModel { Id = calculationId, SpecificationId = specificationId }; IEnumerable <DatasetSchemasAssigned> datasetSchemasAssignedList = new[] { new DatasetSchemasAssigned { IsSetAsProviderData = true } }; ApiResponse <IEnumerable <DatasetSchemasAssigned> > datasetSchemaResponse = new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, datasetSchemasAssignedList); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(Arg.Is(specificationId)) .Returns(datasetSchemaResponse); CalculationProviderResultSearchResultViewModel calculationProviderResultSearchResultViewModel = new CalculationProviderResultSearchResultViewModel { CalculationProviderResults = Enumerable.Empty <CalculationProviderResultSearchResultItemViewModel>() }; ApiResponse <Calculation> CalculationResponse = new ApiResponse <Calculation>(HttpStatusCode.OK, calculation); ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient(); calculationsApiClient .GetCalculationById(Arg.Is(calculationId)) .Returns(CalculationResponse); IMapper mapper = CreateMapper(); mapper .Map <CalculationViewModel>(Arg.Is(calculation)) .Returns(calculationViewModel); ICalculationProviderResultsSearchService calculationProviderResultsSearchService = CreateResultsSearchService(); calculationProviderResultsSearchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(calculationProviderResultSearchResultViewModel); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); specsApiClient.GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, Enumerable.Empty <Clients.SpecsClient.Models.SpecificationSummary>())); Clients.SpecsClient.Models.SpecificationSummary specificationSummary = new Clients.SpecsClient.Models.SpecificationSummary() { Id = specificationId, }; specsApiClient .GetSpecificationSummary(Arg.Is(specificationId)) .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, specificationSummary)); CalculationProviderResultsPageModel pageModel = CreatePageModel( calculationProviderResultsSearchService, calculationsApiClient, mapper: mapper, datasetsApiClient: datasetsApiClient, specsApiClient: specsApiClient); //Act IActionResult result = await pageModel.OnGetAsync(calculationId, null, ""); //Assert result .Should() .BeOfType <PageResult>(); pageModel .CalculationProviderResults .CalculationProviderResults .Any() .Should() .BeFalse(); }