コード例 #1
0
        public void Conformance()
        {
            var dataGraph = new Graph();

            dataGraph.LoadFromString(@"
@prefix : <urn:> .

:s :p :o .
");

            var shapesGraph = new Graph();

            shapesGraph.LoadFromString(@"
@prefix : <urn:> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

[
    sh:targetNode :s ;
    sh:class :C ;
] .
");

            var processor = new ShapesGraph(shapesGraph);
            var conforms  = processor.Conforms(dataGraph);

            Assert.False(conforms);
        }
コード例 #2
0
        public void Consume_validation_results()
        {
            var dataGraph = new Graph();

            dataGraph.LoadFromString(@"
@prefix : <urn:> .

:s :p :o .
");

            var shapesGraph = new Graph();

            shapesGraph.LoadFromString(@"
@prefix : <urn:> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

[
    sh:targetNode :s ;
    sh:property [
        sh:path :p ;
        sh:class :C ;
        sh:message ""test message"" ;
    ]
] .
");

            var processor = new ShapesGraph(shapesGraph);
            var report    = processor.Validate(dataGraph);

            var result = report.Results.Single();

            Assert.Equal("test message", result.Message.Value);
        }
コード例 #3
0
ファイル: TestSuite.cs プロジェクト: zhuliangbing/dotnetrdf
        private void Validates(string name)
        {
            ExtractTestData(name, out var testGraph, out var failure, out var dataGraph, out var shapesGraph);

            void validates()
            {
                var actual   = new ShapesGraph(shapesGraph).Validate(dataGraph).Normalised;
                var expected = Report.Parse(testGraph).Normalised;

                RemoveUnnecessaryResultMessages(actual, expected);

                var writer = new CompressingTurtleWriter();

                output.WriteLine(StringWriter.Write(expected, writer));
                output.WriteLine(StringWriter.Write(actual, writer));

                Assert.Equal(expected, actual);
            }

            if (failure)
            {
                Assert.ThrowsAny <Exception>((Action)validates);
            }
            else
            {
                validates();
            }
        }
コード例 #4
0
        internal static IGraph Generate()
        {
            var testSubject = GenerateTestSubjectGraph(DateTime.UtcNow);

            foreach (var test in CoreFullTests.Concat(SparqlTests).Select(testNames => (string)testNames[0]).ToList())
            {
                ExtractTestData(test, out var testGraph, out var shouldFail, out var dataGraph, out var shapesGraph);

                bool conforms()
                {
                    var report = new ShapesGraph(shapesGraph).Validate(dataGraph);

                    var actual   = report.Normalised;
                    var expected = Report.Parse(testGraph).Normalised;

                    RemoveUnnecessaryResultMessages(actual, expected);

                    return(expected.Equals(actual));
                }

                var success = false;
                if (shouldFail)
                {
                    try
                    {
                        conforms();
                    }
                    catch
                    {
                        success = true;
                    }
                }
                else
                {
                    success = conforms();
                }

                if (success)
                {
                    testSubject.Merge(GenerateAssertionGraph(test, "automatic"));
                }
                else
                {
                    throw new Exception();
                }
            }

            // These test fail validation report graph equality chacking but otherwise pass.
            testSubject.Merge(GenerateAssertionGraph("core/path/path-complex-002", "semiAuto"));
            testSubject.Merge(GenerateAssertionGraph("core/property/nodeKind-001", "semiAuto"));

            // These tests contain the URI node <a:b> but otherwise pass.
            testSubject.Merge(GenerateAssertionGraph("core/node/minLength-001", "semiAuto"));
            testSubject.Merge(GenerateAssertionGraph("core/node/maxLength-001", "semiAuto"));

            return(testSubject);
        }
コード例 #5
0
        public void Validation()
        {
            var dataGraph = new Graph();

            dataGraph.LoadFromString(@"
@prefix : <urn:> .

:s :p :o .
");

            var shapesGraph = new Graph();

            shapesGraph.LoadFromString(@"
@prefix : <urn:> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

[
    sh:targetNode :s ;
    sh:property [
        sh:path :p ;
        sh:class :C
    ]
] .
");

            var reportGraph = new Graph();

            reportGraph.LoadFromString(@"
@prefix : <urn:> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

[
    a sh:ValidationReport ;
    sh:conforms false ;
    sh:result [
        a sh:ValidationResult ;
        sh:resultMessage ""Value node must be an instance of type urn:C."" ;
        sh:sourceConstraintComponent sh:ClassConstraintComponent ;
        sh:resultSeverity sh:Violation ;
        sh:sourceShape [] ;
        sh:focusNode :s ;
        sh:resultPath :p ;
        sh:value :o
    ]
] .
");

            var processor = new ShapesGraph(shapesGraph);
            var report    = processor.Validate(dataGraph);

            Assert.Equal(reportGraph, report.Graph);
        }
コード例 #6
0
ファイル: TestSuite.cs プロジェクト: zhuliangbing/dotnetrdf
        private static void Conforms(string name)
        {
            ExtractTestData(name, out var testGraph, out var failure, out var dataGraph, out var shapesGraph);

            void conforms()
            {
                var actual   = new ShapesGraph(shapesGraph).Conforms(dataGraph);
                var expected = Report.Parse(testGraph).Conforms;

                Assert.Equal(expected, actual);
            }

            if (failure)
            {
                Assert.ThrowsAny <Exception>((Action)conforms);
            }
            else
            {
                conforms();
            }
        }