Exemple #1
0
        public async Task SaveFundingSchema_WhenEmptySchemaProvided_ReturnsBadRequest(string schema)
        {
            //Arrange
            FundingSchemaService fundingSchemaService = CreateFundingSchemaService();

            //Act
            IActionResult result = await fundingSchemaService.SaveFundingSchema(createdAtActionName, createdAtControllerName, schema);

            //Assert
            result
            .Should()
            .BeAssignableTo <BadRequestObjectResult>()
            .Which
            .Value
            .Should()
            .Be("Null or empty funding schema was provided.");
        }
Exemple #2
0
        public async Task SaveFundingSchema_WhenNoVersionIsSet_ReturnsBadRequest(string resourcePath)
        {
            //arrange
            FundingSchemaService fundingSchemaService = CreateFundingSchemaService();

            //Act
            IActionResult result = await fundingSchemaService.SaveFundingSchema(
                createdAtActionName, createdAtControllerName, CreateSchemaFile(resourcePath));

            //Assert
            result
            .Should()
            .BeAssignableTo <BadRequestObjectResult>()
            .Which
            .Value
            .Should()
            .Be("An invalid schema version was provided");
        }
Exemple #3
0
        public async Task SaveFundingSchema_WhenSavingIsSuccessful_ReturnsCreatedAtResult()
        {
            //arrange
            string json = CreateSchemaFile("CalculateFunding.Services.Policy.Resources.LogicalModel.json");

            IFundingSchemaRepository fundingSchemaRepository = CreateFundingSchemaRepository();

            ILogger logger = CreateLogger();

            FundingSchemaService fundingSchemaService = CreateFundingSchemaService(logger, fundingSchemaRepository: fundingSchemaRepository);

            //Act
            IActionResult result = await fundingSchemaService.SaveFundingSchema(
                createdAtActionName, createdAtControllerName, json);

            //Assert
            result
            .Should()
            .BeAssignableTo <CreatedAtActionResult>();

            CreatedAtActionResult actionResult = result as CreatedAtActionResult;

            actionResult
            .ActionName
            .Should()
            .Be("GetFundingSchemaByVersion");

            actionResult
            .ControllerName
            .Should()
            .Be("SchemaController");

            actionResult
            .RouteValues["schemaVersion"].ToString()
            .Should()
            .Be("1.0");
        }
Exemple #4
0
        public async Task SaveFundingSchema_WhenVersionDoesNotExistButSavingToBlobStorageCausesAnError_ReturnsNoContentResult()
        {
            //arrange
            const string version = "1.0";

            string blobName = $"{fundingSchemaFolder}/{version}.json";

            string json = CreateSchemaFile("CalculateFunding.Services.Policy.Resources.LogicalModel.json");

            IFundingSchemaRepository fundingSchemaRepository = CreateFundingSchemaRepository();

            fundingSchemaRepository
            .When(x => x.SaveFundingSchemaVersion(Arg.Any <string>(), Arg.Any <byte[]>()))
            .Do(x => { throw new Exception(); });

            ILogger logger = CreateLogger();

            FundingSchemaService fundingSchemaService = CreateFundingSchemaService(logger, fundingSchemaRepository: fundingSchemaRepository);

            //Act
            IActionResult result = await fundingSchemaService.SaveFundingSchema(
                createdAtActionName, createdAtControllerName, json);

            //Assert
            result
            .Should()
            .BeAssignableTo <InternalServerErrorResult>()
            .Which
            .Value
            .Should()
            .Be("Error occurred uploading funding schema");

            logger
            .Received(1)
            .Error(Arg.Any <Exception>(), Arg.Is($"Failed to save funding schema '{blobName}' to blob storage"));
        }
Exemple #5
0
        public async Task SaveFundingSchema_WhenInvalidSchemaProvided_ReturnsBadRequest()
        {
            //Arrange

            ILogger logger = CreateLogger();

            FundingSchemaService fundingSchemaService = CreateFundingSchemaService(logger);

            //Act
            IActionResult result = await fundingSchemaService.SaveFundingSchema(createdAtActionName, createdAtControllerName, "Blah Blah");

            //Assert
            result
            .Should()
            .BeAssignableTo <BadRequestObjectResult>()
            .Which
            .Value
            .Should()
            .Be("Failed to parse request body as a valid json schema.");

            logger
            .Received(1)
            .Error(Arg.Any <Exception>(), Arg.Is("Failed to parse request body as a valid json schema."));
        }