Пример #1
0
        public void ExecuteAsync_Should_Throw_WhenNullCallback()
        {
            var graph = new GraphModel(GraphModelTests.DefaultType);

            //graph.ExecuteAsync( null );
            Assert.That(() => graph.ExecuteAsync(null), Throws.ArgumentNullException);
        }
Пример #2
0
        public async Task ExecuteAsync_Should_Succeed_NoNodes()
        {
            var graph = new GraphModel(GraphModelTests.GraphTypeWithConnections);

            var result = await graph.ExecuteAsync(ExecuteNodeAsync);

            Assert.That(result, Is.Not.Null);
        }
Пример #3
0
        public async Task ExecuteAsync_Should_Succeed_SingleNode_Cached()
        {
            var graph    = new GraphModel(GraphModelTests.GraphTypeWithConnections);
            var nodeType = new SourceNode("test");
            var node     = nodeType.CreateNode();

            graph.AddNode(node);

            var result = await graph.ExecuteAsync(ExecuteNodeAsync);

            result = await graph.ExecuteAsync(ExecuteNodeAsync);   // this line will take value from cache

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

            var v1 = GetPortValue <string>(nodeType.Out, result, node);

            Assert.That(v1.HasValue, Is.True);
            Assert.That(v1.Value, Is.EqualTo("test"));
        }
Пример #4
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++"));
        }
Пример #5
0
        public async Task ExecuteAsync_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 = await graph.ExecuteAsync(ExecuteNodeAsync, _ => throw exceptionToCatch);

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