< Summary

Information
Class: ValidateLib.Metadata.Descriptors.Context
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Descriptors\Context.cs
Line coverage
85%
Covered lines: 23
Uncovered lines: 4
Coverable lines: 27
Total lines: 70
Line coverage: 85.1%
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
Context()30
CreateContextFromArray(...)330
Normalize(...)02
GetContextFromJToken(...)378

File(s)

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

#LineLine coverage
 1using Newtonsoft.Json.Linq;
 2using ValidateLib.ErrorsAndWarnings.Errors;
 3using ValidateLib.ErrorsAndWarnings.Warnings;
 4using ValidateLib.IRINormalization;
 5using ValidateLib.Metadata.Descriptors.Interfaces;
 6using ValidateLib.Metadata.Properties.AtomicProperties;
 7using ValidateLib.UtilityClasses;
 8
 9namespace ValidateLib.Metadata.Descriptors
 10{
 11    public class Context : INormalize
 12    {
 13        public string? contextURL;
 114        public AtomicPropertyString? _base { get; set; }
 115        public AtomicPropertyString language { get; set; } = new AtomicPropertyString("und");
 16        public static Context CreateContextFromArray(JArray array)
 17        {
 118            Context context = new Context();
 119            context.contextURL = array[0].ToString();
 120            foreach (JProperty property in array[1])
 21            {
 122                if (property.Name == "@base") context._base = new AtomicPropertyString(property.Value.ToString());
 123                else if (property.Name == "@language") context.language = new AtomicPropertyString(property.Value.ToStri
 124                else ErrorFactory.ThrowInvalidPropertyOnContextDescriptorError(property.ToString());
 25
 26            }
 127            return context;
 28        }
 29
 30        public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null)
 31        {
 032            throw new NotImplementedException();
 33        }
 34
 35        public static Context GetContextFromJToken(JToken jToken, List<Warning> warnings, string objectFileLocation)
 36        {
 137            Context context = new Context();
 138            if (jToken["@context"] != null)
 39            {
 140                JToken contextValue = jToken["@context"]!;
 141                if (contextValue!.Type == JTokenType.String)
 42                {
 143                    context.contextURL = contextValue.ToString();
 44                }
 145                else if (contextValue.Type == JTokenType.Array) context = CreateContextFromArray((JArray)contextValue);
 046                else ErrorFactory.ThrowInvalidContextValueError(contextValue.ToString(), contextValue.Type.ToString());
 147                if (context._base == null)
 48                {
 149                    string fileName = Path.GetFileName(objectFileLocation)!;
 150                    context._base = new AtomicPropertyString(objectFileLocation!.Replace(fileName, ""));
 51                }
 52                else
 53                {
 154                    context._base._value = IRINormalizator.TurnUrlIntoAbsoluteWithReferencedUrl(objectFileLocation, cont
 55                }
 156                if (context?.language?._value is not null && !LanguageUtilityClass.IsCorrectLanguageCode(context.languag
 57                {
 158                    warnings.Add(WarningFactory.GetInvalidContextLanuageWarning(context.language._value));
 159                    context.language = new AtomicPropertyString("und");
 60                }
 161                return context!;
 62            }
 63            else
 64            {
 065                ErrorFactory.ThrowMissingContextError(jToken);
 066                return null!;
 67            }
 68        }
 69    }
 70}