< Summary

Information
Class: ValidateLib.TabularData.Validation.ValidationRules.CellValueConstraintValidationRule
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Validation\ValidationRules\CellValueConstraintValidationRule.cs
Line coverage
83%
Covered lines: 35
Uncovered lines: 7
Coverable lines: 42
Total lines: 84
Line coverage: 83.3%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBlocks covered Blocks not covered
ValidateCell(...)2521
AreValueConstraintsMet(...)550

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Validation\ValidationRules\CellValueConstraintValidationRule.cs

#LineLine coverage
 1using ValidateLib.ErrorsAndWarnings.Errors;
 2using ValidateLib.Metadata.Descriptors;
 3using ValidateLib.TabularData.AnnotatedTabularDataModel;
 4using ValidateLib.TabularData.Datatypes;
 5
 6namespace ValidateLib.TabularData.Validation.ValidationRules
 7{
 8    public class CellValueConstraintValidationRule : ICellValidationRule
 9    {
 10        public void ValidateCell(Cell annotatedCell)
 11        {
 12            // this means that the cell is in an column which does not have a descriptor
 113            if (annotatedCell.column is null)
 114                return;
 115            DatatypeDescriptor datatypeDescriptor = annotatedCell.column!.datatype!;
 16
 117            if (datatypeDescriptor._base is null || datatypeDescriptor._base._value is null)
 018                return;
 19
 120            var dt = DatatypeFactory.GetDatatype(null, datatypeDescriptor._base!._value!, null);
 121            if (dt is not IValue)
 122                return;
 23
 124            switch (annotatedCell.cellType)
 25            {
 26                case CellType.NULL:
 127                    bool areMet = AreValueConstraintsMet(null, datatypeDescriptor);
 128                    if (!areMet)
 029                        annotatedCell.errors.Add(ErrorFactory.GetDatatypeValueConstraintVE(annotatedCell));
 030                    break;
 31                case CellType.SIMPLE_VALUE:
 132                    areMet = AreValueConstraintsMet(annotatedCell.value, datatypeDescriptor);
 133                    if (!areMet)
 134                        annotatedCell.errors.Add(ErrorFactory.GetDatatypeValueConstraintVE(annotatedCell));
 135                    break;
 36                case CellType.LIST:
 037                    foreach (var value in annotatedCell.cellValues)
 38                    {
 039                        areMet = AreValueConstraintsMet(value, datatypeDescriptor);
 040                        if (!areMet)
 041                            annotatedCell.errors.Add(ErrorFactory.GetDatatypeValueConstraintVE(annotatedCell));
 42                    }
 43                    break;
 44            }
 145        }
 46
 47        bool AreValueConstraintsMet(BaseDT? dt, DatatypeDescriptor datatypeDescriptor)
 48        {
 149            bool areMet = true;
 150            if (datatypeDescriptor.minimum is not null && datatypeDescriptor.minimum._value is not null)
 51            {
 152                var minimum = DatatypeFactory.GetDatatype(datatypeDescriptor.minimum._value, datatypeDescriptor._base!._
 153                areMet &= minimum.CompareTo(dt) <= 0;
 54            }
 155            if (datatypeDescriptor.minInclusive is not null && datatypeDescriptor.minInclusive._value is not null)
 56            {
 157                var minInclusive = DatatypeFactory.GetDatatype(datatypeDescriptor.minInclusive._value, datatypeDescripto
 158                areMet &= minInclusive.CompareTo(dt) <= 0;
 59            }
 160            if (datatypeDescriptor.minExclusive is not null && datatypeDescriptor.minExclusive._value is not null)
 61            {
 162                var minExclusive = DatatypeFactory.GetDatatype(datatypeDescriptor.minExclusive._value, datatypeDescripto
 163                areMet &= minExclusive.CompareTo(dt) < 0;
 64            }
 65
 166            if (datatypeDescriptor.maximum is not null && datatypeDescriptor.maximum._value is not null)
 67            {
 168                var maximum = DatatypeFactory.GetDatatype(datatypeDescriptor.maximum._value, datatypeDescriptor._base!._
 169                areMet &= maximum.CompareTo(dt) >= 0;
 70            }
 171            if (datatypeDescriptor.maxInclusive is not null && datatypeDescriptor.maxInclusive._value is not null)
 72            {
 173                var maxInclusive = DatatypeFactory.GetDatatype(datatypeDescriptor.maxInclusive._value, datatypeDescripto
 174                areMet &= maxInclusive.CompareTo(dt) >= 0;
 75            }
 176            if (datatypeDescriptor.maxExclusive is not null && datatypeDescriptor.maxExclusive._value is not null)
 77            {
 178                var maxExclusive = DatatypeFactory.GetDatatype(datatypeDescriptor.maxExclusive._value, datatypeDescripto
 179                areMet &= maxExclusive.CompareTo(dt) > 0;
 80            }
 181            return areMet;
 82        }
 83    }
 84}