Exemplo n.º 1
0
        public void Multiple_Flows_Can_Be_Registered()
        {
            var kernel = new StandardKernel();

            kernel.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new NinjectFlowRegistrar(kernel));

            flowBuilder.CreateFlow("TestFlow2")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode4>()
            .AddChild <ITestNode3>()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            var factory = kernel.Get <INodeFactory <object> >();

            var flow = factory.BuildFlow("TestFlow1");

            flow.Should().NotBeNull();

            flow = factory.BuildFlow("TestFlow2");
            flow.Should().NotBeNull();
        }
Exemplo n.º 2
0
        public void Simple_Flow_Contains_Subflow()
        {
            var kernel = new StandardKernel();

            kernel.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new NinjectFlowRegistrar(kernel));

            flowBuilder.CreateFlow("TestFlow2")
            .AddRoot <PipelineNode <object> >()
            .AddChild <ITestNode4>()
            .AddChild <ITestNode3>()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <PipelineNode <object> >()
            .AddChild <ITestNode2>()
            .AddFlow("TestFlow2");

            flowBuilder.Register();

            var factory = kernel.Get <INodeFactory <object> >();

            var flow = (IPipelineNode <object>)factory.BuildFlow("TestFlow1");

            flow.Should().BeOfType <PipelineNode <object> >();
            flow.Children.Count.Should().Be(2);
            var subflow = (IPipelineNode <object>)flow.Children[1];

            subflow.Children.Count.Should().Be(3);
            subflow.Children[1].Should().BeOfType <TestNode3>();
        }
Exemplo n.º 3
0
        public void Adding_ShouldExecute_To_Subflow_Applies_To_Subflow_Root()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow2")
            .AddRoot <PipelineNode <object> >()
            .AddChild <ITestNode4>()
            .AddChild <ITestNode3>()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <PipelineNode <object> >()
            .AddChild <ITestNode2>()
            .AddFlow("TestFlow2")
            .ForChildFlow("TestFlow2").SetShouldExecute(ctxt => Task.FromResult(1 + 1 == 3));

            flowBuilder.Register();

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <object> >();

            var flow = (IPipelineNode <object>)factory.BuildFlow("TestFlow1");

            var subflowRoot = (IPipelineNode <object>)flow.Children[1];

            subflowRoot.ShouldExecuteFunc.Should().NotBeNull();
            subflowRoot.ShouldExecuteFunc(new ExecutionContext <object>(new object())).Result.Should().BeFalse();
        }
        public void Adding_ShouldExecute_To_Subflow_Applies_To_Subflow_Root()
        {
            var kernel = new StandardKernel();

            kernel.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new NinjectFlowRegistrar(kernel));

            flowBuilder.CreateFlow("TestFlow2")
            .AddRoot <PipelineNode <object> >()
            .AddChild <ITestNode4>()
            .AddChild <ITestNode3>()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <PipelineNode <object> >()
            .AddChild <ITestNode2>()
            .AddFlow("TestFlow2")
            .ForChildFlow("TestFlow2").SetShouldExecuteBlock <ShouldNotExecuteTestBlock>();

            flowBuilder.Register();

            var factory = kernel.Get <INodeFactory <object> >();

            var flow = (IPipelineNode <object>)factory.BuildFlow("TestFlow1");

            var subflowRoot = (IPipelineNode <object>)flow.Children[1];

            subflowRoot.ShouldExecuteBlock.ShouldNotBeNull();
            ((IShouldExecuteBlock <object>)subflowRoot.ShouldExecuteBlock).ShouldExecuteAsync(new ExecutionContext <object>(new object())).Result.ShouldBeFalse();
        }
Exemplo n.º 5
0
        public void Multiple_Flows_Can_Be_Registered()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow2")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode4>()
            .AddChild <ITestNode3>()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <object> >();

            var flow = factory.BuildFlow("TestFlow1");

            flow.ShouldNotBeNull();

            flow = factory.BuildFlow("TestFlow2");
            flow.ShouldNotBeNull();
        }
