コード例 #1
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\"");
        }
コード例 #2
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");
        }
コード例 #3
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));
        }
コード例 #4
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");
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: TypeJsonConverter.cs プロジェクト: sambsp/Banzai
        private static Type GetType(string typeName)
        {
            if (!TypeAbbreviationCache.TryGetType(typeName, out var retrievedType))
            {
                retrievedType = Type.GetType(typeName);
            }

            return(retrievedType);
        }
コード例 #7
0
ファイル: TypeJsonConverter.cs プロジェクト: sambsp/Banzai
        private static string GetTypeName(Type type)
        {
            if (!TypeAbbreviationCache.TryGetName(type, out var retrievedName))
            {
                retrievedName = type.AssemblyQualifiedName;
            }

            return(retrievedName);
        }
コード例 #8
0
        static JsonComponentSerializer()
        {
            TypeAbbreviationCache.RegisterCoreTypes();

            _serializer = new JsonSerializer
            {
                NullValueHandling    = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Ignore,
                ContractResolver     = new JsonContractResolver()
            };
        }
コード例 #9
0
        public async void Deserialized_Flow_Component_Can_Be_Built_And_Run()
        {
            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();

            string definition = serializer.Serialize(rootComponent);

            Console.WriteLine(definition);

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

            flowBuilder.RootComponent = deserializedComponent;

            flowBuilder.Register();

            var container = containerBuilder.Build();

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

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

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

            result.Status.ShouldEqual(NodeResultStatus.Succeeded);
        }
コード例 #10
0
        public async Task Deserialized_Flow_Component_With_ShouldExecuteBlock_Can_Be_Built_And_Attempted()
        {
            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("TestFlowDeserializeShouldExecute")
            .AddRoot <IPipelineNode <object> >().SetShouldExecuteBlock <ShouldNotExecuteTestBlock>()
            .AddChild <ITestNode2>();

            var rootComponent = flowBuilder.RootComponent;

            var serializer = new JsonComponentSerializer();

            var definition = serializer.Serialize(rootComponent);

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

            flowBuilder.RootComponent = deserializedComponent;

            flowBuilder.Register();

            var container = containerBuilder.Build();

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

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

            var result = await flowRootNode.ExecuteAsync(new object());

            result.Status.Should().Be(NodeResultStatus.NotRun);
        }
コード例 #11
0
 public WhenSerializingBasicFlow(ITestOutputHelper testOutputHelper)
 {
     _testOutputHelper = testOutputHelper;
     TypeAbbreviationCache.Clear();
     TypeAbbreviationCache.RegisterCoreTypes();
 }