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> /// Starts animation from oldGraph to newGraph. /// </summary> /// <param name="oldGraph"></param> /// <param name="newGraph"></param> /// <param name="diff"></param> public void StartAnimation(PositionedGraph oldGraph, PositionedGraph newGraph, GraphDiff diff) { // account for that the visual controls could have been reused (we are not reusing controls now - NodeControlCache does nothing) this.canvas.Width = newGraph.BoundingRect.Width; this.canvas.Height = newGraph.BoundingRect.Height; if (oldGraph == null) { Draw(newGraph); return; } var durationMove = new Duration(TimeSpan.FromSeconds(animationDurationSeconds)); var durationFade = durationMove; DoubleAnimation fadeOutAnim = new DoubleAnimation(1.0, 0.0, durationFade); DoubleAnimation fadeInAnim = new DoubleAnimation(0.0, 1.0, durationFade); foreach (UIElement drawing in canvas.Children) { var arrow = drawing as Path; if (arrow != null) { arrow.BeginAnimation(UIElement.OpacityProperty, fadeOutAnim); } } foreach (PositionedEdge edge in newGraph.Edges) { AddEdgeToCanvas(edge).BeginAnimation(UIElement.OpacityProperty, fadeInAnim); } foreach (PositionedNode removedNode in diff.RemovedNodes) { removedNode.NodeVisualControl.BeginAnimation(UIElement.OpacityProperty, fadeOutAnim); } foreach (PositionedNode addedNode in diff.AddedNodes) { AddNodeToCanvas(addedNode).BeginAnimation(UIElement.OpacityProperty, fadeInAnim); } bool first = true; foreach (PositionedNode node in diff.ChangedNodes) { var newNode = diff.GetMatchingNewNode(node); PointAnimation anim = new PointAnimation(); if (first) { anim.Completed += (o, e) => { Draw(newGraph); if (oldGraph != null) { foreach (var oldNode in oldGraph.Nodes) { oldNode.ReleaseNodeVisualControl(); } } }; first = false; } anim.From = node.LeftTop; anim.To = newNode.LeftTop; anim.DecelerationRatio = 0.3; anim.AccelerationRatio = 0.3; anim.Duration = durationMove; node.NodeVisualControl.BeginAnimation(CanvasLocationAdapter.LocationProperty, anim); } }
/// <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); }
/// <summary> /// Starts animation from oldGraph to newGraph. /// </summary> /// <param name="oldGraph"></param> /// <param name="newGraph"></param> /// <param name="diff"></param> public void StartAnimation(PositionedGraph oldGraph, PositionedGraph newGraph, GraphDiff diff) { if (oldGraph != null) { foreach (var oldNode in oldGraph.Nodes) { foreach (var newNode in newGraph.Nodes) { if (oldNode.NodeVisualControl == newNode.NodeVisualControl) { ClearCanvas(); } } } } this.canvas.Width = newGraph.BoundingRect.Width; this.canvas.Height = newGraph.BoundingRect.Height; if (oldGraph == null) { Draw(newGraph); return; } double seconds = 0.5; var durationMove = new Duration(TimeSpan.FromSeconds(seconds)); var durationFade = durationMove; DoubleAnimation fadeOutAnim = new DoubleAnimation(1.0, 0.0, durationFade); DoubleAnimation fadeInAnim = new DoubleAnimation(0.0, 1.0, durationFade); foreach (UIElement drawing in canvas.Children) { var arrow = drawing as Path; if (arrow != null) { arrow.BeginAnimation(UIElement.OpacityProperty, fadeOutAnim); } } foreach (PositionedEdge edge in newGraph.Edges) { addEdgeToCanvas(edge).BeginAnimation(UIElement.OpacityProperty, fadeInAnim); } foreach (PositionedGraphNode removedNode in diff.RemovedNodes) { removedNode.NodeVisualControl.BeginAnimation(UIElement.OpacityProperty, fadeOutAnim); } foreach (PositionedGraphNode addedNode in diff.AddedNodes) { addNodeToCanvas(addedNode).BeginAnimation(UIElement.OpacityProperty, fadeInAnim); } bool first = true; foreach (PositionedGraphNode node in diff.ChangedNodes) { var newNode = diff.GetMatchingNewNode(node); PointAnimation anim = new PointAnimation(); if (first) { anim.Completed += new EventHandler((o, e) => { Draw(newGraph); }); first = false; } anim.From = node.LeftTop; anim.To = newNode.LeftTop; anim.DecelerationRatio = 0.3; anim.AccelerationRatio = 0.3; anim.Duration = durationMove; node.NodeVisualControl.BeginAnimation(CanvasLocationAdapter.LocationProperty, anim); } }