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)); }
public async void TestValidConversions(string tableMetadataPath, string csvFilePath, string expectedOutputGraphPath) { var metadataParser = new JsonMetadataParser(new DefaultResolver(), new Uri("http://example.org/metadata.json")); tableMetadataPath = Path.Combine("data", tableMetadataPath); csvFilePath = Path.Combine("data", csvFilePath); expectedOutputGraphPath = Path.Combine("data", expectedOutputGraphPath); TableGroup tableGroup; using (var metadataReader = File.OpenText(tableMetadataPath)) { tableGroup = metadataParser.Parse(metadataReader); } tableGroup.Should().NotBeNull(); tableGroup.Tables.Should().HaveCount(1); var tableMeta = tableGroup.Tables[0]; tableMeta.Should().NotBeNull(because: "The metadata file should parse as table metadata"); var outputGraph = new Graph(); var graphHandler = new GraphHandler(outputGraph); var resolverMock = new Mock <ITableResolver>(); resolverMock.Setup(x => x.ResolveAsync(It.IsAny <Uri>())).Returns(Task.FromResult(File.OpenRead(csvFilePath) as Stream)); var converter = new Converter(graphHandler, resolverMock.Object, ConverterMode.Minimal); await converter.ConvertAsync(tableMeta.Parent as TableGroup); converter.Errors.Count.Should().Be(0, "Expected 0 errors. Got {0}. Error listing is:\n{1}", converter.Errors.Count, string.Join("\n", converter.Errors)); var turtleParser = new TurtleParser(TurtleSyntax.W3C); var expectGraph = new Graph(); turtleParser.Load(expectGraph, expectedOutputGraphPath); var diff = new GraphDiff(); var diffReport = diff.Difference(expectGraph, outputGraph); diffReport.AreEqual.Should().BeTrue("Graphs differ"); }
/// <summary> /// Computes the Difference between this Graph the given Graph /// </summary> /// <param name="g">Graph</param> /// <returns></returns> /// <remarks> /// <para> /// Produces a report which shows the changes that must be made to this Graph to produce the given Graph /// </para> /// </remarks> public GraphDiffReport Difference(IGraph g) { GraphDiff differ = new GraphDiff(); return differ.Difference(this, g); }