public async Task ValidateFundingTemplate_GivenTemplateWithValidFundingPeriodIdButNoFundingPeriodExists_ReturnsValidationResultWithErrors() { //Arrange const string schemaVersion = "1.0"; FundingStream fundingStream = new FundingStream(); JsonSchema schema = JsonSchema.FromType <TestTemplate_schema_1_0>(); TestTemplate_schema_1_0 testClassWithFunding = new TestTemplate_schema_1_0 { SchemaVersion = schemaVersion, Funding = new { templateVersion = "2.1", fundingStream = new { code = "PES" }, fundingPeriod = new { id = "AY-2020" } } }; string fundingTemplate = JsonConvert.SerializeObject(testClassWithFunding); string fundingSchema = schema.AsJson(); string blobName = $"{fundingSchemaFolder}/{schemaVersion}.json"; IFundingSchemaRepository fundingSchemaRepository = CreateFundingSchemaRepository(); fundingSchemaRepository .SchemaVersionExists(Arg.Is(blobName)) .Returns(true); fundingSchemaRepository .GetFundingSchemaVersion(Arg.Is(blobName)) .Returns(fundingSchema); IPolicyRepository policyRepository = CreatePolicyRepository(); policyRepository .GetFundingStreamById(Arg.Is("PES")) .Returns(fundingStream); FundingTemplateValidationService fundingTemplateValidationService = CreateFundingTemplateValidationService( fundingSchemaRepository: fundingSchemaRepository, policyRepository: policyRepository); //Act FundingTemplateValidationResult result = await fundingTemplateValidationService.ValidateFundingTemplate(fundingTemplate, "PES", "AY-2020", "2.1"); //Assert result .IsValid .Should() .BeFalse(); result .Errors[0] .ErrorMessage .Should() .Be("A funding period could not be found for funding period id 'AY-2020'"); }
public async Task ValidateFundingTemplate_Schema_1_0_GivenTemplateIsValidAndValuesExtracted_ReturnsValidationResultWithNoErrors() { //Arrange const string schemaVersion = "1.0"; FundingStream fundingStream = new FundingStream(); JsonSchema schema = JsonSchema.FromType <TestTemplate_schema_1_0>(); TestTemplate_schema_1_0 testClassWithFunding = new TestTemplate_schema_1_0 { SchemaVersion = schemaVersion, Funding = new { templateVersion = "2.1", fundingStream = new { code = "PES" }, fundingPeriod = new { id = "AY-2020" } } }; string fundingTemplate = JsonConvert.SerializeObject(testClassWithFunding); string fundingSchema = schema.AsJson(); string blobName = $"{fundingSchemaFolder}/{schemaVersion}.json"; IFundingSchemaRepository fundingSchemaRepository = CreateFundingSchemaRepository(); fundingSchemaRepository .SchemaVersionExists(Arg.Is(blobName)) .Returns(true); fundingSchemaRepository .GetFundingSchemaVersion(Arg.Is(blobName)) .Returns(fundingSchema); IPolicyRepository policyRepository = CreatePolicyRepository(); policyRepository .GetFundingStreamById(Arg.Is("PES")) .Returns(fundingStream); policyRepository .GetFundingPeriodById(Arg.Is("AY-2020")) .Returns(new FundingPeriod()); FundingTemplateValidationService fundingTemplateValidationService = CreateFundingTemplateValidationService( fundingSchemaRepository: fundingSchemaRepository, policyRepository: policyRepository); //Act FundingTemplateValidationResult result = await fundingTemplateValidationService.ValidateFundingTemplate(fundingTemplate, "PES", "AY-2020", "2.1"); //Assert result .Errors .Should() .BeEmpty(); result .TemplateVersion .Should() .Be("2.1"); result .SchemaVersion .Should() .Be("1.0"); result .FundingStreamId .Should() .Be("PES"); result .FundingPeriodId .Should() .Be("AY-2020"); result .IsValid .Should() .BeTrue(); }