public async Task OnGetAsync_GivenRelationshipIdAndGettingSourceModelReturnsOkButNullContent_Returns404() { // Arrange ApiResponse <SelectDataSourceModel> sourcesResponse = new ApiResponse <SelectDataSourceModel>(HttpStatusCode.OK); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetDatasourcesByRelationshipId(Arg.Is(relationshipId)) .Returns(sourcesResponse); ILogger logger = CreateLogger(); SelectSourceDatasetPageModel pageModel = CreatePageModel(datasetsApiClient, logger); // Act IActionResult result = await pageModel.OnGetAsync(relationshipId); //Assert result .Should() .BeOfType <NotFoundResult>(); logger .Received(1) .Error(Arg.Is($"Failed to fetch data sources with status code OK")); }
public async Task OnGetAsync_GivenRelationshipIdButGettingSourceModelReturnedInternalServerError_Returns404() { // Arrange SelectDataSourceModel model = new SelectDataSourceModel { SpecificationId = "abc123" }; ApiResponse <SelectDataSourceModel> sourcesResponse = new ApiResponse <SelectDataSourceModel>(HttpStatusCode.InternalServerError, model); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetDatasourcesByRelationshipId(Arg.Is(relationshipId)) .Returns(sourcesResponse); ILogger logger = CreateLogger(); SelectSourceDatasetPageModel pageModel = CreatePageModel(datasetsApiClient, logger); // Act IActionResult result = await pageModel.OnGetAsync(relationshipId); //Assert result .Should() .BeOfType <NotFoundResult>(); logger .Received(1) .Error(Arg.Is($"Failed to fetch data sources with status code InternalServerError")); }
public async Task OnGetAsync_GivenRelationshipIdAndGetsModelWithoutDatasets_Returns200() { // Arrange SelectDataSourceModel sourceModel = new SelectDataSourceModel(); ApiResponse <SelectDataSourceModel> sourcesResponse = new ApiResponse <SelectDataSourceModel>(HttpStatusCode.OK, sourceModel); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetDatasourcesByRelationshipId(Arg.Is(relationshipId)) .Returns(sourcesResponse); ILogger logger = CreateLogger(); SelectSourceDatasetPageModel pageModel = CreatePageModel(datasetsApiClient, logger); // Act IActionResult result = await pageModel.OnGetAsync(relationshipId); //Assert result .Should() .BeOfType <PageResult>(); }
public void OnGetAsync_GivenNullOrEmptyRelationshipId_ThrowsArgumentNullException() { // Arrange SelectSourceDatasetPageModel pageModel = CreatePageModel(); // Act Func <Task> test = async() => await pageModel.OnGetAsync(null); // Assert test .Should() .ThrowExactly <ArgumentNullException>(); }
public async Task OnGetAsync_GivenRelationshipIdAndGetsModelWithDatasets_Returns200() { // Arrange SelectDataSourceModel sourceModel = new SelectDataSourceModel(); sourceModel.Datasets = new[] { new DatasetVersionsModel { Id = "ds-id", Name = "ds name", Versions = new[] { 1 } } }; ApiResponse <SelectDataSourceModel> sourcesResponse = new ApiResponse <SelectDataSourceModel>(HttpStatusCode.OK, sourceModel); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetDatasourcesByRelationshipId(Arg.Is(relationshipId)) .Returns(sourcesResponse); ILogger logger = CreateLogger(); SelectSourceDatasetPageModel pageModel = CreatePageModel(datasetsApiClient, logger); // Act IActionResult result = await pageModel.OnGetAsync(relationshipId); //Assert result .Should() .BeOfType <PageResult>(); pageModel .ViewModel .Datasets .Count() .Should() .Be(1); pageModel .IsAuthorizedToMap .Should().BeTrue(); }
public async Task OnGetAsync_GivenUserDoesNotHaveMapDatasetsPermission_ThenReturnPageResultWithAuthorizedToEditFlagSetToFalse() { // Arrange SelectDataSourceModel sourceModel = new SelectDataSourceModel(); sourceModel.Datasets = new[] { new DatasetVersionsModel { Id = "ds-id", Name = "ds name", Versions = new[] { 1 } } }; ApiResponse <SelectDataSourceModel> sourcesResponse = new ApiResponse <SelectDataSourceModel>(HttpStatusCode.OK, sourceModel); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetDatasourcesByRelationshipId(Arg.Is(relationshipId)) .Returns(sourcesResponse); ILogger logger = CreateLogger(); IAuthorizationHelper mockAuthorizationHelper = TestAuthHelper.CreateAuthorizationHelperSubstitute(SpecificationActionTypes.CanMapDatasets, false); SelectSourceDatasetPageModel pageModel = CreatePageModel(datasetsApiClient, logger, authorizationHelper: mockAuthorizationHelper); // Act IActionResult result = await pageModel.OnGetAsync(relationshipId); //Assert result .Should() .BeOfType <PageResult>(); pageModel .IsAuthorizedToMap .Should().BeFalse(); }