< Summary

Information
Class: ValidateLib.Metadata.Descriptors.TransformationDescriptor
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Descriptors\TransformationDescriptor.cs
Line coverage
72%
Covered lines: 27
Uncovered lines: 10
Coverable lines: 37
Total lines: 100
Line coverage: 72.9%
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\TransformationDescriptor.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.Properties.AtomicProperties;
 8using ValidateLib.Metadata.PropertyParsers;
 9using ValidateLib.Metadata.PropertyParsers.DescriptorNS;
 10using ValidateLib.Metadata.PropertyParsers.Transformation;
 11
 12namespace ValidateLib.Metadata.Descriptors
 13{
 14    public class TransformationDescriptor : CommonPropertiesDescriptor, INormalize, Interfaces.IParsable<TransformationD
 15    {
 016        public LinkProperty? url { get; set; }
 117        public LinkProperty? scriptFormat { get; set; }
 018        public LinkProperty? targetFormat { get; set; }
 119        public AtomicPropertyString? source { get; set; } = new AtomicPropertyString(null) { IsDefault = true };
 120        public NaturalLanguageProperty? titles { get; set; }
 121        new public static string getTypeForTypeProperty() => "Template";
 22
 23        public List<Warning> CheckRequiredPropertiesPresent()
 24        {
 025            List<Warning> warnings = new List<Warning>();
 026            if (url == null)
 27            {
 028                ErrorFactory.ThrowRequiredPropertyMissingError(nameof(url), nameof(TransformationDescriptor));
 29            }
 030            if (scriptFormat == null)
 31            {
 032                ErrorFactory.ThrowRequiredPropertyMissingError(nameof(scriptFormat), nameof(TransformationDescriptor));
 33            }
 034            if (targetFormat == null)
 35            {
 036                ErrorFactory.ThrowRequiredPropertyMissingError(nameof(scriptFormat), nameof(TransformationDescriptor));
 37
 38            }
 039            return warnings;
 40
 41        }
 42
 43        public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null)
 44        {
 45
 146            List<Warning> errors = new List<Warning>();
 147            if (token.Type != JTokenType.Object) return errors;
 148            foreach (JProperty jProperty in token)
 49            {
 150                var results = NormalizeProperty(jProperty, context);
 151                MergeTwoList(errors, results);
 52            }
 153            return errors;
 54        }
 55
 56        new static List<Warning> NormalizeProperty(JProperty property, Context context)
 57        {
 158            List<Warning> errors = new List<Warning>();
 159            if (CommonProperty.IsCommonProperty(property.Name)) CommonProperty.Normalize(property.Value, context, proper
 160            switch (property.Name)
 61            {
 62                case "url":
 63                case "scriptFormat":
 64                case "targetFormat":
 165                    return LinkProperty.Normalize(property.Value, context, property);
 66                case "source":
 167                    return errors;
 68                case "titles":
 169                    return NaturalLanguageProperty.Normalize(property.Value, context, property);
 70                default:
 171                    return ContextDescriptor.NormalizeProperty(property, context);
 72            }
 73        }
 74
 75        new public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings)
 76        {
 177            string propertyName = property.Name;
 178            if (CommonProperty.IsCommonProperty(propertyName)) ((CommonPropertiesDescriptor)this).GetPropertyParser(prop
 79            switch (propertyName)
 80            {
 81                case "url":
 182                    return new UrlPropertyParser(warnings, this);
 83                case "scriptFormat":
 184                    return new ScriptFormatPropertyParser(warnings, this);
 85                case "targetFormat":
 186                    return new TargetFormatPropertyParser(warnings, this);
 87                case "source":
 188                    return new SourcePropertyParser(warnings, this);
 89                case "titles":
 190                    return new TitlesPropertyParser(warnings, this);
 91                case "@type":
 192                    return new TypePropertyParser<TransformationDescriptor>(warnings, this);
 93                default:
 194                    return ((Descriptor)this).GetPropertyParser(property, warnings);
 95            }
 96        }
 97
 198        public static IParser<TransformationDescriptor> GetParser(List<Warning> warnings, TransformationDescriptor? desc
 99    }
 100}