Exemplo n.º 6
0
        public void Simple_Flow_Contains_All_Nodes()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <PipelineNode <object> >()
            .AddChild <ITestNode2>()
            .AddChild <IPipelineNode <object> >()
            .ForLastChild()
            .AddChild <ITestNode4>()
            .AddChild <ITestNode3>()
            .AddChild <ITestNode2>()
            .ForParent()
            .AddChild <ITestNode3>();

            flowBuilder.Register();

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <object> >();

            var flow = (IPipelineNode <object>)factory.BuildFlow("TestFlow1");

            flow.ShouldBeType <PipelineNode <object> >();
            flow.Children.Count.ShouldEqual(3);
            var subflow = (IPipelineNode <object>)flow.Children[1];

            subflow.Children.Count.ShouldEqual(3);
            subflow.Children[1].ShouldBeType <TestNode3>();
        }
Exemplo n.º 7
0
        public void Simple_Flow_Is_Serialized_With_Full_Abbreviations()
        {
            TypeAbbreviationCache.RegisterFromAssembly(GetType().Assembly, true, false);

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

            _testOutputHelper.WriteLine(definition);

            definition.Should().NotBeNullOrEmpty();
            definition.Should().Contain("Banzai.Serialization.SystemJson.Test");
        }
Exemplo n.º 8
0
        public void Simple_Flow_Is_Deserialized()
        {
            TypeAbbreviationCache.RegisterFromAssembly(GetType().Assembly, failOnCollision: false);

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

            var deserializedComponent = serializer.Deserialize <object>(definition);

            deserializedComponent.Should().NotBeNull();

            deserializedComponent.Children[0].Children.Count.Should().Be(1);
        }
Exemplo n.º 9
0
        public void Simple_Flow_With_ShouldExecuteJavaScript_Is_Deserialized()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestJsNode>()
            .AddChild <ITestNode2>()
            .ForChild <ITestJsNode>()
            .SetShouldExecuteJavaScript("var x = 1;");

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

            FlowComponent <object> deserializedComponent = serializer.Deserialize <object>(definition);

            deserializedComponent.ShouldNotBeNull();

            var pipelineComponent = deserializedComponent.Children[0];

            pipelineComponent.Children.Count.ShouldEqual(2);

            var jsNode = pipelineComponent.Children[0];

            jsNode.GetShouldExecuteJavaScript().ShouldEqual("var x = 1;");
        }
Exemplo n.º 10
0
        public void CheckFlowWithSwitch()
        {
            // Arrange
            var b = new FlowBuilder();

            var s  = b.SwitchOf <int>();
            var a1 = b.DummyActivity();
            var a2 = b.DummyActivity();
            var a3 = b.DummyActivity();

            b.WithInitialNode(s);
            s.ConnectCase(0).To(a1);
            s.ConnectCase(1).To(a2);
            s.ConnectDefaultTo(a3);

            var e = b.DummyActivity();

            var validator = new ReachabilityValidator();

            // Act
            validator.Validate(b.CreateFlow());
            var result = validator.Result;

            // Assert
            Assert.That(result.GetErrorsOf(s), Is.Empty);
            Assert.That(result.GetErrorsOf(a1), Is.Empty);
            Assert.That(result.GetErrorsOf(a2), Is.Empty);
            Assert.That(result.GetErrorsOf(a3), Is.Empty);
            Assert.That(result.GetErrorsOf(e), Is.Not.Empty);
        }
Exemplo n.º 11
0
        public void CheckFlowWithBlock()
        {
            // Arrange
            var b = new FlowBuilder();

            IFlowNode a = null;
            IFlowNode e = null;

            var block = b.Block("test", (_, builder) =>
            {
                a = builder.DummyActivity();
                e = builder.DummyActivity();
            });

            b.WithInitialNode(block);

            var validator = new ReachabilityValidator();

            // Act
            validator.Validate(b.CreateFlow());
            var result = validator.Result;

            // Assert
            Assert.That(result.GetErrorsOf(block), Is.Empty);
            Assert.That(result.GetErrorsOf(a), Is.Empty);
            Assert.That(result.GetErrorsOf(e), Is.Not.Empty);
        }
