< Summary

Information
Class: ValidateLib.Metadata.Descriptors.ForeignKeyDescriptor
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Descriptors\ForeignKeyDescriptor.cs
Line coverage
91%
Covered lines: 21
Uncovered lines: 2
Coverable lines: 23
Total lines: 66
Line coverage: 91.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

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Descriptors\ForeignKeyDescriptor.cs

#LineLine coverage
 1using Newtonsoft.Json.Linq;
 2using ValidateLib.ErrorsAndWarnings.Errors;
 3using ValidateLib.ErrorsAndWarnings.Warnings;
 4using ValidateLib.Metadata.Descriptors.Interfaces;
 5using ValidateLib.Metadata.Parsers;
 6using ValidateLib.Metadata.Properties;
 7using ValidateLib.Metadata.PropertyParsers;
 8using ValidateLib.Metadata.PropertyParsers.ForeignKey;
 9
 10namespace ValidateLib.Metadata.Descriptors
 11{
 12    public class ForeignKeyDescriptor : DescriptorBase, INormalize, Interfaces.IParsable<ForeignKeyDescriptor>, IRequire
 13    {
 114        public ColumnReferenceProperty? columnReference { get; set; }
 115        public ObjectProperty<ReferenceDescriptor>? reference { get; set; }
 16        public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null)
 17        {
 118            List<Warning> errors = new List<Warning>();
 119            if (token.Type != JTokenType.Object) return errors;
 120            foreach (JProperty jProperty in token)
 21            {
 122                var results = NormalizeProperty(jProperty, context);
 123                errors.AddRange(results);
 24            }
 125            return errors;
 26        }
 27
 28        static public List<Warning> NormalizeProperty(JProperty property, Context context)
 29        {
 130            List<Warning> errors = new List<Warning>();
 131            if (CommonProperty.IsCommonProperty(property.Name)) return CommonProperty.Normalize(property.Value, context,
 132            else if (property.Name == "columnReference") return errors;
 133            else if (property.Name == "reference")
 134                return ObjectProperty<ReferenceDescriptor>.Normalize(property.Value, context, property);
 35            else
 36            {
 037                errors.Add(WarningFactory.GetUnknownPropertyWarning(property));
 038                return errors;
 39            }
 40
 41        }
 42
 143        public static IParser<ForeignKeyDescriptor> GetParser(List<Warning> warnings, ForeignKeyDescriptor? descriptor =
 44
 45
 46        public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings)
 47        {
 148            switch (property.Name)
 49            {
 50                case "columnReference":
 151                    return new ColumnReferencePropertyParser(warnings, this);
 52                case "reference":
 153                    return new ReferencePropertyParser(warnings, this);
 54                default:
 155                    return null;
 56            }
 57        }
 58
 59        public List<Warning> CheckRequiredPropertiesPresent()
 60        {
 161            if (reference is null) ErrorFactory.ThrowRequiredPropertyMissingError("reference", nameof(ForeignKeyDescript
 162            if (columnReference is null) ErrorFactory.ThrowRequiredPropertyMissingError("columnReference", nameof(Foreig
 163            return new List<Warning>();
 64        }
 65    }
 66}