public override void ExpandTests(string testId, JsonLdTestType testType, string inputPath, string contextPath,
                                  string expectedOutputPath, JsonLdErrorCode expectErrorCode, string baseIri,
                                  string processorMode, string expandContextPath, bool compactArrays, string rdfDirection)
 {
     base.ExpandTests(testId, testType, inputPath, contextPath, expectedOutputPath, expectErrorCode,
                      baseIri, processorMode, expandContextPath, compactArrays, rdfDirection);
 }
        public virtual void FlattenTests(string testId, JsonLdTestType testType, string inputPath, string contextPath,
                                         string expectedOutputPath, JsonLdErrorCode expectedErrorCode, string baseIri,
                                         string processorMode, string expandContextPath, bool compactArrays, string rdfDirection)
        {
            var processorOptions = MakeProcessorOptions(inputPath, baseIri, processorMode, expandContextPath,
                                                        compactArrays, rdfDirection);
            var inputJson      = File.ReadAllText(inputPath);
            var contextJson    = contextPath == null ? null : File.ReadAllText(contextPath);
            var inputElement   = JToken.Parse(inputJson);
            var contextElement = contextJson == null ? null : JToken.Parse(contextJson);

            switch (testType)
            {
            case JsonLdTestType.PositiveEvaluationTest:
                var expectedOutputJson    = File.ReadAllText(expectedOutputPath);
                var expectedOutputElement = JToken.Parse(expectedOutputJson);

                var actualOutputElement = JsonLdProcessor.Flatten(inputElement, contextElement, processorOptions);
                Assert.True(DeepEquals(actualOutputElement, expectedOutputElement),
                            $"Error processing flatten test {Path.GetFileName(inputPath)}.\nActual output does not match expected output.\nExpected:\n{expectedOutputElement}\n\nActual:\n{actualOutputElement}");
                break;

            case JsonLdTestType.NegativeEvaluationTest:
                var exception = Assert.Throws <JsonLdProcessorException>(() =>
                                                                         JsonLdProcessor.Flatten(inputElement, contextElement, processorOptions));
                Assert.Equal(expectedErrorCode, exception.ErrorCode);
                break;

            default:
                Assert.True(false, $"Test type {testType} has not been implemented for Flatten tests");
                break;
            }
        }
 public override void JsonLdFramingTests(string testId, JsonLdTestType testType, string inputPath, string framePath,
                                         string expectedOutputPath, JsonLdErrorCode expectErrorCode, string processingMode,
                                         bool pruneBlankNodeIdentifiers, bool?omitGraph, bool ordered)
 {
     base.JsonLdFramingTests(testId, testType, inputPath, framePath, expectedOutputPath, expectErrorCode, processingMode,
                             pruneBlankNodeIdentifiers, omitGraph, ordered);
 }
 public override void JsonLdParserTests(string testId, JsonLdTestType testType, string inputPath, string contextPath,
                                        string expectedOutputPath, JsonLdErrorCode expectedErrorCode, string baseIri, string processorMode,
                                        string expandContextPath, bool compactArrays, string rdfDirection)
 {
     if (_skippedParserTests.ContainsKey(testId))
     {
         throw new SkipException(_skippedParserTests[testId]);
     }
     base.JsonLdParserTests(testId, testType, inputPath, contextPath, expectedOutputPath,
                            expectedErrorCode, baseIri, processorMode, expandContextPath, compactArrays, rdfDirection);
 }
        public virtual void JsonLdFramingTests(string testId, JsonLdTestType testType, string inputPath, string framePath,
                                               string expectedOutputPath, JsonLdErrorCode expectErrorCode, string processingMode,
                                               bool pruneBlankNodeIdentifiers, bool?omitGraph, bool ordered)
        {
            var inputJson            = File.ReadAllText(inputPath);
            var frameJson            = File.ReadAllText(framePath);
            var jsonLdProcessingMode = "json-ld-1.0".Equals(processingMode)
                ? JsonLdProcessingMode.JsonLd10
                : JsonLdProcessingMode.JsonLd11FrameExpansion;
            var options = new JsonLdProcessorOptions
            {
                ProcessingMode            = jsonLdProcessingMode,
                PruneBlankNodeIdentifiers = pruneBlankNodeIdentifiers,
                Ordered = ordered,
            };

            if (omitGraph.HasValue)
            {
                options.OmitGraph = omitGraph.Value;
            }
            var inputElement = JToken.Parse(inputJson);
            var frameElement = JToken.Parse(frameJson);

            switch (testType)
            {
            case JsonLdTestType.PositiveEvaluationTest:
                var expectedOutputJson    = File.ReadAllText(expectedOutputPath);
                var expectedOutputElement = JToken.Parse(expectedOutputJson);
                var actualOutput          = JsonLdProcessor.Frame(inputElement, frameElement, options);
                Assert.True(DeepEquals(expectedOutputElement, actualOutput),
                            $"Test failed for input {Path.GetFileName(inputPath)}\nExpected:\n{expectedOutputElement}\nActual:\n{actualOutput}");
                break;

            case JsonLdTestType.NegativeEvaluationTest:
                var exception = Assert.ThrowsAny <JsonLdProcessorException>(() =>
                                                                            JsonLdProcessor.Frame(inputElement, frameElement, options));
                Assert.Equal(expectErrorCode, exception.ErrorCode);
                break;

            case JsonLdTestType.PositiveSyntaxTest:
                JsonLdProcessor.Frame(inputElement, frameElement, options);
                break;

            case JsonLdTestType.NegativeSyntaxTest:
                Assert.ThrowsAny <JsonLdProcessorException>(() =>
                                                            JsonLdProcessor.Frame(inputElement, frameElement, options));
                break;
            }
        }
        public virtual void JsonLdParserTests(string testId, JsonLdTestType testType, string inputPath, string contextPath,
                                              string expectedOutputPath, JsonLdErrorCode expectedErrorCode, string baseIri,
                                              string processorMode, string expandContextPath, bool compactArrays, string rdfDirection)
        {
            var processorOptions = MakeProcessorOptions(inputPath, baseIri, processorMode, expandContextPath,
                                                        compactArrays, rdfDirection);
            var jsonldParser = new JsonLdParser(processorOptions);
            var actualStore  = new TripleStore();

            switch (testType)
            {
            case JsonLdTestType.PositiveEvaluationTest:
                var nqParser      = new NQuadsParser(NQuadsSyntax.Rdf11);
                var expectedStore = new TripleStore();
                nqParser.Load(expectedStore, expectedOutputPath);
                FixStringLiterals(expectedStore);
                jsonldParser.Load(actualStore, inputPath);
                Assert.True(expectedStore.Graphs.Count.Equals(actualStore.Graphs.Count) ||
                            (expectedStore.Graphs.Count == 0 && actualStore.Graphs.Count == 1 &&
                             actualStore.Graphs[null].IsEmpty),
                            $"Test failed for input {Path.GetFileName(inputPath)}.\r\nActual graph count {actualStore.Graphs.Count} does not match expected graph count {expectedStore.Graphs.Count}.");
                AssertStoresEqual(expectedStore, actualStore, Path.GetFileName(inputPath));
                break;

            case JsonLdTestType.NegativeEvaluationTest:
                var exception =
                    Assert.Throws <JsonLdProcessorException>(() => jsonldParser.Load(actualStore, inputPath));
                Assert.Equal(expectedErrorCode, exception.ErrorCode);
                break;

            case JsonLdTestType.PositiveSyntaxTest:
                // Positive syntax test should load input file without raising any exceptions
                jsonldParser.Load(actualStore, inputPath);
                break;

            default:
                Assert.True(false, $"Test type {testType} is not currently supported for the JSON-LD Parser tests");
                break;
            }
        }
        public virtual void ExpandTests(string testId, JsonLdTestType testType, string inputPath, string contextPath,
                                        string expectedOutputPath, JsonLdErrorCode expectErrorCode, string baseIri,
                                        string processorMode, string expandContextPath, bool compactArrays, string rdfDirection)
        {
            var processorOptions = MakeProcessorOptions(inputPath, baseIri, processorMode, expandContextPath,
                                                        compactArrays, rdfDirection);
            var inputJson    = File.ReadAllText(inputPath);
            var inputElement = JToken.Parse(inputJson);

            // Expand tests should not have a context parameter
            Assert.Null(contextPath);

            switch (testType)
            {
            case JsonLdTestType.PositiveEvaluationTest:
                var actualOutputElement   = JsonLdProcessor.Expand(inputElement, processorOptions);
                var expectedOutputJson    = File.ReadAllText(expectedOutputPath);
                var expectedOutputElement = JToken.Parse(expectedOutputJson);
                Assert.True(DeepEquals(actualOutputElement, expectedOutputElement),
                            $"Error processing expand test {Path.GetFileName(inputPath)}.\nActual output does not match expected output.\nExpected:\n{expectedOutputElement}\n\nActual:\n{actualOutputElement}");
                break;

            case JsonLdTestType.NegativeEvaluationTest:
                var exception =
                    Assert.Throws <JsonLdProcessorException>(
                        () => JsonLdProcessor.Expand(inputElement, processorOptions));
                Assert.Equal(expectErrorCode, exception.ErrorCode);
                break;

            case JsonLdTestType.PositiveSyntaxTest:
                // Expect test to run without throwing processing errors
                var _ = JsonLdProcessor.Expand(inputElement, processorOptions);
                break;

            case JsonLdTestType.NegativeSyntaxTest:
                Assert.ThrowsAny <JsonLdProcessorException>(() => JsonLdProcessor.Expand(inputElement, processorOptions));
                break;
            }
        }
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
        public virtual void JsonLdWriterTests(string testId, JsonLdTestType testType, string inputPath, string contextPath,
                                              string expectedOutputPath, JsonLdErrorCode expectErrorCode, bool useNativeTypes, bool useRdfType, bool ordered, string rdfDirection)
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
        {
            var nqParser = new NQuadsParser(NQuadsSyntax.Rdf11);
            var input    = new TripleStore();

            nqParser.Load(input, inputPath);
            FixStringLiterals(input);
            var writerOptions = new JsonLdWriterOptions
            {
                UseNativeTypes = useNativeTypes, UseRdfType = useRdfType, Ordered = ordered
            };

            if (rdfDirection != null)
            {
                switch (rdfDirection)
                {
                case "i18n-datatype":
                    writerOptions.RdfDirection = JsonLdRdfDirectionMode.I18NDatatype;
                    break;

                case "compound-literal":
                    writerOptions.RdfDirection = JsonLdRdfDirectionMode.CompoundLiteral;
                    break;

                default:
                    throw new Exception($"Test {testId} specifies an unrecognized value for the rdfDirection option: {rdfDirection}.");
                }
            }
            var jsonLdWriter = new JsonLdWriter(writerOptions);

            switch (testType)
            {
            case JsonLdTestType.PositiveEvaluationTest:
            {
                var actualOutput       = jsonLdWriter.SerializeStore(input);
                var expectedOutputJson = File.ReadAllText(expectedOutputPath);
                var expectedOutput     = JToken.Parse(expectedOutputJson);

                try
                {
                    Assert.True(DeepEquals(expectedOutput, actualOutput, true, true),
                                $"Test failed for input {Path.GetFileName(inputPath)}\nExpected:\n{expectedOutput}\nActual:\n{actualOutput}");
                }
                catch (DeepEqualityFailure ex)
                {
                    Assert.True(false,
                                $"Test failed for input {Path.GetFileName(inputPath)}\nExpected:\n{expectedOutput}\nActual:\n{actualOutput}\nMatch Failured: {ex}");
                }

                break;
            }

            case JsonLdTestType.NegativeEvaluationTest:
            {
                var exception = Assert.Throws <JsonLdProcessorException>(() => jsonLdWriter.SerializeStore(input));
                Assert.Equal(expectErrorCode, exception.ErrorCode);
                break;
            }

            case JsonLdTestType.PositiveSyntaxTest:
                var _ = jsonLdWriter.SerializeStore(input);
                break;

            case JsonLdTestType.NegativeSyntaxTest:
                Assert.ThrowsAny <JsonLdProcessorException>(() => jsonLdWriter.SerializeStore(input));
                break;
            }
        }
 public override void JsonLdWriterTests(string testId, JsonLdTestType testType, string inputPath, string contextPath,
                                        string expectedOutputPath, JsonLdErrorCode expectErrorCode, bool useNativeTypes, bool useRdfType, bool ordered, string rdfDirection)
 {
     base.JsonLdWriterTests(testId, testType, inputPath, contextPath, expectedOutputPath, expectErrorCode, useNativeTypes, useRdfType, ordered, rdfDirection);
 }