Exemplo n.º 12
0
        public void Simple_Flow_Is_Built_With_NodeFactory_And_Json_Serializer()
        {
            Registrar.RegisterAsDefault();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <object> >();

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            var component = flowBuilder.RootComponent;

            var serialized = SerializerProvider.Serializer.Serialize(component);

            var flow = factory.BuildSerializedFlow(serialized);

            flow.Should().NotBeNull();
        }
Exemplo n.º 13
0
        public void Flow_Is_Built_With_NodeFactory_And_Json_Serializer()
        {
            Json.Registrar.RegisterAsDefault();

            var kernel = new StandardKernel();

            kernel.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new NinjectFlowRegistrar(kernel));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            var component = flowBuilder.RootComponent;
            var factory   = kernel.Get <INodeFactory <object> >();

            var serialized = SerializerProvider.Serializer.Serialize(component);

            var flow = factory.BuildSerializedFlow(serialized);

            flow.FlowId.Should().Be("TestFlow1");
            flow.Id.Should().Be("Banzai.Ninject.Test.TestPipelineNode1");
            ((IMultiNode <object>)flow).Children[0].Id.Should().Be("Banzai.Ninject.Test.TestNode2");
        }
Exemplo n.º 14
0
        public void Flow_Builder_Is_Hydrated_And_Flow_Built_From_Json_Serializer()
        {
            Json.Registrar.RegisterAsDefault();

            var kernel = new StandardKernel();

            kernel.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new NinjectFlowRegistrar(kernel));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            var factory = kernel.Get <INodeFactory <object> >();

            var serialized = flowBuilder.SerializeRootComponent();

            Console.WriteLine(serialized);

            var component = flowBuilder.DeserializeAndSetRootComponent(serialized);

            var flow = factory.BuildFlow(component);

            flow.FlowId.ShouldEqual("TestFlow1");
            flow.Id.ShouldEqual("Banzai.Ninject.Test.TestPipelineNode1");
            ((IMultiNode <object>)flow).Children[0].Id.ShouldEqual("Banzai.Ninject.Test.TestNode2");
        }
Exemplo n.º 15
0
        public async Task ShouldExecuteAsync_Is_Added_To_Child_Node()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>()
            .ForChild <ITestNode2>().SetShouldExecute(ctxt => Task.FromResult(1 + 1 != 2));

            flowBuilder.Register();

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <object> >();

            var flow = (IPipelineNode <object>)factory.BuildFlow("TestFlow1");

            var subflow = flow.Children[0];

            subflow.ShouldExecuteFunc.Should().NotBeNull();
            (await subflow.ShouldExecuteFunc(new ExecutionContext <object>(new object()))).Should().BeFalse();
        }
Exemplo n.º 16
0
        public void ShouldExecute_Is_Added_To_Child_Node()
        {
            var kernel = new StandardKernel();

            kernel.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new NinjectFlowRegistrar(kernel));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>()
            .ForChild <ITestNode2>()
            .SetShouldExecute(ctxt => Task.FromResult(1 + 1 == 3));

            flowBuilder.Register();

            var factory = kernel.Get <INodeFactory <object> >();

            var flow = (IPipelineNode <object>)factory.BuildFlow("TestFlow1");

            var subflow = flow.Children[0];

            subflow.ShouldExecuteFunc.ShouldNotBeNull();
            subflow.ShouldExecuteFunc(new ExecutionContext <object>(new object())).Result.ShouldBeFalse();
        }
Exemplo n.º 17
0
        public void Flow_Builder_Is_Hydrated_And_Flow_Built_From_Json_Serializer()
        {
            Json.Registrar.RegisterAsDefault();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var container   = containerBuilder.Build();
            var factory     = container.Resolve <INodeFactory <object> >();
            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            var serialized = flowBuilder.SerializeRootComponent();

            Console.WriteLine(serialized);


            var component = flowBuilder.DeserializeAndSetRootComponent(serialized);

            var flow = factory.BuildFlow(component);

            flow.FlowId.Should().Be("TestFlow1");
            flow.Id.Should().Be("Banzai.Autofac.Test.TestPipelineNode1");
            ((IMultiNode <object>)flow).Children[0].Id.Should().Be("Banzai.Autofac.Test.TestNode2");
        }
