Beispiel #1
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);
        }
Beispiel #2
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));
        }
Beispiel #3
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"));
        }