| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using System.Text; |
| | 6 | | using System.Threading.Tasks; |
| | 7 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 8 | | using ValidateLib.Metadata.Descriptors; |
| | 9 | | using ValidateLib.Metadata.Properties; |
| | 10 | |
|
| | 11 | | namespace NormalizationTests |
| | 12 | | { |
| | 13 | | public class LinkPropertiesTests |
| | 14 | | { |
| | 15 | | public readonly string testFilesDirectory; |
| 1 | 16 | | public LinkPropertiesTests() |
| 1 | 17 | | { |
| 1 | 18 | | testFilesDirectory = Path.Combine(GetProjectDirectory(),"TestFiles", "LinkPropertiesTests"); |
| 1 | 19 | | } |
| | 20 | | static string GetProjectDirectory() |
| 1 | 21 | | { |
| 1 | 22 | | string? currentDirectory = Directory.GetCurrentDirectory(); |
| | 23 | |
|
| 1 | 24 | | while (!string.IsNullOrEmpty(currentDirectory)) |
| 1 | 25 | | { |
| 1 | 26 | | string[] projectFiles = Directory.GetFiles(currentDirectory, "*.csproj"); |
| | 27 | |
|
| 1 | 28 | | if (projectFiles.Length > 0) |
| 1 | 29 | | return currentDirectory; |
| 1 | 30 | | currentDirectory = Directory.GetParent(currentDirectory)?.FullName; |
| 1 | 31 | | } |
| | 32 | |
|
| 0 | 33 | | throw new Exception("Could not find project directory."); |
| 1 | 34 | | } |
| | 35 | | [Fact] |
| | 36 | | public void NaturalLanguagePropertyStringToObjectEnLanguageTest() |
| 1 | 37 | | { |
| 1 | 38 | | string testFilePath = Path.Combine(testFilesDirectory, "testFile1.json"); |
| 1 | 39 | | string jsonString = File.ReadAllText(testFilePath); |
| 1 | 40 | | JObject jsonObject = JObject.Parse(jsonString); |
| | 41 | |
|
| 1 | 42 | | List<Warning> warnings = new List<Warning>(); |
| 1 | 43 | | Context context = Context.GetContextFromJToken(jsonObject,warnings, testFilePath); |
| | 44 | |
|
| | 45 | |
|
| 1 | 46 | | var property = jsonObject.Property("url"); |
| 1 | 47 | | LinkProperty.Normalize(property?.Value!, context, property); |
| | 48 | |
|
| 1 | 49 | | var titlesObject = property.Value; |
| | 50 | |
|
| 1 | 51 | | Assert.Equal("http://example.com/table.csv", property.Value); |
| | 52 | |
|
| | 53 | |
|
| 1 | 54 | | } |
| | 55 | |
|
| | 56 | | } |
| | 57 | | } |