diff --git a/src/json-ld.net/Core/JsonLdApi.cs b/src/json-ld.net/Core/JsonLdApi.cs index 186d913..6672070 100644 --- a/src/json-ld.net/Core/JsonLdApi.cs +++ b/src/json-ld.net/Core/JsonLdApi.cs @@ -430,8 +430,7 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e /// /// JsonLdError /// - public virtual JToken Expand(Context activeCtx, string activeProperty, JToken element - ) + public virtual JToken Expand(Context activeCtx, string activeProperty, JToken element) { // 1) if (element.IsNull()) @@ -1405,7 +1404,7 @@ public virtual JArray Frame(JToken input, JArray frame) { state.omitDefault = this.opts.GetOmitDefault().Value; } - // use tree map so keys are sotred by default + // use tree map so keys are sorted by default // XXX BUG BUG BUG XXX (sblom) Figure out where this needs to be sorted and use extension methods to return sorted enumerators or something! JObject nodes = new JObject(); GenerateNodeMap(input, nodes); @@ -2116,7 +2115,12 @@ public virtual JArray FromRDF(RDFDataset dataset) JArray result = new JArray(); // 6) JArray ids = new JArray(defaultGraph.GetKeys()); - ids.SortInPlace(); + + if (opts.GetSortGraphsFromRdf()) + { + ids.SortInPlace(); + } + foreach (string subject_1 in ids) { JsonLdApi.NodeMapNode node = (NodeMapNode)defaultGraph[subject_1]; @@ -2127,7 +2131,12 @@ public virtual JArray FromRDF(RDFDataset dataset) node["@graph"] = new JArray(); // 6.1.2) JArray keys = new JArray(graphMap[subject_1].GetKeys()); - keys.SortInPlace(); + + if (opts.GetSortGraphNodesFromRdf()) + { + keys.SortInPlace(); + } + foreach (string s in keys) { JsonLdApi.NodeMapNode n = (NodeMapNode)graphMap[subject_1][s]; diff --git a/src/json-ld.net/Core/JsonLdOptions.cs b/src/json-ld.net/Core/JsonLdOptions.cs index 2478481..ebd2cc2 100644 --- a/src/json-ld.net/Core/JsonLdOptions.cs +++ b/src/json-ld.net/Core/JsonLdOptions.cs @@ -1,4 +1,3 @@ -using JsonLD.Core; using Newtonsoft.Json.Linq; namespace JsonLD.Core @@ -43,6 +42,9 @@ public virtual JsonLD.Core.JsonLdOptions Clone() private bool produceGeneralizedRdf = false; + private bool sortGraphsFromRdf = true; + + private bool sortGraphNodesFromRdf = true; // base options // frame options // rdf conversion options @@ -147,6 +149,25 @@ public virtual void SetProduceGeneralizedRdf(bool produceGeneralizedRdf) this.produceGeneralizedRdf = produceGeneralizedRdf; } + public virtual bool GetSortGraphsFromRdf() + { + return sortGraphsFromRdf; + } + + public virtual void SetSortGraphsFromRdf(bool sortGraphs) + { + this.sortGraphsFromRdf = sortGraphs; + } + + public virtual bool GetSortGraphNodesFromRdf() + { + return sortGraphNodesFromRdf; + } + + public virtual void SetSortGraphNodesFromRdf(bool sortGraphNodes) + { + this.sortGraphNodesFromRdf = sortGraphNodes; + } public string format = null; public bool useNamespaces = false; diff --git a/src/json-ld.net/Core/JsonLdProcessor.cs b/src/json-ld.net/Core/JsonLdProcessor.cs index f383f2c..b77acbb 100644 --- a/src/json-ld.net/Core/JsonLdProcessor.cs +++ b/src/json-ld.net/Core/JsonLdProcessor.cs @@ -13,8 +13,7 @@ namespace JsonLD.Core public class JsonLdProcessor { /// - public static JObject Compact(JToken input, JToken context, JsonLdOptions - opts) + public static JObject Compact(JToken input, JToken context, JsonLdOptions opts) { // 1) // TODO: look into java futures/promises diff --git a/src/json-ld.net/Core/NormalizeUtils.cs b/src/json-ld.net/Core/NormalizeUtils.cs index 91aa552..bf746ed 100644 --- a/src/json-ld.net/Core/NormalizeUtils.cs +++ b/src/json-ld.net/Core/NormalizeUtils.cs @@ -108,6 +108,7 @@ public virtual object HashBlankNodes(IEnumerable unnamed_) normalized.Add(RDFDatasetUtils.ToNQuad(quad, quad.ContainsKey("name" ) && !(quad["name"] == null) ? (string)((IDictionary)((IDictionary)quad)["name"])["value"] : null)); } + // sort normalized output normalized.SortInPlace(); // handle output format diff --git a/src/json-ld.net/json-ld.net.csproj b/src/json-ld.net/json-ld.net.csproj index 1d4f881..3bd4f7c 100644 --- a/src/json-ld.net/json-ld.net.csproj +++ b/src/json-ld.net/json-ld.net.csproj @@ -3,7 +3,7 @@ JSON-LD processor for .NET Implements the W3C JSON-LD 1.0 standard. - 1.0.6 + 1.0.7 NuGet;linked-data-dotnet netstandard1.3;netstandard2.0;netcoreapp2.1 json-ld.net diff --git a/test/json-ld.net.tests/ConformanceTests.cs b/test/json-ld.net.tests/ConformanceTests.cs index 02eaa82..09bcaf8 100644 --- a/test/json-ld.net.tests/ConformanceTests.cs +++ b/test/json-ld.net.tests/ConformanceTests.cs @@ -1,13 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Newtonsoft.Json.Linq; using Xunit; -using Xunit.Extensions; using System.IO; -using Newtonsoft.Json; using JsonLD.Core; using JsonLD.Util; @@ -16,7 +13,7 @@ namespace JsonLD.Test public class ConformanceTests { [Theory, ClassData(typeof(ConformanceCases))] - public void ConformanceTestPasses(string id, string testname, ConformanceCase conformanceCase) + public void ConformanceTestPasses(string id, ConformanceCase conformanceCase) { JToken result = conformanceCase.run(); if (conformanceCase.error != null) @@ -77,20 +74,21 @@ public ConformanceCases() public IEnumerator GetEnumerator() { + var jsonFetcher = new JsonFetcher(); + var rootDirectory = "W3C"; + foreach (string manifest in manifests) { - JToken manifestJson; - - manifestJson = GetJson(manifest); + JToken manifestJson = jsonFetcher.GetJson(manifest, rootDirectory); foreach (JObject testcase in manifestJson["sequence"]) { Func run; ConformanceCase newCase = new ConformanceCase(); - newCase.input = GetJson(testcase["input"]); - newCase.context = GetJson(testcase["context"]); - newCase.frame = GetJson(testcase["frame"]); + newCase.input = jsonFetcher.GetJson(testcase["input"], rootDirectory); + newCase.context = jsonFetcher.GetJson(testcase["context"], rootDirectory); + newCase.frame = jsonFetcher.GetJson(testcase["frame"], rootDirectory); var options = new JsonLdOptions("http://json-ld.org/test-suite/tests/" + (string)testcase["input"]); @@ -109,11 +107,11 @@ public IEnumerator GetEnumerator() else if (testType.Any((s) => (string)s == "jld:FromRDFTest")) { newCase.input = File.ReadAllText(Path.Combine("W3C", (string)testcase["input"])); - newCase.output = GetJson(testcase["expect"]); + newCase.output = jsonFetcher.GetJson(testcase["expect"], rootDirectory); } else { - newCase.output = GetJson(testcase["expect"]); + newCase.output = jsonFetcher.GetJson(testcase["expect"], rootDirectory); } } else @@ -138,7 +136,7 @@ public IEnumerator GetEnumerator() } if (optionDescription.TryGetValue("expandContext", out value)) { - newCase.context = GetJson(testcase["option"]["expandContext"]); + newCase.context = jsonFetcher.GetJson(testcase["option"]["expandContext"], rootDirectory); options.SetExpandContext((JObject)newCase.context); } if (optionDescription.TryGetValue("produceGeneralizedRdf", out value)) @@ -227,32 +225,11 @@ public IEnumerator GetEnumerator() newCase.run = run; - yield return new object[] { manifest + (string)testcase["@id"], (string)testcase["name"], newCase }; + yield return new object[] { manifest + (string)testcase["@id"], newCase }; } } } - private JToken GetJson(JToken j) - { - try - { - if (j == null || j.Type == JTokenType.Null) return null; - using (Stream manifestStream = File.OpenRead(Path.Combine("W3C", (string)j))) - using (TextReader reader = new StreamReader(manifestStream)) - using (JsonReader jreader = new Newtonsoft.Json.JsonTextReader(reader) - { - DateParseHandling = DateParseHandling.None - }) - { - return JToken.ReadFrom(jreader); - } - } - catch (Exception e) - { // TODO: this should not be here, figure out why this is needed or catch specific exception. - return null; - } - } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw new Exception("auggh"); diff --git a/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-in.json b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-in.json new file mode 100644 index 0000000..9b9e54e --- /dev/null +++ b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-in.json @@ -0,0 +1,58 @@ +{ + "quads": [ + { + "graph": "http://example.org/node/3", + "subject": "http://example.org/object/3", + "predicate": "http://example.org/value", + "value": "n3-o3-value" + }, + { + "graph": "http://example.org/node/3", + "subject": "http://example.org/object/1", + "predicate": "http://example.org/value", + "value": "n3-o1-value" + }, + { + "graph": "http://example.org/node/3", + "subject": "http://example.org/object/2", + "predicate": "http://example.org/value", + "value": "n3-o2-value" + }, + { + "graph": "http://example.org/node/1", + "subject": "http://example.org/object/3", + "predicate": "http://example.org/value", + "value": "n1-o3-value" + }, + { + "graph": "http://example.org/node/1", + "subject": "http://example.org/object/1", + "predicate": "http://example.org/value", + "value": "n1-o1-value" + }, + { + "graph": "http://example.org/node/1", + "subject": "http://example.org/object/2", + "predicate": "http://example.org/value", + "value": "n1-o2-value" + }, + { + "graph": "http://example.org/node/2", + "subject": "http://example.org/object/3", + "predicate": "http://example.org/value", + "value": "n2-o3-value" + }, + { + "graph": "http://example.org/node/2", + "subject": "http://example.org/object/1", + "predicate": "http://example.org/value", + "value": "n2-o1-value" + }, + { + "graph": "http://example.org/node/2", + "subject": "http://example.org/object/2", + "predicate": "http://example.org/value", + "value": "n2-o2-value" + } + ] +} \ No newline at end of file diff --git a/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-manifest.jsonld b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-manifest.jsonld new file mode 100644 index 0000000..2718fa2 --- /dev/null +++ b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-manifest.jsonld @@ -0,0 +1,40 @@ +{ + "@type": "mf:Manifest", + "name": "From RDF", + "description": "JSON-LD sorting graphs and nodes when running FromRDF", + "input": "fromRdf-in.json", + "sequence": [ + { + "@id": "#t0001", + "sort-type": "jld:GraphsAndNodes", + "test-type": "jld:FromRDF", + "name": "sort graphs and nodes", + "purpose": "graphs and nodes sorted when running FromRDF", + "expect": "fromRdf-out-sort-graphs-and-nodes.jsonld" + }, + { + "@id": "#t0002", + "sort-type": "jld:Graphs", + "test-type": "jld:FromRDF", + "name": "sort graphs only", + "purpose": "graphs sorted when running FromRDF", + "expect": "fromRdf-out-sort-graphs.jsonld" + }, + { + "@id": "#t0003", + "sort-type": "jld:Nodes", + "test-type": "jld:FromRDF", + "name": "sort graph nodes only", + "purpose": "graph nodes sorted when running FromRDF", + "expect": "fromRdf-out-sort-graph-nodes.jsonld" + }, + { + "@id": "#t0004", + "sort-type": "jld:None", + "test-type": "jld:FromRDF", + "name": "sort nothing", + "purpose": "sort nothing running FromRDF", + "expect": "fromRdf-out-no-sorting.jsonld" + } + ] +} diff --git a/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-no-sorting.jsonld b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-no-sorting.jsonld new file mode 100644 index 0000000..b5920e3 --- /dev/null +++ b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-no-sorting.jsonld @@ -0,0 +1,89 @@ +[ + { + "@id": "http://example.org/node/3", + "@graph": [ + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n3-o3-value" + } + ] + }, + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n3-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n3-o2-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/1", + "@graph": [ + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n1-o3-value" + } + ] + }, + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n1-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n1-o2-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/2", + "@graph": [ + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n2-o3-value" + } + ] + }, + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n2-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n2-o2-value" + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graph-nodes.jsonld b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graph-nodes.jsonld new file mode 100644 index 0000000..0fcc4c8 --- /dev/null +++ b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graph-nodes.jsonld @@ -0,0 +1,89 @@ +[ + { + "@id": "http://example.org/node/3", + "@graph": [ + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n3-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n3-o2-value" + } + ] + }, + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n3-o3-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/1", + "@graph": [ + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n1-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n1-o2-value" + } + ] + }, + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n1-o3-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/2", + "@graph": [ + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n2-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n2-o2-value" + } + ] + }, + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n2-o3-value" + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graphs-and-nodes.jsonld b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graphs-and-nodes.jsonld new file mode 100644 index 0000000..b9d5253 --- /dev/null +++ b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graphs-and-nodes.jsonld @@ -0,0 +1,89 @@ +[ + { + "@id": "http://example.org/node/1", + "@graph": [ + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n1-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n1-o2-value" + } + ] + }, + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n1-o3-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/2", + "@graph": [ + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n2-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n2-o2-value" + } + ] + }, + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n2-o3-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/3", + "@graph": [ + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n3-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n3-o2-value" + } + ] + }, + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n3-o3-value" + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graphs.jsonld b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graphs.jsonld new file mode 100644 index 0000000..ce0a7cf --- /dev/null +++ b/test/json-ld.net.tests/ExtendedFunctionality/Sorting/fromRdf-out-sort-graphs.jsonld @@ -0,0 +1,89 @@ +[ + { + "@id": "http://example.org/node/1", + "@graph": [ + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n1-o3-value" + } + ] + }, + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n1-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n1-o2-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/2", + "@graph": [ + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n2-o3-value" + } + ] + }, + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n2-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n2-o2-value" + } + ] + } + ] + }, + { + "@id": "http://example.org/node/3", + "@graph": [ + { + "@id": "http://example.org/object/3", + "http://example.org/value": [ + { + "@id": "n3-o3-value" + } + ] + }, + { + "@id": "http://example.org/object/1", + "http://example.org/value": [ + { + "@id": "n3-o1-value" + } + ] + }, + { + "@id": "http://example.org/object/2", + "http://example.org/value": [ + { + "@id": "n3-o2-value" + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/json-ld.net.tests/ExtendedFunctionalityTests.cs b/test/json-ld.net.tests/ExtendedFunctionalityTests.cs new file mode 100644 index 0000000..f0c4f68 --- /dev/null +++ b/test/json-ld.net.tests/ExtendedFunctionalityTests.cs @@ -0,0 +1,142 @@ +using JsonLD.Core; +using JsonLD.Util; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using Xunit; + +namespace JsonLD.Test +{ + public class ExtendedFunctionalityTests + { + private const string ManifestRoot = "ExtendedFunctionality"; + + [Theory, MemberData(nameof(ExtendedFunctionalityCases))] + public void ExtendedFunctionalityTestPasses(string id, ExtendedFunctionalityTestCase testCase) + { + JToken result = testCase.run(); + if (testCase.error != null) + { + Assert.True(((string)result["error"]).StartsWith((string)testCase.error), "Resulting error doesn't match expectations."); + } + else + { + if (!JsonLdUtils.DeepCompare(result, testCase.output, true)) + { +#if DEBUG + Console.WriteLine(id); + Console.WriteLine("Actual:"); + Console.Write(JSONUtils.ToPrettyString(result)); + Console.WriteLine("--------------------------"); + Console.WriteLine("Expected:"); + Console.Write(JSONUtils.ToPrettyString(testCase.output)); + Console.WriteLine("--------------------------"); +#endif + + Assert.True(false, "Returned JSON doesn't match expectations."); + } + } + } + + public class ExtendedFunctionalityTestCase + { + public JToken input { get; set; } + public JToken output { get; set; } + public JToken context { get; set; } + public JToken frame { get; set; } + public JToken error { get; set; } + public Func run { get; set; } + } + + public static IEnumerable ExtendedFunctionalityCases() + { + foreach (var testCase in SortingTestCases()) + { + yield return testCase; + } + } + + private static string[] SortingManifests = + { + "fromRdf-manifest.jsonld" + }; + + private static IEnumerable SortingTestCases() + { + var jsonFetcher = new JsonFetcher(); + var rootDirectory = Path.Combine(ManifestRoot, "Sorting"); + + foreach (string manifest in SortingManifests) + { + JToken manifestJson = jsonFetcher.GetJson(manifest, rootDirectory); + + foreach (JObject testcase in manifestJson["sequence"]) + { + Func run = null; + ExtendedFunctionalityTestCase newCase = new ExtendedFunctionalityTestCase(); + + newCase.input = jsonFetcher.GetJson(manifestJson["input"], rootDirectory); + newCase.output = jsonFetcher.GetJson(testcase["expect"], rootDirectory); + + var options = new JsonLdOptions(); + + var sortType = (string)testcase["sort-type"]; + + if (sortType == "jld:GraphsAndNodes") + { + options.SetSortGraphsFromRdf(true); + options.SetSortGraphNodesFromRdf(true); + } + else if (sortType == "jld:Graphs") + { + options.SetSortGraphsFromRdf(true); + options.SetSortGraphNodesFromRdf(false); + } + else if (sortType == "jld:Nodes") + { + options.SetSortGraphsFromRdf(false); + options.SetSortGraphNodesFromRdf(true); + } + else if (sortType == "jld:None") + { + options.SetSortGraphsFromRdf(false); + options.SetSortGraphNodesFromRdf(false); + } + + JsonLdApi jsonLdApi = new JsonLdApi(options); + + var testType = (string)testcase["test-type"]; + + if (testType == "jld:FromRDF") + { + JToken quads = newCase.input["quads"]; + RDFDataset rdf = new RDFDataset(); + + foreach (JToken quad in quads) + { + string subject = (string)quad["subject"]; + string predicate = (string)quad["predicate"]; + string value = (string)quad["value"]; + string graph = (string)quad["graph"]; + + rdf.AddQuad(subject, predicate, value, graph); + } + + options.format = "application/nquads"; + + run = () => jsonLdApi.FromRDF(rdf); + } + else + { + run = () => { throw new Exception("Couldn't find a test type, apparently."); }; + } + + newCase.run = run; + + yield return new object[] { manifest + (string)testcase["@id"], newCase }; + } + } + } + } +} diff --git a/test/json-ld.net.tests/JsonFetcher.cs b/test/json-ld.net.tests/JsonFetcher.cs new file mode 100644 index 0000000..35ec309 --- /dev/null +++ b/test/json-ld.net.tests/JsonFetcher.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.IO; + +namespace JsonLD.Test +{ + public class JsonFetcher + { + public JToken GetJson(JToken j, string rootDirectory) + { + try + { + if (j == null || j.Type == JTokenType.Null) return null; + using (Stream manifestStream = File.OpenRead(Path.Combine(rootDirectory, (string)j))) + using (TextReader reader = new StreamReader(manifestStream)) + using (JsonReader jreader = new JsonTextReader(reader) + { + DateParseHandling = DateParseHandling.None + }) + { + return JToken.ReadFrom(jreader); + } + } + catch (Exception e) + { // TODO: this should not be here, figure out why this is needed or catch specific exception. + return null; + } + } + } +} \ No newline at end of file diff --git a/test/json-ld.net.tests/json-ld.net.tests.csproj b/test/json-ld.net.tests/json-ld.net.tests.csproj index d59bfc0..22eb64a 100644 --- a/test/json-ld.net.tests/json-ld.net.tests.csproj +++ b/test/json-ld.net.tests/json-ld.net.tests.csproj @@ -27,4 +27,25 @@ + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + \ No newline at end of file