Exemple #1
0
        private async Task RunNegativeRdfTest(CsvwTestDescription test)
        {
            var actual        = new Graph();
            var insertHandler = new GraphHandler(actual);
            var errorMessages = new List <string>();

            // Set up converter
            var converter = new Converter(
                insertHandler,
                new DefaultResolver(),
                test.Options.Minimal ? ConverterMode.Minimal : ConverterMode.Standard,
                errorMessage => errorMessages.Add(errorMessage),
                suppressStringDatatype: true);

            if (test.Options.Metadata != null)
            {
                var localMetadata = File.ReadAllText(test.Options.Metadata.LocalPath);
                await converter.ConvertWithLocalMetadata(new Uri(_baseUri, test.Action.Uri), new HttpClient(), localMetadata);
            }
            else
            {
                await converter.ConvertAsync(new Uri(_baseUri, test.Action.Uri), new HttpClient());
            }

            Assert.NotEmpty(errorMessages);
        }
Exemple #2
0
        private async Task RunToRdfTest(CsvwTestDescription test, bool expectWarnings)
        {
            var expect = new Graph();

            expect.LoadFromUri(new Uri(_baseUri, test.Result.Uri));

            var actual        = new Graph();
            var insertHandler = new GraphHandler(actual);
            var errorMessages = new List <string>();

            // Set up converter
            var converter = new Converter(
                insertHandler,
                new DefaultResolver(),
                test.Options.Minimal ? ConverterMode.Minimal : ConverterMode.Standard,
                errorMessage => errorMessages.Add(errorMessage),
                suppressStringDatatype: true);

            if (test.Options.Metadata != null)
            {
                var localMetadata = File.ReadAllText(test.Options.Metadata.LocalPath);
                await converter.ConvertWithLocalMetadata(new Uri(_baseUri, test.Action.Uri), new HttpClient(), localMetadata);
            }
            else
            {
                await converter.ConvertAsync(new Uri(_baseUri, test.Action.Uri), new HttpClient());
            }

            //var tableGroup = new TableGroup();
            //var table = new Table(tableGroup) {Url = new Uri(_baseUri, test.Action.Uri)};
            //await converter.ConvertAsync(tableGroup, new DefaultResolver());
            converter.Errors.Should().BeEmpty("expected no errors during conversion");
            var differ = new GraphDiff();

            NormalizeLiterals(expect);
            NormalizeLiterals(actual);
            var graphDiff = differ.Difference(expect, actual);

            // Assert graphs are equal
            //actual.Triples.Count.Should().Be(expect.Triples.Count,
            //    "Count of triples in output graph should match the count of triples in the expected result graph");
            //Assert.Equal(expect.Triples.Count, actual.Triples.Count);
            Assert.True(graphDiff.AreEqual, "Expected graphs to be the same.\n" + ReportGraphDiff(graphDiff));
        }
Exemple #3
0
        /* */

        private async Task RunTestAsync(CsvwTestDescription test)
        {
            switch (test.TestType)
            {
            case CsvwTestType.ToRdfTest:
                await RunToRdfTest(test, false);

                break;

            case CsvwTestType.ToRdfTestWithWarnings:
                await RunToRdfTest(test, true);

                break;

            case CsvwTestType.NegativeRdfTest:
                await RunNegativeRdfTest(test);

                break;
            }
        }
Exemple #4
0
        private void SetupTest(CsvwTestDescription test)
        {
            var csvResponse = Response.Create()
                              .WithBodyFromFile(test.Action.LocalFilePath)
                              .WithHeader("Content-Type", test.Action.LocalFilePath.EndsWith(".json") ? "application/json" : "text/csv")
                              .WithStatusCode(200);

            if (!string.IsNullOrEmpty(test.HttpLink))
            {
                csvResponse = csvResponse.WithHeader("Link", test.HttpLink);
            }

            _server
            .Given(Request.Create().WithPath("/" + test.Action.Uri).UsingGet())
            .RespondWith(csvResponse);

            if (test.Result.LocalFilePath != null)
            {
                _server
                .Given(Request.Create().WithPath("/" + test.Result.Uri).UsingGet())
                .RespondWith(
                    Response.Create()
                    .WithBodyFromFile(test.Result.LocalFilePath)
                    .WithHeader("Content-Type", "application/turtle")
                    .WithStatusCode(200)
                    );
            }

            if (test.Implicit != null)
            {
                foreach (var implictFile in test.Implicit)
                {
                    _server.Given(Request.Create().WithPath("/" + implictFile.Uri).UsingGet())
                    .RespondWith(
                        Response.Create()
                        .WithBodyFromFile(implictFile.LocalFilePath)
                        .WithHeader("Content-Type", "application/csvm+json")
                        .WithStatusCode(200));
                }
            }
        }
