public async Task ListDatasetSchemasModel_OnGet_WhenProviderDatasetsIsPresent_ThenHasProviderDatasetsAssignedIsTrue() { // Arrange IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>(); ISpecsApiClient specsClient = Substitute.For <ISpecsApiClient>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); ILogger logger = Substitute.For <ILogger>(); string specificationId = "10"; Specification specification = new Specification() { Id = specificationId }; specsClient .GetSpecification(specificationId) .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, specification)); List <DatasetSchemasAssigned> datasetSchemasAssigned = new List <DatasetSchemasAssigned>() { new DatasetSchemasAssigned() { Id = "ds1", Name = "Dataset Schema 1", IsSetAsProviderData = false, DatasetDefinition = new Reference("1234", "Definition 1234"), Description = "Datasets Schema 1 Description", UsedInDataAggregations = false, }, new DatasetSchemasAssigned() { Id = "providerDs", Name = "Provider Dataset", IsSetAsProviderData = true, DatasetDefinition = new Reference("5678", "Provider Dataset Definition"), } }; datasetClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, datasetSchemasAssigned.AsEnumerable())); ListDatasetSchemasModel listDatasetSchemasPageModel = new ListDatasetSchemasModel(specsClient, datasetClient, mapper); // Act IActionResult result = await listDatasetSchemasPageModel.OnGet(specificationId); // Assert result.Should().BeOfType <PageResult>() .Which.Should().NotBeNull(); listDatasetSchemasPageModel.DatasetDefinitions.Should().NotBeNull(); listDatasetSchemasPageModel.HasProviderDatasetsAssigned.Should().BeTrue(); }
public void ProcessChanges_GivenChangeModelWithFieldNameChangesButNoRelationshipsFound_ThrowsRetriableException() { //Arrange string definitionId = "df-id-1"; string specificationId = "spec-1"; DatasetDefinitionChanges datasetDefinitionChanges = new DatasetDefinitionChanges { Id = definitionId, }; FieldDefinitionChanges fieldDefinitionChanges = new FieldDefinitionChanges { FieldDefinition = new FieldDefinition { Id = "field1" } }; fieldDefinitionChanges.ChangeTypes.Add(FieldDefinitionChangeType.FieldName); TableDefinitionChanges tableDefinitionChanges = new TableDefinitionChanges(); tableDefinitionChanges.FieldChanges.Add(fieldDefinitionChanges); datasetDefinitionChanges.TableDefinitionChanges.Add(tableDefinitionChanges); string json = JsonConvert.SerializeObject(datasetDefinitionChanges); Message message = new Message(Encoding.UTF8.GetBytes(json)); ILogger logger = CreateLogger(); IEnumerable <string> relationshipSpecificationIds = new[] { specificationId }; IDatasetsApiClient datasetRepository = CreateDatasetRepository(); datasetRepository .GetSpecificationIdsForRelationshipDefinitionId(Arg.Is(definitionId)) .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, relationshipSpecificationIds)); datasetRepository .GetCurrentRelationshipsBySpecificationIdAndDatasetDefinitionId(Arg.Is(specificationId), Arg.Is(definitionId)) .Returns(new ApiResponse <IEnumerable <Common.ApiClient.DataSets.Models.DatasetSpecificationRelationshipViewModel> >(HttpStatusCode.OK, Enumerable.Empty <Common.ApiClient.DataSets.Models.DatasetSpecificationRelationshipViewModel>())); DatasetDefinitionFieldChangesProcessor processor = CreateProcessor(logger: logger, datasetRepository: datasetRepository); //Act Func <Task> test = async() => await processor.Run(message); //Assert test .Should() .ThrowExactly <RetriableException>() .Which .Message .Should() .Be($"No relationships found for specificationId '{specificationId}' and dataset definition id '{definitionId}'"); }
public DatasetAggregationsRepository(IDatasetsApiClient datasetsApiClient, IMapper mapper) { Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient)); Guard.ArgumentNotNull(mapper, nameof(mapper)); _datasetsApiClient = datasetsApiClient; _mapper = mapper; }
static DatasetDefinitionSearchService CreateSearchService(IDatasetsApiClient apiClient = null, IMapper mapper = null, ILogger logger = null, IFeatureToggle featureToggle = null) { return(new DatasetDefinitionSearchService( apiClient ?? CreateApiClient(), mapper ?? CreateMapper(), logger ?? CreateLogger(), featureToggle ?? CreateFeatureToggle())); }
private static SelectSourceDatasetPageModel CreatePageModel(IDatasetsApiClient datasetClient = null, ILogger logger = null, IAuthorizationHelper authorizationHelper = null) { SelectSourceDatasetPageModel pageModel = new SelectSourceDatasetPageModel(datasetClient ?? CreateDatasetsApiClient(), logger ?? CreateLogger(), authorizationHelper ?? TestAuthHelper.CreateAuthorizationHelperSubstitute(SpecificationActionTypes.CanMapDatasets)); pageModel.PageContext = TestAuthHelper.CreatePageContext(); return(pageModel); }
public void SetUp() { _specifications = new Mock <ISpecificationsApiClient>(); _authorisationHelper = new Mock <IAuthorizationHelper>(); _logger = Substitute.For <ILogger>(); _apiClient = Substitute.For <IDatasetsApiClient>(); _controller = CreateController(_apiClient, _logger); }
public DatasetSearchService(IDatasetsApiClient datasetsClient, IMapper mapper, ILogger logger) { Guard.ArgumentNotNull(datasetsClient, nameof(datasetsClient)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(logger, nameof(logger)); _datasetsClient = datasetsClient; _mapper = mapper; _logger = logger; }
public SelectSourceDatasetPageModel(IDatasetsApiClient datasetClient, ILogger logger, IAuthorizationHelper authorizationHelper) { Guard.ArgumentNotNull(datasetClient, nameof(datasetClient)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(authorizationHelper, nameof(authorizationHelper)); _datasetClient = datasetClient; _logger = logger; _authorizationHelper = authorizationHelper; }
private static ManageDatasetsPageModel CreateDatasetPageModel( IDatasetSearchService searchService = null, IDatasetsApiClient datasetApiClient = null, IFeatureToggle featureToggle = null) { return(new ManageDatasetsPageModel( searchService ?? CreateSearchService(), datasetApiClient ?? CreateDatasetApiClient(), featureToggle ?? CreateFeatureToggle())); }
public DatasetController(IDatasetsApiClient datasetApiClient, ILogger logger, IMapper mapper) { Guard.ArgumentNotNull(datasetApiClient, nameof(datasetApiClient)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(mapper, nameof(mapper)); _datasetApiClient = datasetApiClient; _logger = logger; _mapper = mapper; }
public UpdateDatasetPageModel(IDatasetsApiClient datasetsApiClient, ILogger logger, IMapper mapper) { Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(mapper, nameof(mapper)); _datasetsClient = datasetsApiClient; _logger = logger; _mapper = mapper; }
public ListDatasetSchemasModel(ISpecsApiClient specsClient, IDatasetsApiClient datasetsClient, IMapper mapper) { Guard.ArgumentNotNull(specsClient, nameof(specsClient)); Guard.ArgumentNotNull(specsClient, nameof(mapper)); Guard.ArgumentNotNull(datasetsClient, nameof(datasetsClient)); _specsClient = specsClient; _datasetsClient = datasetsClient; _mapper = mapper; }
public DatasetRelationshipsSearchController(IDatasetRelationshipsSearchService searchService, ISpecificationsApiClient specificationsApiClient, IAuthorizationHelper authorizationHelper, IMapper mapper, IDatasetsApiClient datasetsApiClient) { Guard.ArgumentNotNull(searchService, nameof(searchService)); _searchService = searchService; _specificationsApiClient = specificationsApiClient; _authorizationHelper = authorizationHelper; _mapper = mapper; _datasetsApiClient = datasetsApiClient; }
public async Task OnGet_WhenSpecificationStatusCodeIsNotFoundThenNotFoundObjectResultReturned() { // Arrange IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>(); ISpecsApiClient specsClient = Substitute.For <ISpecsApiClient>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); ILogger logger = Substitute.For <ILogger>(); string expectedSpecificationId = "1"; Specification expectedSpecification = null; AssignDatasetSchemaPageModel datasetSchemaPageModel = CreatePageModel(specsClient, datasetClient, mapper); specsClient .GetSpecification(expectedSpecificationId) .Returns(new ApiResponse <Specification>(HttpStatusCode.NotFound, expectedSpecification)); DatasetDefinition d1 = new DatasetDefinition() { Id = "1", Name = "APT Final Baselines", Description = "Local Authority return of provider baselines", }; DatasetDefinition d2 = new DatasetDefinition() { Id = "2", Name = "School Provider Dataset", Description = "List of providers", }; IEnumerable <DatasetDefinition> dataDefn = new List <DatasetDefinition> { d1, d2 }; datasetClient .GetDataDefinitions() .Returns(new ApiResponse <IEnumerable <DatasetDefinition> >(HttpStatusCode.OK, dataDefn)); // Act IActionResult result = await datasetSchemaPageModel.OnGet(expectedSpecificationId); // Assert result.Should().NotBeNull(); result.Should().BeOfType <NotFoundObjectResult>(); NotFoundObjectResult typeResult = result as NotFoundObjectResult; typeResult.Value.Should().Be("Unable to get specification response. Specification Id value = 1"); Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult)); }
public ManageDatasetsPageModel(IDatasetSearchService searchService, IDatasetsApiClient datasetApiClient, IFeatureToggle featureToggle) { Guard.ArgumentNotNull(searchService, nameof(searchService)); Guard.ArgumentNotNull(datasetApiClient, nameof(datasetApiClient)); Guard.ArgumentNotNull(featureToggle, nameof(featureToggle)); _searchService = searchService; _datasetApiClient = datasetApiClient; _featureToggle = featureToggle; ShouldNewManageSourcesPageBeEnabled = _featureToggle.IsNewManageDataSourcesPageEnabled(); }
public void OnPost_WhenModelIsInvalidAndDatasetDefinitionListReturnedIsNull_ShoulThrowInvalidOperationException() { // Arrange string anyString = "anyString"; string expectedSpecificationId = "spec123"; SpecificationSummary expectedSpecification = new SpecificationSummary() { FundingPeriod = new Reference(anyString, anyString), Name = anyString, Description = anyString }; ISpecsApiClient mockSpecsClient = Substitute.For <ISpecsApiClient>(); mockSpecsClient .GetSpecificationSummary(Arg.Is(expectedSpecificationId)) .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, expectedSpecification)); IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>(); mockDatasetsApiClient .GetDataDefinitions() .Returns(new ApiResponse <IEnumerable <DatasetDefinition> >(HttpStatusCode.OK)); mockDatasetsApiClient .AssignDatasetSchema(Arg.Any <AssignDatasetSchemaModel>()) .Returns(HttpStatusCode.OK); IAuthorizationHelper mockAuthorizationHelper = Substitute.For <IAuthorizationHelper>(); mockAuthorizationHelper .DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Any <ISpecificationAuthorizationEntity>(), Arg.Is(SpecificationActionTypes.CanEditSpecification)) .Returns(true); AssignDatasetSchemaPageModel datasetSchemaPageModel = CreatePageModel(specsClient: mockSpecsClient, authorizationHelper: mockAuthorizationHelper, datasetsClient: mockDatasetsApiClient, mapper: MappingHelper.CreateFrontEndMapper()); datasetSchemaPageModel.AssignDatasetSchemaViewModel = new AssignDatasetSchemaViewModel(); datasetSchemaPageModel.ModelState.AddModelError(anyString, anyString); // Act Func <Task <IActionResult> > postAction = async() => await datasetSchemaPageModel.OnPostAsync(expectedSpecificationId); // Assert postAction .Should() .Throw <InvalidOperationException>() .Which .Message .Should().Be( $"Unable to retrieve Dataset definition from the response. Specification Id value = {expectedSpecificationId}"); }
public async Task OnGetAsync_WhenOperationTypeIsDatasetCreated_ThenBannerPopulated() { //Arrange IDatasetSearchService searchService = CreateSearchService(); IDatasetsApiClient datasetsApiClient = CreateDatasetApiClient(); DatasetSearchResultViewModel searchResult = new DatasetSearchResultViewModel() { CurrentPage = 2, EndItemNumber = 0, Facets = new List <SearchFacetViewModel>(), PagerState = new PagerState(1, 1), Datasets = new List <DatasetSearchResultItemViewModel>(), StartItemNumber = 1, TotalResults = 0 }; searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(searchResult); ManageDatasetsPageModel DatasetModel = CreateDatasetPageModel(searchService, datasetsApiClient); string datasetId = "Dataset1"; DatasetVersionResponse datasetVersionResponse = CreateDatasetResponseForBannerChecks(datasetId); datasetsApiClient.GetCurrentDatasetVersionByDatasetId(Arg.Any <string>()) .Returns(new ApiResponse <DatasetVersionResponse>(HttpStatusCode.OK, datasetVersionResponse)); //Act IActionResult result = await DatasetModel.OnGetAsync(null, null, DatasetPageBannerOperationType.DatasetCreated, "Dataset1"); //Assert result .Should() .BeOfType <PageResult>(); DatasetModel .PageBanner .Should() .BeEquivalentTo(new PageBannerOperation() { EntityName = "Test Dataset", EntityType = "Data Source", OperationId = "Dataset1", SecondaryActionUrl = "/datasets/updatedataset?datasetId=" + datasetId, CurrentDataSourceRows = datasetVersionResponse.CurrentDataSourceRows, PreviousDataSourceRows = datasetVersionResponse.PreviousDataSourceRows, DisplayOperationActionSummary = true, OperationActionSummaryText = "A new data source with " + datasetVersionResponse.CurrentDataSourceRows + " data rows uploaded", }); }
private static UpdateDatasetPageModel CreatePageModel( IDatasetsApiClient datasetsApiClient = null, ILogger logger = null, IMapper mapper = null ) { return(new UpdateDatasetPageModel( datasetsApiClient ?? CreateDatasetsApiClient(), logger ?? CreateLogger(), MappingHelper.CreateFrontEndMapper() )); }
public AssignDatasetSchemaPageModel(ISpecsApiClient specsClient, IDatasetsApiClient datasetsClient, IMapper mapper, IAuthorizationHelper authorizationHelper) { Guard.ArgumentNotNull(specsClient, nameof(specsClient)); Guard.ArgumentNotNull(specsClient, nameof(mapper)); Guard.ArgumentNotNull(datasetsClient, nameof(datasetsClient)); Guard.ArgumentNotNull(authorizationHelper, nameof(authorizationHelper)); _specsClient = specsClient; _datasetsClient = datasetsClient; _mapper = mapper; _authorizationHelper = authorizationHelper; }
public DatasetDefinitionSearchService(IDatasetsApiClient datasetsClient, IMapper mapper, ILogger logger, IFeatureToggle featureToggle) { Guard.ArgumentNotNull(datasetsClient, nameof(datasetsClient)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(featureToggle, nameof(featureToggle)); _datasetsClient = datasetsClient; _mapper = mapper; _logger = logger; _featureToggle = featureToggle; }
public SpecGenerator(ISpecsApiClient specsApiClient, IDatasetsApiClient datasetsApiClient, ICalculationsApiClient calcsApiClient, ILogger logger) { Guard.ArgumentNotNull(specsApiClient, nameof(specsApiClient)); Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient)); Guard.ArgumentNotNull(calcsApiClient, nameof(calcsApiClient)); Guard.ArgumentNotNull(logger, nameof(logger)); _specsClient = specsApiClient; _datasetsClient = datasetsApiClient; _calcsClient = calcsApiClient; _logger = logger; }
public async Task SpecificationRelationshipsPageModel_GivenDatasetRelationshipsResponseReturnsBadRequest_ReturnsStatusCode500() { // Arrange string specificationId = Guid.NewGuid().ToString(); SpecificationSummary specification = new SpecificationSummary { Id = specificationId }; ApiResponse <SpecificationSummary> specificationResponse = new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, specification); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); specsApiClient .GetSpecificationSummary(Arg.Is(specificationId)) .Returns(specificationResponse); ApiResponse <IEnumerable <DatasetSpecificationRelationshipModel> > relationshipsResponse = new ApiResponse <IEnumerable <DatasetSpecificationRelationshipModel> >(HttpStatusCode.BadRequest); IDatasetsApiClient datasetsApiClient = CreateDatasetApiClient(); datasetsApiClient .GetDatasetSpecificationRelationshipsBySpecificationId(Arg.Is(specificationId)) .Returns(relationshipsResponse); ILogger logger = CreateLogger(); SpecificationRelationshipsPageModel pageModel = CreatePageModel(specsApiClient, datasetsApiClient, logger); // Act IActionResult result = await pageModel.OnGetAsync(specificationId); // Assert result .Should() .BeOfType <StatusCodeResult>(); StatusCodeResult statusCodeResult = result as StatusCodeResult; statusCodeResult .StatusCode .Should() .Be(500); logger .Received(1) .Error($"Failed to fetch specification relationships for specification id: {specificationId}"); logger .Received(1) .Error($"A null view model was returned"); }
public async Task OnGet_WhenDatasetResponseIsNullThenNotObjectFoundResultIsReturned() { // Arrange IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>(); ISpecsApiClient specsClient = Substitute.For <ISpecsApiClient>(); IMapper mapper = MappingHelper.CreateFrontEndMapper(); ILogger logger = Substitute.For <ILogger>(); string expectedSpecificationId = "1"; SpecificationSummary expectedSpecification = new SpecificationSummary { FundingPeriod = new Reference("2018", "17-18"), FundingStreams = new List <Reference>() { new Reference("2018", "18-19"), }, Description = "Test Spec", Id = "1", Name = "APT Final Baselines current year" }; AssignDatasetSchemaPageModel datasetSchemaPageModel = CreatePageModel(specsClient, datasetClient, mapper); specsClient .GetSpecificationSummary(expectedSpecificationId) .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, expectedSpecification)); IEnumerable <DatasetDefinition> dataDefn = null; datasetClient .GetDataDefinitions() .Returns(new ApiResponse <IEnumerable <DatasetDefinition> >(HttpStatusCode.NotFound, dataDefn)); // Act IActionResult result = await datasetSchemaPageModel.OnGet(expectedSpecificationId); // Assert result.Should().NotBeNull(); result.Should().BeOfType <NotFoundObjectResult>(); NotFoundObjectResult typeResult = result as NotFoundObjectResult; typeResult.Value.Should().Be("Check the data schema - one or more the data definitions aren't working"); }
public async Task OnPost_WhenModelIsInvalidAndDataDefinitionsNotReturnedCorrectly_ShoulReturnNotFoundObjectResult() { // Arrange string anyString = "anyString"; string expectedSpecificationId = "spec123"; SpecificationSummary expectedSpecification = new SpecificationSummary() { FundingPeriod = new Reference(anyString, anyString), Name = anyString, Description = anyString }; ISpecsApiClient mockSpecsClient = Substitute.For <ISpecsApiClient>(); mockSpecsClient .GetSpecificationSummary(Arg.Is(expectedSpecificationId)) .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, expectedSpecification)); IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>(); mockDatasetsApiClient .GetDataDefinitions() .Returns(new ApiResponse <IEnumerable <DatasetDefinition> >(HttpStatusCode.NotFound)); mockDatasetsApiClient .AssignDatasetSchema(Arg.Any <AssignDatasetSchemaModel>()) .Returns(HttpStatusCode.OK); IAuthorizationHelper mockAuthorizationHelper = Substitute.For <IAuthorizationHelper>(); mockAuthorizationHelper .DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Any <ISpecificationAuthorizationEntity>(), Arg.Is(SpecificationActionTypes.CanEditSpecification)) .Returns(true); AssignDatasetSchemaPageModel datasetSchemaPageModel = CreatePageModel(specsClient: mockSpecsClient, authorizationHelper: mockAuthorizationHelper, datasetsClient: mockDatasetsApiClient, mapper: MappingHelper.CreateFrontEndMapper()); datasetSchemaPageModel.AssignDatasetSchemaViewModel = new AssignDatasetSchemaViewModel(); datasetSchemaPageModel.ModelState.AddModelError(anyString, anyString); // Act IActionResult result = await datasetSchemaPageModel.OnPostAsync(expectedSpecificationId); // Assert result .Should().BeOfType <NotFoundObjectResult>() .Which .Value .Should().Be("Check the data schema - one or more the data definitions aren't working"); }
public async Task OnPost_WhenModelIsInvalidAndUserIsUnauthorizedToEditSpecification_ShouldReturnForbidResult() { // Arrange const string anyString = "any"; string expectedSpecificationId = "spec123"; const string fundingPeriodId = "2018"; const string fundingPeriodName = "1819"; const string specificationName = "Pe and sports spec"; const string specDescription = "test spec"; SpecificationSummary expectedSpecification = new SpecificationSummary() { FundingPeriod = new Reference(fundingPeriodId, fundingPeriodName), Name = specificationName, Description = specDescription }; ISpecsApiClient mockSpecsClient = Substitute.For <ISpecsApiClient>(); mockSpecsClient .GetSpecificationSummary(Arg.Is(expectedSpecificationId)) .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, expectedSpecification)); IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>(); mockDatasetsApiClient .GetDataDefinitions() .Returns(new ApiResponse <IEnumerable <DatasetDefinition> >(HttpStatusCode.OK, GetDummyDataDefinitions())); mockDatasetsApiClient .AssignDatasetSchema(Arg.Any <AssignDatasetSchemaModel>()) .Returns(HttpStatusCode.OK); IAuthorizationHelper mockAuthorizationHelper = Substitute.For <IAuthorizationHelper>(); mockAuthorizationHelper .DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Any <ISpecificationAuthorizationEntity>(), Arg.Is(SpecificationActionTypes.CanEditSpecification)) .Returns(false); AssignDatasetSchemaPageModel datasetSchemaPageModel = CreatePageModel(specsClient: mockSpecsClient, authorizationHelper: mockAuthorizationHelper, datasetsClient: mockDatasetsApiClient, mapper: MappingHelper.CreateFrontEndMapper()); datasetSchemaPageModel.AssignDatasetSchemaViewModel = new AssignDatasetSchemaViewModel(); datasetSchemaPageModel.ModelState.AddModelError(anyString, anyString); // Act IActionResult result = await datasetSchemaPageModel.OnPostAsync(expectedSpecificationId); // Assert result .Should().BeOfType <ForbidResult>(); }
public DatasetController(IDatasetsApiClient datasetApiClient, ILogger logger, IMapper mapper, ISpecificationsApiClient specificationsApiClient, IAuthorizationHelper authorizationHelper) { Guard.ArgumentNotNull(datasetApiClient, nameof(datasetApiClient)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(mapper, nameof(mapper)); _datasetApiClient = datasetApiClient; _logger = logger; _mapper = mapper; _specificationsApiClient = specificationsApiClient; _authorizationHelper = authorizationHelper; }
private static SpecificationRelationshipsPageModel CreatePageModel( ISpecsApiClient specsApiClient = null, IDatasetsApiClient datasetsApiClient = null, ILogger logger = null, IMapper mapper = null, IAuthorizationHelper authorizationHelper = null) { return(new SpecificationRelationshipsPageModel( specsApiClient ?? CreateSpecsApiClient(), datasetsApiClient ?? CreateDatasetApiClient(), logger ?? CreateLogger(), mapper ?? MappingHelper.CreateFrontEndMapper(), authorizationHelper ?? CreateMockAuthenticationHelper())); }
public SpecificationRelationshipsPageModel(ISpecsApiClient specsApiClient, IDatasetsApiClient datasetsApiClient, ILogger logger, IMapper mapper, IAuthorizationHelper authorizationHelper) { Guard.ArgumentNotNull(specsApiClient, nameof(specsApiClient)); Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(authorizationHelper, nameof(authorizationHelper)); _specsApiClient = specsApiClient; _datasetsApiClient = datasetsApiClient; _logger = logger; _mapper = mapper; _authorizationHelper = authorizationHelper; }
public async Task OnPost_WhenModelIsInvalidShouldPopulate_ShoulReturnCorrectRedirect() { // Arrange string anyString = "anyString"; string expectedSpecificationId = "spec123"; SpecificationSummary expectedSpecification = new SpecificationSummary() { FundingPeriod = new Reference(anyString, anyString), Name = anyString, Description = anyString }; ISpecsApiClient mockSpecsClient = Substitute.For <ISpecsApiClient>(); mockSpecsClient .GetSpecificationSummary(Arg.Is(expectedSpecificationId)) .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, expectedSpecification)); IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>(); mockDatasetsApiClient .GetDataDefinitions() .Returns(new ApiResponse <IEnumerable <DatasetDefinition> >(HttpStatusCode.OK, GetDummyDataDefinitions())); mockDatasetsApiClient .AssignDatasetSchema(Arg.Any <AssignDatasetSchemaModel>()) .Returns(HttpStatusCode.OK); IAuthorizationHelper mockAuthorizationHelper = Substitute.For <IAuthorizationHelper>(); mockAuthorizationHelper .DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Any <ISpecificationAuthorizationEntity>(), Arg.Is(SpecificationActionTypes.CanEditSpecification)) .Returns(true); AssignDatasetSchemaPageModel datasetSchemaPageModel = CreatePageModel(specsClient: mockSpecsClient, authorizationHelper: mockAuthorizationHelper, datasetsClient: mockDatasetsApiClient, mapper: MappingHelper.CreateFrontEndMapper()); datasetSchemaPageModel.AssignDatasetSchemaViewModel = new AssignDatasetSchemaViewModel(); // Act IActionResult result = await datasetSchemaPageModel.OnPostAsync(expectedSpecificationId); // Assert result .Should().BeOfType <RedirectResult>() .Subject .Url .Should().EndWith($"datasets/ListDatasetSchemas/{expectedSpecificationId}"); }
private PoliciesModel GetPoliciesModel( ISpecsApiClient specsApiClient = null, IDatasetsApiClient datasetsApiClient = null, ILogger logger = null, IAuthorizationHelper authorizationHelper = null ) { return(new PoliciesModel( specsApiClient ?? CreateSpecsApiClient(), datasetsApiClient ?? CreateDatasetsApiClient(), logger ?? CreateLogger(), MappingHelper.CreateFrontEndMapper(), authorizationHelper ?? TestAuthHelper.CreateAuthorizationHelperSubstitute(SpecificationActionTypes.CanApproveSpecification))); }