Exemplo n.º 18
0
        public void ShouldExecute_Is_Added_To_Child_Node()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>()
            .ForChild <ITestNode2>()
            .SetShouldExecuteBlock <ShouldNotExecuteTestBlock>();

            flowBuilder.Register();

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <object> >();

            var flow = (IPipelineNode <object>)factory.BuildFlow("TestFlow1");

            var subflow = flow.Children[0];

            subflow.ShouldExecuteBlock.ShouldNotBeNull();
            ((IShouldExecuteBlock <object>)subflow.ShouldExecuteBlock).ShouldExecuteAsync(new ExecutionContext <object>(new object())).Result.ShouldBeFalse();
        }
Exemplo n.º 19
0
        public void Flow_Is_Built_With_NodeFactory_And_Json_Serializer()
        {
            Json.Registrar.RegisterAsDefault();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <object> >();

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode2>();

            var component = flowBuilder.RootComponent;

            var serialized = SerializerProvider.Serializer.Serialize(component);

            var flow = factory.BuildSerializedFlow(serialized);

            flow.FlowId.ShouldEqual("TestFlow1");
            flow.Id.ShouldEqual("Banzai.Autofac.Test.TestPipelineNode1");
            ((IMultiNode <object>)flow).Children[0].Id.ShouldEqual("Banzai.Autofac.Test.TestNode2");
        }
Exemplo n.º 20
0
        public void Simple_Flow_Is_Serialized_With_Full_Abbreviations()
        {
            TypeAbbreviationCache.Clear();
            TypeAbbreviationCache.RegisterFromAssembly(GetType().Assembly, useFullName: true, failOnCollision: false);

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestJsNode>()
            .AddChild <ITestNode2>();

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

            Console.WriteLine(definition);

            definition.ShouldNotBeNull().ShouldNotBeEmpty();
            definition.ShouldContain("Banzai.Json.Test");
        }
Exemplo n.º 21
0
        public void Flow_With_ShouldExecuteBlock_Is_Deserialized()
        {
            TypeAbbreviationCache.RegisterFromAssembly(GetType().Assembly, failOnCollision: false);

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >().SetShouldExecuteBlock <ShouldNotExecuteTestBlock>()
            .AddChild <ITestJsNode>()
            .AddChild <ITestNode2>();

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

            FlowComponent <object> deserializedComponent = serializer.Deserialize <object>(definition);

            deserializedComponent.ShouldNotBeNull();

            deserializedComponent.Children[0].ShouldExecuteBlockType.ShouldEqual(typeof(ShouldNotExecuteTestBlock));
        }
Exemplo n.º 22
0
        public void Flow_With_ShouldExecuteBlock_Is_Serialized_With_Abbreviations()
        {
            TypeAbbreviationCache.RegisterFromAssembly(GetType().Assembly, failOnCollision: false);

            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <object> >().SetShouldExecuteBlock <ShouldNotExecuteTestBlock>()
            .AddChild <ITestJsNode>()
            .AddChild <ITestNode2>();

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

            Console.WriteLine(definition);

            definition.ShouldNotBeNull().ShouldNotBeEmpty();
            definition.ShouldContain("\"ShouldExecuteBlockType\":\"ShouldNotExecuteTestBlock\"");
        }
Exemplo n.º 23
0
        public void Adding_Child_Flow_To_Simple_Node_Errs()
        {
            var kernel = new StandardKernel();

            kernel.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new NinjectFlowRegistrar(kernel));

            flowBuilder.CreateFlow("TestFlow2")
            .AddRoot <IPipelineNode <object> >()
            .AddChild <ITestNode4>()
            .AddChild <ITestNode3>()
            .AddChild <ITestNode2>();

            flowBuilder.Register();

            var componentBuilder = flowBuilder.CreateFlow("TestFlow")
                                   .AddRoot <ITestNode4>();

            Assert.Throws <InvalidOperationException>(() => componentBuilder.AddFlow("TestFlow2"));
        }
        public void ErrorWhenActivityHasNoPublicConstructor()
        {
            // Arrange
            var builder   = new FlowBuilder();
            var node      = builder.Activity <ActivityWithoutPublicCtor>();
            var validator = new ActivityTypeValidator();

            // Act
            validator.Validate(builder.CreateFlow());

            // Assert
            Assert.That(validator.Result.GetErrorsOf(node), Is.Not.Empty);
        }
