< Summary

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

#LineLine coverage
 1using Newtonsoft.Json.Linq;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5using System.Text;
 6using System.Threading.Tasks;
 7using ValidateLib.ErrorsAndWarnings.Warnings;
 8using ValidateLib.Metadata.Descriptors;
 9using ValidateLib.Metadata.Properties;
 10
 11namespace NormalizationTests
 12{
 13    public  class NaturalLanguagePropertiesTests
 14    {
 15        public readonly string testFilesDirectory;
 116        public NaturalLanguagePropertiesTests()
 117        {
 118            testFilesDirectory = Path.Combine(GetProjectDirectory(),  "TestFiles", "NaturalLanguagePropertiesTests");
 119        }
 20        static string GetProjectDirectory()
 121        {
 122            string? currentDirectory = Directory.GetCurrentDirectory();
 23
 124            while (!string.IsNullOrEmpty(currentDirectory))
 125            {
 126                string[] projectFiles = Directory.GetFiles(currentDirectory, "*.csproj");
 27
 128                if (projectFiles.Length > 0)
 129                    return currentDirectory;
 130                currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
 131            }
 32
 033            throw new Exception("Could not find project directory.");
 134        }
 35
 36
 37        [Fact]
 38        public void NaturalLanguagePropertyStringToObjectEnLanguageTest()
 139        {
 140            string testFilePath = Path.Combine(testFilesDirectory, "testFile1.json");
 141            string jsonString = File.ReadAllText(testFilePath);
 142            JObject jsonObject = JObject.Parse(jsonString);
 43
 144            var warnings = new List<Warning>();
 145            Context context = Context.GetContextFromJToken(jsonObject,warnings, testFilePath);
 46
 47
 148            var property = ((JObject)jsonObject!["tableSchema"]!["columns"]![0]!)!.Property("titles")!;
 149            NaturalLanguageProperty.Normalize(property?.Value!, context, property);
 50
 151            var titlesObject = property!.Value;
 52
 153            Assert.Equal(typeof(JObject), titlesObject.GetType());
 154            Assert.Equal("GID", titlesObject!["en"]![0]!.ToString());
 55
 56
 157        }
 58
 59        [Fact]
 60        public void NaturalLanguagePropertyStringToObjectUndLanguageTest()
 161        {
 162            string testFilePath = Path.Combine(testFilesDirectory, "testFile2.json");
 163            string jsonString = File.ReadAllText(testFilePath);
 164            JObject jsonObject = JObject.Parse(jsonString);
 65
 166            var warnings = new List<Warning>();
 167            Context context = Context.GetContextFromJToken(jsonObject, warnings, testFilePath);
 68
 69
 170            var property = ((JObject)jsonObject!["tableSchema"]!["columns"]![0]!)!.Property("titles");
 171            NaturalLanguageProperty.Normalize(property?.Value!, context, property);
 72
 173            var titlesObject = property!.Value;
 74
 175            Assert.Equal(typeof(JObject), titlesObject.GetType());
 176            Assert.Equal("GID", titlesObject!["und"]![0]!.ToString());
 77
 78
 179        }
 80
 81        [Fact]
 82        public void NaturalLanguagePropertyMultipleStringToObjectUndLanguageTest()
 183        {
 184            string testFilePath = Path.Combine(testFilesDirectory, "testFile3.json");
 185            string jsonString = File.ReadAllText(testFilePath);
 186            JObject jsonObject = JObject.Parse(jsonString);
 87
 188            var warnings = new List<Warning>();
 189            Context context = Context.GetContextFromJToken(jsonObject, warnings, testFilePath);
 90
 91
 192            var property = ((JObject)jsonObject!["tableSchema"]!["columns"]![0]!)!.Property("titles");
 193            NaturalLanguageProperty.Normalize(property?.Value!, context, property);
 94
 195            var titlesObject = property!.Value;
 96
 197            Assert.Equal(typeof(JObject), titlesObject.GetType());
 198            Assert.Equal("GID", titlesObject!["und"]![0]!.ToString());
 199            Assert.Equal("PID", titlesObject!["und"]![1]!.ToString());
 1100            Assert.Equal("XD", titlesObject!["und"]![2]!.ToString());
 101
 102
 1103        }
 104
 105        [Fact]
 106        public void NaturalLanguageArrayTitlesEnLanguageTest()
 1107        {
 1108            string testFilePath = Path.Combine(testFilesDirectory, "testFile4.json");
 1109            string jsonString = File.ReadAllText(testFilePath);
 1110            JObject jsonObject = JObject.Parse(jsonString);
 111
 1112            var warnings = new List<Warning>();
 1113            Context context = Context.GetContextFromJToken(jsonObject, warnings, testFilePath);
 114
 115
 1116            var property = ((JObject)jsonObject!["tableSchema"]!["columns"]![0]!)!.Property("titles");
 1117            NaturalLanguageProperty.Normalize(property?.Value!, context, property);
 118
 1119            var titlesObject = property!.Value;
 120
 1121            Assert.Equal(typeof(JObject), titlesObject.GetType());
 122
 123
 1124        }
 125    }
 126}