public void IsConnected_WorkflowWithTwoDoublyConnectedStates_ReturnTrue() { // Arrange var workflow = new IeWorkflow { States = new List <IeState> { new IeState { Name = "New", IsInitial = true }, new IeState { Name = "Done" } }, TransitionEvents = new List <IeTransitionEvent> { new IeTransitionEvent { FromState = "New", ToState = "Done" }, new IeTransitionEvent { FromState = "Done", ToState = "New" } } }; var graph = new WorkflowGraph(workflow); // Assert Assert.AreEqual(true, graph.IsConnected()); }
public void Construction_WorkflowTransitionWithoutToState_ThrowsArgumentException() { // Arrange var workflow = new IeWorkflow { States = new List <IeState> { new IeState { Name = "New" } }, TransitionEvents = new List <IeTransitionEvent> { new IeTransitionEvent { FromState = "New" } } }; try { // Act var graph = new WorkflowGraph(workflow); } catch (ArgumentException ex) { // Assert Assert.IsNotNull(ex); return; } Assert.Fail("Expected ArgumentException to have been thrown."); }
public void IsConnected_ComplexConnectedWorkflow_ReturnsTrue() { // Arrange var workflow = new IeWorkflow { States = new List <IeState> { new IeState { Name = "New", IsInitial = true }, new IeState { Name = "Ready" }, new IeState { Name = "In Progress" }, new IeState { Name = "On Hold" }, new IeState { Name = "Done" } }, TransitionEvents = new List <IeTransitionEvent> { new IeTransitionEvent { FromState = "New", ToState = "Ready" }, new IeTransitionEvent { FromState = "Ready", ToState = "In Progress" }, new IeTransitionEvent { FromState = "In Progress", ToState = "On Hold" }, new IeTransitionEvent { FromState = "On Hold", ToState = "In Progress" }, new IeTransitionEvent { FromState = "In Progress", ToState = "Done" } } }; var graph = new WorkflowGraph(workflow); // Assert Assert.AreEqual(true, graph.IsConnected()); }
public void IsConnected_WorkflowWithInitialState_ReturnTrue() { // Arrange var workflow = new IeWorkflow { States = new List <IeState> { new IeState { Name = "New", IsInitial = true } }, TransitionEvents = new List <IeTransitionEvent>() }; var graph = new WorkflowGraph(workflow); // Assert Assert.AreEqual(true, graph.IsConnected()); }
public void Construction_WorkflowWithoutStates_ThrowsArgumentNullException() { // Arrange var workflow = new IeWorkflow(); try { // Act new WorkflowGraph(workflow); } catch (ArgumentNullException ex) { // Assert Assert.AreEqual(nameof(workflow.States), ex.ParamName); return; } Assert.Fail("Expected ArgumentNullException to have been thrown."); }
public void Construction_NullWorkflow_ThrowsArgumentNullException() { // Arrange IeWorkflow workflow = null; try { // Act new WorkflowGraph(workflow); } catch (ArgumentNullException ex) { // Assert Assert.AreEqual(nameof(workflow), ex.ParamName); return; } Assert.Fail("Expected ArgumentNullException to have been thrown."); }
public void IsConnected_WorkflowWithTwoDisconnectedStates_ReturnFalse() { // Arrange var workflow = new IeWorkflow { States = new List <IeState> { new IeState { Name = "New", IsInitial = true }, new IeState { Name = "Done" } }, TransitionEvents = new List <IeTransitionEvent>() }; var graph = new WorkflowGraph(workflow); // Assert Assert.AreEqual(false, graph.IsConnected()); }
public void Construction_WorkflowStateWithoutName_ThrowsArgumentException() { // Arrange var workflow = new IeWorkflow { States = new List <IeState> { new IeState() } }; try { // Act new WorkflowGraph(workflow); } catch (ArgumentException ex) { // Assert Assert.IsNotNull(ex); return; } Assert.Fail("Expected ArgumentException to have been thrown."); }
protected bool Equals(IeWorkflow other) { return(Id.GetValueOrDefault() == other.Id.GetValueOrDefault() && string.Equals(Name, other.Name) && string.Equals(Description, other.Description) && IsActive == other.IsActive && WorkflowHelper.CollectionEquals(States, other.States) && WorkflowHelper.CollectionEquals(TransitionEvents, other.TransitionEvents) && WorkflowHelper.CollectionEquals(PropertyChangeEvents, other.PropertyChangeEvents) && WorkflowHelper.CollectionEquals(NewArtifactEvents, other.NewArtifactEvents) && WorkflowHelper.CollectionEquals(Projects, other.Projects)); }
public WorkflowGraph(IeWorkflow workflow) { if (workflow == null) { throw new ArgumentNullException(nameof(workflow)); } if (workflow.States == null) { throw new ArgumentNullException(nameof(workflow.States)); } if (workflow.TransitionEvents == null) { throw new ArgumentNullException(nameof(workflow.TransitionEvents)); } _nodesByName = new Dictionary <string, WorkflowGraphNode>(); foreach (var state in workflow.States) { if (string.IsNullOrWhiteSpace(state.Name)) { throw new ArgumentException(StateHasNoNameError); } var node = new WorkflowGraphNode(state); _nodesByName[state.Name] = node; if (node.IsInitial) { _initialNode = node; } } if (_initialNode == null) { throw new ArgumentException(NoInitialStateError); } foreach (var transition in workflow.TransitionEvents) { if (string.IsNullOrWhiteSpace(transition.FromState)) { throw new ArgumentException(TransitionHasNoFromStateError); } if (string.IsNullOrWhiteSpace(transition.ToState)) { throw new ArgumentException(TransitionHasNoToStateError); } WorkflowGraphNode fromNode; WorkflowGraphNode toNode; if (_nodesByName.TryGetValue(transition.FromState, out fromNode) && _nodesByName.TryGetValue(transition.ToState, out toNode)) { fromNode.AddNextNode(toNode); } } }