Ejemplo n.º 1
0
        public async Task ExecuteAsync_Should_Succeed_MultipleNodes()
        {
            // graph sceme:
            //   node1 -------------> node2 -------------> node3
            //          connection1          connection2

            var graph        = new GraphModel(GraphModelTests.CreateGraphType(new AppendConnection("+")));
            var sourceType   = new SourceNode("test");
            var transferType = new TransferNode();
            var destType     = new DestinationNode();

            var node1 = sourceType.CreateNode();

            graph.AddNode(node1);

            var node2 = transferType.CreateNode();

            graph.AddNode(node2);

            var node3 = destType.CreateNode();

            graph.AddNode(node3);

            var connection1 = graph.Connect(sourceType.Out.FromNode(node1), transferType.In.FromNode(node2));
            var connection2 = graph.Connect(transferType.Out.FromNode(node2), destType.In.FromNode(node3));

            var result = await graph.ExecuteAsync(ExecuteNodeAsync, ExecuteConnectionAsync);

            Assert.That(result, Is.Not.Null);

            var pv1 = GetPortValue <string>(sourceType.Out, result, node1);

            Assert.That(pv1.HasValue, Is.True);
            Assert.That(pv1.Value, Is.EqualTo("test"));

            var pv2 = GetPortValue <string>(transferType.Out, result, node2);

            Assert.That(pv2.HasValue, Is.True);
            Assert.That(pv2.Value, Is.EqualTo("test+"));

            var cv1 = GetConnectionValue <string>(result, connection1);

            Assert.That(cv1.HasValue, Is.True);
            Assert.That(cv1.Value, Is.EqualTo("test+"));

            var cv2 = GetConnectionValue <string>(result, connection2);

            Assert.That(cv2.HasValue, Is.True);
            Assert.That(cv2.Value, Is.EqualTo("test++"));

            Assert.That(destType.OutValue, Is.EqualTo("test++"));
        }
Ejemplo n.º 2
0
        public void Execute_Should_Succeed_CatchException_DuringConnectionActionExecution()
        {
            var exceptionToCatch = new Exception("some_exception");

            var graph        = new GraphModel(GraphModelTests.CreateGraphType(new AppendConnection("+")));
            var sourceType   = new SourceNode("test");
            var transferType = new TransferNode();

            var node1 = sourceType.CreateNode();

            graph.AddNode(node1);

            var node2 = transferType.CreateNode();

            graph.AddNode(node2);

            graph.Connect(sourceType.Out.FromNode(node1), transferType.In.FromNode(node2));

            var result = graph.Execute(ExecuteNode, _ => throw exceptionToCatch);

            Assert.IsNotEmpty(result.Exceptions);
            Assert.That(result.Exceptions, Has.Member(exceptionToCatch));
        }