public void AddsNestedWorkflow() { var model = new WorkflowDefinitionModel(); model.Nodes.Add(new NodeModel { Identifier = "node", OutgoingTransitions = new[] { new TransitionModel { Identifier = "transitionId", Source = "node", Destination = "nested" } } }); model.Nodes.Add(new WorkflowDefinitionModel { Identifier = "nested", OperationType = typeof (TakeDefaultTransitionOperation).AssemblyQualifiedName }); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); var nestedWorkflow = definition.Nodes.FirstOrDefault(n => n.Identifier == "nested"); Assert.That(nestedWorkflow, Is.Not.Null); Assert.That(nestedWorkflow, Is.InstanceOf<IWorkflowDefinition>()); }
public void AddsIncomingTransitionOnNode() { var model = new WorkflowDefinitionModel(); model.Nodes.Add(new NodeModel { Identifier = "node", OutgoingTransitions = new[] { new TransitionModel { Identifier = "transitionId", Source = "node", Destination = "destNode" } } }); model.Nodes.Add(new NodeModel { Identifier = "destNode" }); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); var destNode = definition.Nodes.First(n => n.Identifier == "destNode"); Assert.That(destNode.IncomingTransitions.Count(), Is.EqualTo(1)); var transition = destNode.IncomingTransitions.First(); Assert.That(transition.Identifier, Is.EqualTo("transitionId")); Assert.That(transition.Source.Identifier, Is.EqualTo("node")); }
public WorkflowDefinitionModel Transform(IWorkflowDefinition workflowDefinition) { var workflowDefinitionModel = new WorkflowDefinitionModel { Identifier = workflowDefinition.Identifier, OperationType = workflowDefinition.Operation.AssemblyQualifiedName }; foreach (var node in workflowDefinition.Nodes) { NodeModel nodeModel = CreateNode(workflowDefinition, (dynamic) node); workflowDefinitionModel.Nodes.Add(nodeModel); } return workflowDefinitionModel; }
public void SetsWorkflowIdentifier() { var model = new WorkflowDefinitionModel {Identifier = "identifier"}; model.Nodes.Add(new NodeModel { Identifier = "node" }); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); Assert.That(definition.Identifier, Is.EqualTo("identifier")); }
public void SetsStartNodePropertyOnNode() { var model = new WorkflowDefinitionModel(); model.Nodes.Add(new NodeModel { Identifier = "node", IsInitialNode = true }); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); var node = definition.Nodes.First(); Assert.That(definition.InitialNode, Is.EqualTo(node)); }
public void SetsDefaultPropertyOnTransition() { var model = new WorkflowDefinitionModel(); model.Nodes.Add(new NodeModel { Identifier = "node", OutgoingTransitions = new[] { new TransitionModel { Identifier = "transitionId", IsDefault = true, Source = "node", Destination = "destNode" } } }); model.Nodes.Add(new NodeModel { Identifier = "destNode" }); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); var transition = definition.Nodes.First(n => n.Identifier == "node").OutgoingTransitions.First(); Assert.That(transition.IsDefault); }
public void ReturnsEmptyWorkflowDefinitionIfModelIsEmpty() { var model = new WorkflowDefinitionModel(); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); Assert.That(definition, Is.Not.Null); Assert.That(definition.Nodes, Is.Empty); Assert.That(definition.OutgoingTransitions, Is.Empty); Assert.That(definition.IncomingTransitions, Is.Empty); }
public void AddsOperationToNode() { var model = new WorkflowDefinitionModel(); model.Nodes.Add(new NodeModel { Identifier = "node", OperationType = typeof (TestOperation).AssemblyQualifiedName }); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); Assert.That(definition.Nodes.First().Operation, Is.EqualTo(typeof (TestOperation))); }
public void AddsNode() { var model = new WorkflowDefinitionModel(); model.Nodes.Add(new NodeModel { Identifier = "node" }); var transformer = new Transform.WorkflowDefinitionTransformer(); IWorkflowDefinition definition = transformer.TransformBack(model); Assert.That(definition.Nodes.Count, Is.EqualTo(1)); Assert.That(definition.Nodes.First().Identifier, Is.EqualTo("node")); }
private WorkflowDefinitionBuilder BuildWorkflowDefinition(WorkflowDefinitionBuilder builder, WorkflowDefinitionModel model) { builder.WithIdentifier(model.Identifier); foreach (var node in model.Nodes) { NodeBuilder nodeBuilder = builder.AddNode() .WithName(node.Identifier); if (node.OperationType != null) { nodeBuilder.WithOperation(Type.GetType(node.OperationType)); } if (node.IsInitialNode) { nodeBuilder.IsStartNode(); } if (node.IsEndNode) { nodeBuilder.IsEndNode(); } foreach (var transition in node.OutgoingTransitions) { TransitionBuilder transitionBuilder = nodeBuilder.AddTransition() .WithName(transition.Identifier) .To(transition.Destination); if (transition.IsDefault) { transitionBuilder.IsDefault(); } transitionBuilder.BuildTransition(); } BuildNode(builder, nodeBuilder, (dynamic) node); } return builder; }
public IWorkflowDefinition TransformBack(WorkflowDefinitionModel model) { var builder = new WorkflowDefinitionBuilder(); return BuildWorkflowDefinition(builder, model).BuildWorkflow(); }
private void BuildNode(WorkflowDefinitionBuilder workflowBuilder, NodeBuilder nodeBuilder, WorkflowDefinitionModel node) { nodeBuilder.BuildSubWorkflow(BuildWorkflowDefinition(workflowBuilder, node)); }