< Summary

Information
Class: ValidateLib.Metadata.Descriptors.ReferenceDescriptor
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Descriptors\ReferenceDescriptor.cs
Line coverage
95%
Covered lines: 23
Uncovered lines: 1
Coverable lines: 24
Total lines: 72
Line coverage: 95.8%
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\ReferenceDescriptor.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.Reference;
 9
 10namespace ValidateLib.Metadata.Descriptors
 11{
 12    public class ReferenceDescriptor : DescriptorBase, INormalize, Interfaces.IParsable<ReferenceDescriptor>, IRequiredP
 13    {
 114        public LinkProperty? resource { get; set; }
 115        public LinkProperty? schemaReference { get; set; }
 116        public ColumnReferenceProperty? columnReference { get; set; }
 17
 18        public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null)
 19        {
 120            List<Warning> errors = new List<Warning>();
 121            if (token.Type != JTokenType.Object) return errors;
 122            foreach (JProperty jProperty in token)
 23            {
 124                var results = NormalizeProperty(jProperty, context);
 125                Descriptor.MergeTwoList(errors, results);
 26            }
 127            return errors;
 28        }
 29
 30        static protected List<Warning> NormalizeProperty(JProperty property, Context context)
 31        {
 132            List<Warning> warnings = new List<Warning>();
 133            switch (property.Name)
 34            {
 35                case "resource":
 36                case "schemaReference":
 137                    return LinkProperty.Normalize(property.Value, context, property);
 38                case "columnReference":
 139                    return warnings;
 40                default:
 141                    warnings.Add(WarningFactory.GetUnknownPropertyWarning(property));
 142                    return warnings;
 43
 44            }
 45        }
 46
 047        public static IParser<ReferenceDescriptor> GetParser(List<Warning> warnings, ReferenceDescriptor? descriptor = n
 48
 49        public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings)
 50        {
 51
 152            switch (property.Name)
 53            {
 54                case "resource":
 155                    return new ResourcePropertyParser(warnings, this);
 56                case "schemaReference":
 157                    return new SchemaReferencePropertyParser(warnings, this);
 58                case "columnReference":
 159                    return new ColumnReferencePropertyParser(warnings, this);
 60                default:
 161                    return null;
 62            }
 63        }
 64
 65        public List<Warning> CheckRequiredPropertiesPresent()
 66        {
 167            if (columnReference is null) ErrorFactory.ThrowRequiredPropertyMissingError("columnReference", nameof(Refere
 168            if (resource is null && schemaReference is null) ErrorFactory.ThrowRequiredPropertyMissingError("Missing bot
 169            return new List<Warning>();
 70        }
 71    }
 72}