Exemple #5
0
 public async void CsvwRdfTests(CsvwTestDescription test)
 {
     SetupTest(test);
     await RunTestAsync(test);
 }
Exemple #6
0
        private CsvwTestDescription ReadTestDescription(IUriNode testNode)
        {
            var mfName       = _manifestGraph.CreateUriNode("mf:name");
            var mfAction     = _manifestGraph.CreateUriNode("mf:action");
            var mfResult     = _manifestGraph.CreateUriNode("mf:result");
            var rdfType      = _manifestGraph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
            var rdfsComment  = _manifestGraph.CreateUriNode("rdfs:comment");
            var rdftApproval = _manifestGraph.CreateUriNode("rdft:approval");
            var rdftApproved = _manifestGraph.CreateUriNode("rdft:Approved");
            var csvtOption   = _manifestGraph.CreateUriNode("csvt:option");
            var csvtImplicit = _manifestGraph.CreateUriNode("csvt:implicit");
            var csvtHttpLink = _manifestGraph.CreateUriNode("csvt:httpLink");

            // Don't pass tests that are not approved to the test runner
            var approved = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, rdftApproval)
                           .WithObject(rdftApproved).Any();

            if (!approved)
            {
                return(null);
            }

            var type = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, rdfType)
                       .Select(t => (t.Object as IUriNode)).FirstOrDefault()?.ToString();

            if (type == null)
            {
                return(null);
            }
            CsvwTestType testType;

            switch (type)
            {
            case "http://www.w3.org/2013/csvw/tests/vocab#ToRdfTest":
                testType = CsvwTestType.ToRdfTest;
                break;

            case "http://www.w3.org/2013/csvw/tests/vocab#ToRdfTestWithWarnings":
                testType = CsvwTestType.ToRdfTestWithWarnings;
                break;

            case "http://www.w3.org/2013/csvw/tests/vocab#NegativeRdfTest":
                testType = CsvwTestType.NegativeRdfTest;
                break;

            default:
                throw new Exception("Unrecognized test type: " + type);
            }

            var testId = testNode.Uri.Fragment;
            var name   = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, mfName)
                         .Select(t => t.Object.AsValuedNode().AsString()).FirstOrDefault();
            var comment = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, rdfsComment)
                          .Select(t => t.Object.AsValuedNode().AsString()).FirstOrDefault();
            var optionsNode = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, csvtOption)
                              .Select(t => t.Object).FirstOrDefault();
            var options = GetOptions(optionsNode);
            var action  = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, mfAction)
                          .Select(t => (t.Object as IUriNode)?.Uri).FirstOrDefault();
            var result = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, mfResult)
                         .Select(t => (t.Object as IUriNode)?.Uri).FirstOrDefault();
            var implicitResources = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, csvtImplicit)
                                    .Select(t => (t.Object as IUriNode)?.Uri).ToList();
            var httpLink = _manifestGraph.GetTriplesWithSubjectPredicate(testNode, csvtHttpLink)
                           .Select(t => (t.Object as ILiteralNode)?.Value).FirstOrDefault();

            var relAction = action == null ? null : _manifestGraph.BaseUri.MakeRelativeUri(action);
            var relResult = result == null ? null : _manifestGraph.BaseUri.MakeRelativeUri(result);

            var testDescription = new CsvwTestDescription
            {
                Id       = testId,
                Name     = name,
                Comment  = comment,
                TestType = testType,
                Approved = true,
                Options  = options,
                Action   = new CsvwTestFileDescription
                {
                    Uri           = relAction,
                    LocalFilePath = action?.LocalPath
                },
                Result = new CsvwTestFileDescription
                {
                    Uri           = relResult,
                    LocalFilePath = result?.LocalPath
                },
                Implicit = new List <CsvwTestFileDescription>(),
                HttpLink = httpLink
            };

            foreach (var implicitResource in implicitResources)
            {
                var relImplicit = implicitResource == null
                    ? null
                    : _manifestGraph.BaseUri.MakeRelativeUri(implicitResource);
                testDescription.Implicit.Add(new CsvwTestFileDescription
                {
                    Uri           = relImplicit,
                    LocalFilePath = implicitResource?.LocalPath
                });
            }

            return(testDescription);
        }