Example #1
0
        public static void MyClassInitialize(TestContext testContext)
        {
            GraphSerializer gSrz = null;

            gSrz    = new GraphSerializer();
            m_graph = gSrz.Deserialize(@"c:\temp\training\car_graph.xml");
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KDocumentBase"/> class.
        /// </summary>
        public CSDocument(Microsoft.CodeAnalysis.Document document)
        {
            this.IsGraphActive = true;
            this.Document      = document;
            this.Name          = document.Name;
            this.FilePath      = document.FilePath;

            this.AvalonDocument = new ICSharpCode.AvalonEdit.Document.TextDocument()
            {
                FileName = this.Name, Text = File.ReadAllText(document.FilePath)
            };
            this.AvalonDocument.TextChanged += AvalonDocument_TextChanged;

            if (File.Exists(this.GraphFilePath))
            {
                _graph = GraphSerializer.Deserialize <CSGraph>(File.ReadAllText(this.GraphFilePath));
            }
            else
            {
                _graph = new CSGraph();
            }

            this.Graph.Name     = Path.GetFileNameWithoutExtension(document.Name);
            this.Graph.FilePath = this.GraphFilePath;
            this.Graph.Document = document;

            _graph.GraphChanged         += _graph_GraphChanged;
            _graph.NodeChanged          += _graph_NodeChanged;
            _graph.NodeSelectionChanged += _graph_NodeSelectionChanged;
            _graph.CodeChanged          += _graph_CodeChanged;

            OnNodeSelectionChanged();
        }
Example #3
0
        public void Test_Deserialize()
        {
            GraphSerializer gSrz = null;
            Graph           g    = null;

            gSrz = new GraphSerializer();
            g    = gSrz.Deserialize(GRAPH_INFO_FILE);

            Assert.AreEqual("Carmelia area roadmap as graph model", g.Description);
        }
Example #4
0
        private Graph LoadGraphFromInfoFile()
        {
            GraphSerializer gSrz = null;
            Graph           g    = null;

            gSrz = new GraphSerializer();
            g    = gSrz.Deserialize(GRAPH_INFO_FILE);

            return(g);
        }
Example #5
0
        public void Deserialize_Should_Throw_WhenGraphTypeNotFound()
        {
            var sgraph = new SGraph()
            {
                Type = "NonExistingType"
            };
            var str = JsonConvert.SerializeObject(sgraph);

            Assert.That(() => GraphSerializer.Deserialize(str), Throws.InvalidOperationException);
        }
        public void Deserialize_CanDeserializePrettyJson()
        {
            // Arrange
            var node           = new TestNode(99);
            var expected       = new SerializedNode(node);
            var serializedNode = GetSerializeString(expected, true);

            using (var reader = new StringReader(serializedNode))
            {
                // Act
                var actual = GraphSerializer.Deserialize(reader);

                // Assert
                Assert.Equal(expected.NodeType, actual.NodeType);
                Assert.Equal(((TestNode)expected.Node).SomeValue, ((TestNode)actual.Node).SomeValue);
            }
        }
Example #7
0
        public void Deserialize_Should_Throw_WhenNodeTypeNotFound_ByCustomResolver()
        {
            var sgraph = new SGraph()
            {
                Type = typeof(GraphTypeWithResolver).FullName
            };
            var snode = new SNode()
            {
                Type = "NonExistingType"
            };

            sgraph.AddNode(snode);

            var str = JsonConvert.SerializeObject(sgraph);

            Assert.That(() => GraphSerializer.Deserialize(str), Throws.InvalidOperationException);
        }
Example #8
0
        public void Deserialize_Should_Return_BrokenConnections(string fromNodeId, string fromPortId, string toNodeId, string toPortId)
        {
            var sgraph = new SGraph()
            {
                Type = typeof(GraphType).FullName
            };

            var snode1 = new SNode()
            {
                Id = "1", Type = typeof(NodeWithProperties).FullName, Properties = "{}"
            };
            var snode2 = new SNode()
            {
                Id = "2", Type = typeof(NodeWithProperties).FullName, Properties = "{}"
            };

            sgraph.AddNode(snode1);
            sgraph.AddNode(snode2);

            var sconnection = new SConnection()
            {
                FromNodeId = fromNodeId,
                FromPortId = fromPortId,
                ToNodeId   = toNodeId,
                ToPortId   = toPortId,
            };

            sgraph.AddConnection(sconnection);

            var brokenConnections = new List <SConnection>();

            var str = JsonConvert.SerializeObject(sgraph);

            GraphSerializer.Deserialize(str, brokenConnections);

            Assert.That(brokenConnections, Has.Count.EqualTo(1));

            var c = brokenConnections[0];

            Assert.That(c.FromNodeId, Is.EqualTo(sconnection.FromNodeId));
            Assert.That(c.FromPortId, Is.EqualTo(sconnection.FromPortId));
            Assert.That(c.ToNodeId, Is.EqualTo(sconnection.ToNodeId));
            Assert.That(c.ToPortId, Is.EqualTo(sconnection.ToPortId));
        }
Example #9
0
        public void Deserialize_Should_Fix_ConnectionDirection()
        {
            var sgraph = new SGraph()
            {
                Type = typeof(GraphType).FullName
            };

            var snode1 = new SNode()
            {
                Id = "1", Type = typeof(NodeWithProperties).FullName, Properties = "{}"
            };
            var snode2 = new SNode()
            {
                Id = "2", Type = typeof(NodeWithProperties).FullName, Properties = "{}"
            };

            sgraph.AddNode(snode1);
            sgraph.AddNode(snode2);

            // this connection has inverted direction: In -> Out
            var sconnection = new SConnection()
            {
                FromNodeId = "2",
                FromPortId = "In",
                ToNodeId   = "1",
                ToPortId   = "Out",
            };

            sgraph.AddConnection(sconnection);

            var str   = JsonConvert.SerializeObject(sgraph);
            var graph = GraphSerializer.Deserialize(str);

            Assert.That(graph.Connections.Count, Is.EqualTo(1));

            var c = graph.Connections[0];

            Assert.That(c.From.Node.Id, Is.EqualTo("1"));
            Assert.That(c.From.Id, Is.EqualTo("Out"));
            Assert.That(c.To.Node.Id, Is.EqualTo("2"));
            Assert.That(c.To.Id, Is.EqualTo("In"));
        }
Example #10
0
 public void Deserialize_Should_Throw_WhenNullGraph()
 {
     Assert.That(() => GraphSerializer.Deserialize(null), Throws.ArgumentNullException);
 }
Example #11
0
        private GraphModel SaveLoadGraph(GraphModel graph)
        {
            var str = GraphSerializer.Serialize(graph);

            return(GraphSerializer.Deserialize(str));
        }