< Summary

Information
Class: NormalizationTests.CommonPropertiesTests
Assembly: normalizationtests.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\Tests\NormalizationTests\CommonPropertiesTests.cs
Line coverage
98%
Covered lines: 64
Uncovered lines: 1
Coverable lines: 65
Total lines: 109
Line coverage: 98.4%
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\Tests\NormalizationTests\CommonPropertiesTests.cs

#LineLine coverage
 1using Newtonsoft.Json.Linq;
 2using ValidateLib.ErrorsAndWarnings.Warnings;
 3using ValidateLib.Metadata.Descriptors;
 4using ValidateLib.Metadata.Properties;
 5
 6namespace NormalizationTests
 7{
 8    public class CommonPropertiesTests
 9    {
 10        public readonly string testFilesDirectory;
 111        public CommonPropertiesTests()
 112        {
 113            testFilesDirectory = Path.Combine(GetProjectDirectory(), "TestFiles","CommonPropertiesFiles");
 114        }
 15        static string GetProjectDirectory()
 116        {
 117            string? currentDirectory = Directory.GetCurrentDirectory();
 18
 119            while (!string.IsNullOrEmpty(currentDirectory))
 120            {
 121                string[] projectFiles = Directory.GetFiles(currentDirectory, "*.csproj");
 22
 123                if (projectFiles.Length > 0)
 124                    return currentDirectory;
 125                currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
 126            }
 27
 028            throw new Exception("Could not find project directory.");
 29
 30
 131        }
 32        [Fact]
 33        public void CommonPropertyStringValueToObjectWithValuePropertyTest()
 134        {
 135            string testFilePath = Path.Combine(testFilesDirectory, "testFile1.json");
 136            string jsonString = File.ReadAllText(testFilePath);
 137            JToken jToken = JObject.Parse(jsonString);
 138            var warnings = new List<Warning>();
 139            Context context = Context.GetContextFromJToken(jToken, warnings, testFilePath);
 140            var property = ((JObject)jToken).Property("dc:title");
 141            CommonProperty.Normalize(property!.Value, context,property);
 42
 143            Assert.Equal(typeof(JObject), property.Value.GetType());
 144            Assert.Equal("The title of this Table",property?.Value?["@value"]?.ToString());
 145            Assert.Equal("en",property?.Value?["@language"]?.ToString());
 46
 147        }
 48
 49        [Fact]
 50        public void CommonPropertyArrayPropertyTest()
 151        {
 152            string testFilePath = Path.Combine(testFilesDirectory, "testFile3.json");
 153            string jsonString = File.ReadAllText(testFilePath);
 154            JToken jToken = JObject.Parse(jsonString);
 155            var warnings = new List<Warning>();
 156            Context context = Context.GetContextFromJToken(jToken, warnings,testFilePath);
 157            var property = ((JObject)jToken).Property("dc:title");
 158            CommonProperty.Normalize(property!.Value, context, property);
 59
 160            Assert.Equal(typeof(JArray), property.Value.GetType());
 61
 162            var object1 = property.Value[0];
 163            var object2 = property.Value[1];
 164            Assert.Equal("The title of this Table", object1?["@value"]?.ToString());
 165            Assert.Equal("en", object1?["@language"]?.ToString());
 66
 167            Assert.Equal("Der Titel dieser Tabelle", object2?["@value"]?.ToString());
 168            Assert.Equal("de", object2?["@language"]?.ToString());
 69
 170        }
 71
 72        [Fact]
 73        public void CommonPropertyNormalizeAgainstBaseIdPropertyTest()
 174        {
 175            string testFilePath = Path.Combine(testFilesDirectory, "testFile4.json");
 176            string jsonString = File.ReadAllText(testFilePath);
 177            JToken jToken = JObject.Parse(jsonString);
 178            var warnings = new List<Warning>();
 179            Context context = Context.GetContextFromJToken(jToken, warnings, testFilePath);
 180            var property = ((JObject)jToken).Property("schema:url");
 181            CommonProperty.Normalize(property?.Value!, context, property);
 82
 183            Assert.Equal(typeof(JObject), property!.Value.GetType());
 84
 185            Assert.Equal("http://example.com/table.csv", property?.Value?["@id"]!.ToString());
 86
 87
 188        }
 89
 90        [Fact]
 91        public void CommonPropertyNormalizeEmbeddedObjectInArrayTest()
 192        {
 193            string testFilePath = Path.Combine(testFilesDirectory, "testFile5.json");
 194            string jsonString = File.ReadAllText(testFilePath);
 195            JToken jToken = JObject.Parse(jsonString); var warnings = new List<Warning>();
 196            Context context = Context.GetContextFromJToken(jToken, warnings, testFilePath);
 197            var property = ((JObject)jToken).Property("dc:publisher");
 198            CommonProperty.Normalize(property?.Value!, context, property);
 99
 1100            var object1 = property!.Value[0];
 101
 1102            Assert.Equal(typeof(JArray), property.Value.GetType());
 103
 1104            Assert.Equal("Example Municipality", object1?["schema:name"]!["@value"]!.ToString());
 105
 106
 1107        }
 108    }
 109}