< Summary

Information
Class: ValidateLib.TabularData.Datatypes.DateDatatypes.GBaseDT
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\DateDatatypes\GBaseDT.cs
Line coverage
25%
Covered lines: 9
Uncovered lines: 26
Coverable lines: 35
Total lines: 77
Line coverage: 25.7%
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

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\DateDatatypes\GBaseDT.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2using System.Xml;
 3using ValidateLib.ErrorsAndWarnings.Errors;
 4using ValidateLib.Metadata.Descriptors;
 5
 6namespace ValidateLib.TabularData.Datatypes.DateDatatypes
 7{
 8    public abstract class GBaseDT : BaseDT
 9    {
 110        public DateTime Value { get; set; }
 111        public GBaseDT() { }
 112        protected GBaseDT(string stringValue) : base(stringValue)
 13        {
 114            CheckLexicalSpace(stringValue);
 15            try
 16            {
 117                Value = XmlConvert.ToDateTime(stringValue, XmlDateTimeSerializationMode.RoundtripKind);
 118            }
 19
 120            catch (Exception)
 21            {
 122                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 023            }
 24
 125        }
 026        protected GBaseDT(string stringValue, FormatDescriptor format) : base(stringValue, format)
 27        {
 028            VerifyFormatPatternIsValidRegex(format.pattern!);
 029            ValidateFormat(stringValue, format.pattern!);
 030            CheckLexicalSpace(stringValue);
 31            try
 32            {
 033                Value = XmlConvert.ToDateTime(stringValue, XmlDateTimeSerializationMode.RoundtripKind);
 034            }
 35
 036            catch (Exception)
 37            {
 038                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 039            }
 040        }
 41
 42        void ValidateFormat(string stringValue, string formatPattern)
 43        {
 044            if (!Regex.IsMatch(stringValue, formatPattern))
 045                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 046        }
 47
 48        public virtual void CheckLexicalSpace(string stringValue)
 49        {
 50
 051        }
 52
 53        override public int CompareTo(BaseDT? other)
 54        {
 055            if (other is null)
 056                return 1;
 057            if (other is not GBaseDT)
 058                throw new ArgumentException();
 059            var typedOther = (GBaseDT)other;
 060            return Value.CompareTo(typedOther.Value);
 61
 62        }
 63        public override bool IsPatternValid(FormatDescriptor format)
 64        {
 65            try
 66            {
 067                Regex regex = new Regex(format.pattern!);
 068                return true;
 69            }
 070            catch (Exception)
 71            {
 072                return false;
 73            }
 074        }
 75
 76    }
 77}