public void FundingLine_03_No_Error_WhenContractEndDate_IsNull(string year, string month) { _contractAllocations = new List <ContractAllocation>() { new ContractAllocation() { FundingStreamPeriodCode = "APPS2021", StartDate = new DateTime(2021, 06, 01), EndDate = null } }; var easRecord = new EasCsvRecord() { AdjustmentType = "adjustment", FundingLine = "FundingLine2021", CalendarYear = year, CalendarMonth = month, Value = "10" }; _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); var result = _validator.Validate(easRecord); Assert.DoesNotContain(result.Errors, x => x.ErrorCode.Equals("FundingLine_03")); }
public DevolvedSourceOfFundingValidations() { easRecord = new EasCsvRecord() { CalendarMonth = "8", CalendarYear = "2020", Value = "1", AdjustmentType = "adjustmentType" }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); }
public void FundingLine_02_HaveError_When_ContractTypeIsNotFound_For_A_FundingLine() { var easRecord = new EasCsvRecord() { CalendarMonth = "8", CalendarYear = "2020", Value = "1", FundingLine = "FundingLineWithoutContract", AdjustmentType = "adjustmentType" }; _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.FundingLine, easRecord).WithErrorCode("FundingLine_02"); }
public void HaveError_WhenCalendarMonth_Is_NotValid(string calendarMonth) { var easRecord = new EasCsvRecord() { CalendarMonth = calendarMonth, CalendarYear = "2020", Value = "1", AdjustmentType = "AdjustmentType", FundingLine = "FundingLine" }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); _validator = new BusinessRulesValidator(null, null, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.CalendarMonth, easRecord).WithErrorCode("CalendarMonth_01"); }
public void HaveError_For_Invalid_FundingLine_Lookup() { var easRecord = new EasCsvRecord() { CalendarMonth = "8", CalendarYear = "2020", Value = "1", FundingLine = paymentTypes[0].FundingLine.Name, AdjustmentType = "InvalidAdjustmentType" }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); _validator = new BusinessRulesValidator(null, null, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.AdjustmentType, easRecord).WithErrorCode("AdjustmentType_02"); }
public void FundingLine_01_HaveError_When_FundingLine_IsNotFound(string fundingLine) { var easRecord = new EasCsvRecord() { CalendarMonth = "8", CalendarYear = "2020", Value = "1", FundingLine = fundingLine, AdjustmentType = "adjustmentType" }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); _validator = new BusinessRulesValidator(null, null, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.FundingLine, easRecord).WithErrorCode("FundingLine_01"); }
public void HaveError_For_Empty_Value(string value) { var easRecord = new EasCsvRecord() { CalendarMonth = "8", CalendarYear = "2018", FundingLine = paymentTypes[0].FundingLine.Name, AdjustmentType = "adjustmentType", Value = value }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2018, 09, 01)); _validator = new BusinessRulesValidator(null, null, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.Value, easRecord).WithErrorCode("Value_01"); }
public void HaveErrorWhenCalendarMonthAndYearAreNotInTheAcademicYear(string calendarMonth, string calendarYear) { var easRecord = new EasCsvRecord() { CalendarMonth = calendarMonth, CalendarYear = calendarYear, Value = "1", AdjustmentType = "AdjustmentType", FundingLine = "FundingLine" }; // Mock future date , so that validation doesn't fail on Calendar Month future date dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2021, 10, 01)); _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.CalendarMonth, easRecord).WithErrorCode("CalendarYearCalendarMonth_02"); }
public void Not_HaveAnError_WhenCalendarYear_Is_Valid() { var easRecord = new EasCsvRecord() { CalendarMonth = "8", CalendarYear = "2020", Value = "1", AdjustmentType = "AdjustmentType", FundingLine = "FundingLine" }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); var result = _validator.Validate(easRecord); Assert.True(result.IsValid); }
public void AllowValidAlphaNumericCharacters_When_Validating_AdjustmentType(string adjustmentType) { var easRecord = new EasCsvRecord() { CalendarMonth = "8", CalendarYear = "2020", Value = "1", FundingLine = "Funding-123+.Line", AdjustmentType = adjustmentType }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); var result = _validator.Validate(easRecord); Assert.True(result.IsValid); }
public void FundingLine_03_NotHaveError_When_ContractTypeIsNotRequiredForFundline(string fundline) { var easRecord = new EasCsvRecord() { CalendarMonth = "7", CalendarYear = "2020", Value = "1", FundingLine = fundline, AdjustmentType = "adjustmentType" }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); var result = _validator.Validate(easRecord); Assert.DoesNotContain(result.Errors, x => x.ErrorCode.Equals("FundingLine_03")); }
public void NotHaveErrorWhenCalendarMonthAndYearAreInTheAcademicYear(string calendarMonth, string calendarYear) { var easRecord = new EasCsvRecord() { CalendarMonth = calendarMonth, CalendarYear = calendarYear, Value = "1", AdjustmentType = "AdjustmentType", FundingLine = "FundingLine" }; // Mock future date , so that validation doesn't fail on Calendar Month future date dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2021, 10, 01)); _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); var result = _validator.Validate(easRecord); Assert.False(result?.Errors != null && result.Errors.Any(x => x.ErrorCode == $"CalendarYearCalendarMonth_02")); }
public void HaveError_WhenCalendarYear_Is_NotValid(string calendarYear) { var easRecord = new EasCsvRecord() { CalendarMonth = "12", CalendarYear = calendarYear, Value = "1", AdjustmentType = "AdjustmentType", FundingLine = "FundingLine" }; dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(new DateTime(2020, 09, 01)); _validator = new BusinessRulesValidator(null, null, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.CalendarYear, easRecord).WithErrorCode("CalendarYear_01"); var result = _validator.Validate(easRecord); //Assert.False(result.IsValid); //Assert.Equal("The CalendarYear is not valid.", result.Errors[0].ErrorMessage); //Assert.Equal("CalendarYear_01", result.Errors[0].ErrorCode); }
private List <EasCsvRecord> BuildEasCsvRecords(List <PaymentType> allPaymentTypes, List <EasSubmissionValue> easSubmissionValues) { List <EasCsvRecord> records = new List <EasCsvRecord>(); foreach (var submissionValue in easSubmissionValues) { var paymentType = allPaymentTypes.FirstOrDefault(x => x.PaymentId == submissionValue.PaymentId); var record = new EasCsvRecord { AdjustmentType = paymentType.AdjustmentType.Name, FundingLine = paymentType.FundingLine.Name, Value = submissionValue.PaymentValue.ToString(CultureInfo.InvariantCulture), CalendarYear = CollectionPeriodHelper.GetCalendarYearAndMonth(submissionValue.CollectionPeriod).Item1.ToString(), CalendarMonth = CollectionPeriodHelper.GetCalendarYearAndMonth(submissionValue.CollectionPeriod).Item2.ToString(), DevolvedAreaSourceOfFunding = submissionValue.DevolvedAreaSoF == -1? null : submissionValue.DevolvedAreaSoF.ToString() }; records.Add(record); } return(records); }
private ValidationErrorModel BuildValidationErrorModel(EasCsvRecord record, string errorCode, ValidationErrorRule validationErrorRule) { if (validationErrorRule == null) { throw new Exception($"ValidationErrorRule Not found for the error code: {errorCode}"); } var errorModel = new ValidationErrorModel() { FundingLine = record.FundingLine, AdjustmentType = record.AdjustmentType, CalendarYear = record.CalendarYear, CalendarMonth = record.CalendarMonth, Value = record.Value, ErrorMessage = validationErrorRule.Message, RuleName = errorCode, Severity = validationErrorRule.Severity, DevolvedAreaSoF = record.DevolvedAreaSourceOfFunding }; return(errorModel); }
public void FundingLine_02_Have_Error_WhenContractEndDate_IsLessThan_EasRecordDate(string year, string month) { _contractAllocations = new List <ContractAllocation>() { new ContractAllocation() { FundingStreamPeriodCode = "APPS2021", EndDate = new DateTime(2021, 07, 31) } }; var easRecord = new EasCsvRecord() { AdjustmentType = "adjustment", FundingLine = "FundingLine2021", CalendarYear = year, CalendarMonth = month, Value = "10" }; _validator = new BusinessRulesValidator(_contractAllocations, _fundingLineContractTypeMappings, paymentTypes, null, null, dateTimeProviderMock.Object, 1); _validator.ShouldHaveValidationErrorFor(x => x.FundingLine, easRecord).WithErrorCode("FundingLine_02"); }