public void ValidateField_WhenGivenFieldIsLessThanMinimum_ShouldReturnCorrectResult() { // Arrange DatasetUploadCellReference anyCellReference = new DatasetUploadCellReference(1, 1); MaxAndMinFieldValidator maxAndMinFieldValidator = new MaxAndMinFieldValidator(); FieldDefinition fieldDefinition = new FieldDefinition { Description = "Count of high needs students aged 16-19 from the ILR R04 collection", Id = "1100013", IdentifierFieldType = null, MatchExpression = null, Maximum = 10000, Minimum = 9000, Name = "Number of students", Required = false, Type = FieldType.Integer }; Field field = new Field(anyCellReference, 8999, fieldDefinition); // Act FieldValidationResult result = maxAndMinFieldValidator.ValidateField(field); // Assert result.FieldValidated.CellReference.Should().Be(anyCellReference); result.ReasonOfFailure.Should().Be(FieldValidationResult.ReasonForFailure.MaxOrMinValueExceeded); }
public void ValidateField_WhenGivenDecimalFieldIsMin_ShouldReturnCorrectResult() { // Arrange DatasetUploadCellReference anyCellReference = new DatasetUploadCellReference(1, 1); MaxAndMinFieldValidator maxAndMinFieldValidator = new MaxAndMinFieldValidator(); FieldDefinition fieldDefinition = new FieldDefinition { Description = "Count of high needs students aged 16-19 from the ILR R04 collection", Id = "1100013", IdentifierFieldType = null, MatchExpression = null, Maximum = 10000, Minimum = 9000, Name = "Number of students", Required = false, Type = FieldType.Integer }; Field field = new Field(anyCellReference, 10000m, fieldDefinition); // Act FieldValidationResult result = maxAndMinFieldValidator.ValidateField(field); // Assert result.Should().BeNull(); }
public void ValidateField_GivenProviderIdentifierIsNotBlank_ShouldReturnCorrectResult() { // Arrange ProviderIdentifierBlankValidator validatorUnderTest = new ProviderIdentifierBlankValidator(); DatasetUploadCellReference anyCellReference = new DatasetUploadCellReference(0, 2); FieldDefinition definition = new FieldDefinition { Name = "UPIN", Description = "The UPIN identifier for the provider", Id = "1100003", IdentifierFieldType = IdentifierFieldType.UPIN, MatchExpression = null, Maximum = null, Minimum = null, Required = false, Type = FieldType.String }; Field field = new Field(anyCellReference, "107013", definition); // Act FieldValidationResult result = validatorUnderTest.ValidateField(field); // Assert result.Should().BeNull(); }
public void FormatExcelSheetBasedOnErrors(IDatasetUploadValidationResult validationResult) { ExcelWorksheet workbookWorksheet = _excelPackage.Workbook.Worksheets[1]; foreach (FieldValidationResult fieldValidationResult in validationResult.FieldValidationFailures) { DatasetUploadCellReference cellReferenceOfValidatedField = fieldValidationResult.FieldValidated.CellReference; ExcelRange cell = workbookWorksheet.Cells[cellReferenceOfValidatedField.RowIndex, cellReferenceOfValidatedField.ColumnIndex]; Color colorCodeForFailure = fieldValidationResult.ReasonOfFailure.GetColorCodeForFailure(); cell.Style.Fill.PatternType = ExcelFillStyle.Solid; cell.Style.Fill.BackgroundColor.SetColor(colorCodeForFailure); } _excelPackage.Save(); }
public void CreateHeaderErrorSheet_WhenNotAlreadyExists_ShouldCreateWithExpectedFormatting() { using (ExcelPackage excelPackage = new ExcelPackage()) { // Arrange List <Tuple <string, Color> > expectedColors = new List <Tuple <string, Color> > { new Tuple <string, Color>("Data type mismatch", Color.FromArgb(255, 138, 80)), new Tuple <string, Color>("Max. or Min. value exceeded", Color.FromArgb(255, 217, 102)), new Tuple <string, Color>("Provider ID value missing", Color.FromArgb(255, 255, 114)), new Tuple <string, Color>("Duplicate entries in the provider ID column", Color.FromArgb(122, 124, 255)), new Tuple <string, Color>("Provider ID does not exist in the current funding stream provider", Color.FromArgb(255, 178, 255)) }; // Act SheetTemplate sheetTemplateCreated = ErrorSheetTemplateCreator.CreateHeaderErrorSheet(excelPackage); ExcelWorksheet templateWorkSheet = sheetTemplateCreated.ExcelWorksheet; DatasetUploadCellReference startingCellReference = sheetTemplateCreated.StartingCell; // Assert ExcelRange headerCell = templateWorkSheet.Cells[1, 1]; headerCell.Value.Should().Be("Cell level error key"); int firstColumn = 1; int errorColoringStartRow = 2; for (int row = errorColoringStartRow, index = 0; row < errorColoringStartRow + expectedColors.Count; row++, index++) { Tuple <string, Color> expectedColor = expectedColors[index]; ExcelRange cell = templateWorkSheet.Cells[row, firstColumn]; cell.Style.Fill.BackgroundColor.Rgb.Should().BeEquivalentTo(ToAsciRgbRepresentation(expectedColor.Item2)); } int fieldsMissingTextRow = expectedColors.Count + errorColoringStartRow + 2; ExcelRange fieldsMissingCell = templateWorkSheet.Cells[fieldsMissingTextRow, firstColumn]; fieldsMissingCell.Value.Should().Be( "Data schema fields missing from first sheet of Excel file to be uploaded"); startingCellReference.ColumnIndex.Should().Be(firstColumn); startingCellReference.RowIndex.Should().Be(fieldsMissingTextRow + 1); } }
public void FormatExcelSheetBasedOnErrors(IDatasetUploadValidationResult validationResult) { if (!validationResult.IsValid()) { SheetTemplate templateReturned = ErrorSheetTemplateCreator.CreateHeaderErrorSheet(_excelPackage); List <HeaderValidationResult> headerValidationFailures = validationResult.HeaderValitionFailures.ToList(); DatasetUploadCellReference errorInsertionsStartingCell = templateReturned.StartingCell; ExcelWorksheet headerErrorsWorksheet = _excelPackage.Workbook.Worksheets[templateReturned.ExcelWorksheet.Name]; for (int index = 0, rowIndex = errorInsertionsStartingCell.RowIndex; index < headerValidationFailures.Count; rowIndex++, index++) { ExcelRange cellToInsertErrorInto = headerErrorsWorksheet.Cells[rowIndex, 1]; cellToInsertErrorInto.Value = headerValidationFailures[index].FieldDefinitionValidated.Name; } } }
public SheetTemplate(ExcelWorksheet excelWorksheet, DatasetUploadCellReference startingCell) { ExcelWorksheet = excelWorksheet; StartingCell = startingCell; }