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\""); }
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"); }
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)); }
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"); }
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); }
private static Type GetType(string typeName) { if (!TypeAbbreviationCache.TryGetType(typeName, out var retrievedType)) { retrievedType = Type.GetType(typeName); } return(retrievedType); }
private static string GetTypeName(Type type) { if (!TypeAbbreviationCache.TryGetName(type, out var retrievedName)) { retrievedName = type.AssemblyQualifiedName; } return(retrievedName); }
static JsonComponentSerializer() { TypeAbbreviationCache.RegisterCoreTypes(); _serializer = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore, ContractResolver = new JsonContractResolver() }; }
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); }
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); }
public WhenSerializingBasicFlow(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; TypeAbbreviationCache.Clear(); TypeAbbreviationCache.RegisterCoreTypes(); }