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