/// <summary> /// Add a switch activity /// </summary> public static Workflow AddSwitch(this Workflow wf, string name, string switchExpression, string[] exits, string fromNamed = null, string fromExit = null) { var act = new SwitchActivity() { Name = name }; var actAs = act.As <WfActivity>(); AddExpressionToActivityArgument(wf, actAs, "Value to Switch On", switchExpression); AddExits(act.ExitPoints, exits); wf.AddActivity(actAs, fromNamed, fromExit); AddMissingExpressionParametersToWorkflow(wf); return(wf); }
public async Task Test___Method_Start___Status_Created___Default_Completed() { var to = new AnyVariable(); var testee = new SwitchActivity() { Value = new AnyVariable <int>() { Value = 3 }, Cases = new Dictionary <object, IActivity>() { { 1, new AssignActivity() { To = to, Value = new AnyVariable() { Value = 100 } } }, { 2, new AssignActivity() { To = to, Value = new AnyVariable() { Value = 1000 } } } }, Default = new AssignActivity() { To = to, Value = new AnyVariable() { Value = 10000 } } }; await testee.Start(); Assert.AreEqual(ActivityStatus.Completed, testee.Status); Assert.AreEqual(10000, to.GetValue()); }
public async Task Test___Method_Start___Status_Created___Cases_Suspended() { var testee = new SwitchActivity() { Value = new AnyVariable <int>() { Value = 1 }, Cases = new Dictionary <object, IActivity>() { { 1, new SuspendActivity() { Until = new FalseCondition() } }, { 2, new NullActivity() } } }; await testee.Start(); Assert.AreEqual(ActivityStatus.Suspended, testee.Status); }
public async Task Test___Method_Stop___Status_Executing() { var to = new AnyVariable(); var testee = new SwitchActivity() { Value = new AnyVariable <int>() { Value = 1 }, Cases = new Dictionary <object, IActivity>() { { 1, new DelayActivity() { Duration = new AnyVariable <int>() { Value = 1000 } } }, { 2, new AssignActivity() { To = to, Value = new AnyVariable() { Value = 1000 } } } } }; var task = testee.Start(); Assert.AreEqual(ActivityStatus.Executing, testee.Status); testee.Stop(); await task; Assert.AreEqual(ActivityStatus.Stopped, testee.Status); }
public void Test___Method_Reset___Status_Stopped() { var to = new AnyVariable(); var testee = new SwitchActivity() { Value = new AnyVariable <int>() { Value = 1 }, Cases = new Dictionary <object, IActivity>() { { 1, new AssignActivity() { To = to, Value = new AnyVariable() { Value = 100 } } }, { 2, new AssignActivity() { To = to, Value = new AnyVariable() { Value = 1000 } } } } }; testee.Stop(); Assert.AreEqual(ActivityStatus.Stopped, testee.Status); Assert.IsNull(to.GetValue()); testee.Reset(); Assert.AreEqual(ActivityStatus.Created, testee.Status); }
public void SwitchTest( ) { var wf = new Workflow { Name = "ConnectingParameters Wf" }; var wfAs = wf.Cast <WfActivity>( ); wf.InputArguments.Add((new StringArgument { Name = "wfInString" }).Cast <ActivityArgument>( )); var wfYesExit = new ExitPoint { IsDefaultExitPoint = true, Name = "Wf Yes" }; var wfNoExit = new ExitPoint { Name = "Wf No" }; var wfMaybeExit = new ExitPoint { Name = "Wf Maybe" }; var wfDontKnowExit = new ExitPoint { Name = "Wf Dont know" }; wf.ExitPoints.Add(wfYesExit); wf.ExitPoints.Add(wfNoExit); wf.ExitPoints.Add(wfMaybeExit); wf.ExitPoints.Add(wfDontKnowExit); var switch1 = new SwitchActivity { Name = "Switch1" }; var switch1As = switch1.Cast <WfActivity>( ); ActivityTestHelper.AddFirstActivityWithMapping( wf, switch1As, null); ActivityTestHelper.CreateArgumentInstance(wf, wfAs, wfAs.GetInputArgument("wfInString")); ActivityTestHelper.AddExpressionToActivityArgument(wf, switch1As, "Value to Switch On", "wfInString", false); var switchYesExit = new ExitPoint { IsDefaultExitPoint = true, Name = "Yes" }; var switchNoExit = new ExitPoint { Name = "No" }; var switchMaybeExit = new ExitPoint { Name = "Maybe" }; switch1.ExitPoints.Add(switchYesExit); switch1.ExitPoints.Add(switchNoExit); switch1.ExitPoints.Add(switchMaybeExit); ActivityTestHelper.AddTermination( wf, switch1As, switchYesExit, wfYesExit); ActivityTestHelper.AddTermination( wf, switch1As, switchNoExit, wfNoExit); ActivityTestHelper.AddTermination( wf, switch1As, switchMaybeExit, wfMaybeExit); var otherwiseExit = Entity.Get <ExitPoint>(new EntityRef("core", "switchActivityOtherwiseExitPoint")); ActivityTestHelper.AddTermination( wf, switch1As, otherwiseExit, wfDontKnowExit); ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf); wf.Save( ); ToDelete.Add(wf.Id); ToDelete.Add(switch1.Id); TestResult(wf, "Yes", wfYesExit); TestResult(wf, "No", wfNoExit); TestResult(wf, "Maybe", wfMaybeExit); TestResult(wf, "Something else", wfDontKnowExit); }