Exemplo n.º 25
0
        public void Adding_Child_Node_To_Simple_Node_Errs()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);

            var flowBuilder = new FlowBuilder <object>(new AutofacFlowRegistrar(containerBuilder));

            var componentBuilder = flowBuilder.CreateFlow("TestFlow")
                                   .AddRoot <ITestNode4>();

            Assert.Throws <InvalidOperationException>(() => componentBuilder.AddChild <ITestNode4>());
        }
        public void ErrorWhenActivityIsAbstract()
        {
            // Arrange
            var builder   = new FlowBuilder();
            var node      = builder.Activity <AbstractActivity>();
            var validator = new ActivityTypeValidator();

            // Act
            validator.Validate(builder.CreateFlow());

            // Assert
            Assert.That(validator.Result.GetErrorsOf(node), Is.Not.Empty);
        }
        public void CheckRequiredInitializers()
        {
            // Arrange
            var b    = new FlowBuilder();
            var node = b.Activity <DelayedIncrementActivity>();

            var validator = new ActivityInitializationValidator();

            // Act
            validator.Validate(b.CreateFlow());

            // Assert
            Assert.That(validator.Result.GetErrorsOf(node), Is.Not.Empty);
        }
        public void NoErrorsWhenGood()
        {
            // Arrange
            var b    = new FlowBuilder();
            var node = b.Activity <DelayedIncrementActivity>();

            node.Bind(a => a.X).To(1);

            var validator = new ActivityInitializationValidator();

            // Act
            validator.Validate(b.CreateFlow());

            // Assert
            Assert.That(validator.Result.GetErrorsOf(node), Is.Empty);
        }
Exemplo n.º 29
0
        public async void Deserialized_Flow_Component_Can_Be_Built_And_Run()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterBanzaiNodes(GetType().Assembly, true);
            containerBuilder.RegisterBanzaiNodes(typeof(JavaScriptMetaDataBuilder).Assembly, true);

            var flowBuilder = new FlowBuilder <TestObjectA>(new AutofacFlowRegistrar(containerBuilder));

            flowBuilder.CreateFlow("TestFlow1")
            .AddRoot <IPipelineNode <TestObjectA> >()
            .AddChild <ITestJsNode2>()
            .AddChild <ITestNode2>()
            .ForChild <ITestJsNode2>()
            .SetExecutedJavaScript("context.Subject.TestValueString = 'Hello JavaScript';");

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

            Console.WriteLine(definition);

            FlowComponent <TestObjectA> deserializedComponent = serializer.Deserialize <TestObjectA>(definition);

            deserializedComponent.ShouldNotBeNull();

            flowBuilder.RootComponent = deserializedComponent;

            flowBuilder.Register();

            var container = containerBuilder.Build();

            var factory = container.Resolve <INodeFactory <TestObjectA> >();

            var flowRootNode = factory.BuildFlow("TestFlow1");

            NodeResult result = await flowRootNode.ExecuteAsync(new TestObjectA());

            result.Status.ShouldEqual(NodeResultStatus.Succeeded);

            var subject = result.GetSubjectAs <TestObjectA>();

            subject.TestValueString.ShouldEqual("Hello JavaScript");
        }
        public static FlowDescription ExtractFrom([NotNull] Type type)
        {
            if (!typeof(Flow).IsAssignableFrom(type))
            {
                throw new InvalidOperationException("Type isn't a Flow");
            }

            var flow = (Flow)TypeUtils.CreateDefaultConstructorFactoryFor(type)();

            var buildMethod = type.GetMethod("Build", BindingFlags.Instance | BindingFlags.NonPublic);

            var flowBuilder = new FlowBuilder();

            buildMethod.Invoke(flow, new object[] { flowBuilder });

            return(flowBuilder.CreateFlow());
        }