static async Task Main(string[] args) { var elapsed = new AnyVariable <long>(); var activity = new TryCatchActivity() { Try = new StopwatchActivity() { Activity = new DelayActivity(new AnyVariable <int>(10000)), Elapsed = elapsed }, Finally = new ConsoleWriteLineActivity() { Value = elapsed } }; // start Console.WriteLine("Press any key to start."); Console.ReadKey(); var task = activity.Start(); // stop Console.WriteLine("Press any key to stop."); Console.ReadKey(); activity.Stop(); await task; Console.ReadKey(); }
public async Task Test___Method_Stop___Status_Executing___Try() { var variable1 = new AnyVariable <int>() { Value = 0 }; var variable2 = new AnyVariable <int>() { Value = 10 }; var duration = new AnyVariable <int>() { Value = 1000 }; var testee = new TryCatchActivity() { Try = new DelayActivity() { Duration = duration }, Catch = new AssignActivity() { To = variable1, Value = new AnyVariable <int>() { Value = 30 } }, Finally = new AssignActivity() { To = variable2, Value = variable1 } }; using (var task = testee.Start()) { Assert.AreEqual(ActivityStatus.Executing, testee.Status); testee.Stop(); await task; } Assert.AreEqual(ActivityStatus.Completed, testee.Status); Assert.AreEqual(30, variable1.GetValueAsObject()); Assert.AreEqual(30, variable2.GetValueAsObject()); }
public async Task Test___Method_Reset___Status_Completed() { var variable1 = new AnyVariable <int>() { Value = 0 }; var variable2 = new AnyVariable <int>() { Value = 10 }; var testee = new TryCatchActivity() { Try = new AssignActivity() { To = variable1, Value = new AnyVariable <int>() { Value = 20 } }, Catch = new AssignActivity() { To = variable1, Value = new AnyVariable <int>() { Value = 30 } }, Finally = new AssignActivity() { To = variable2, Value = variable1 } }; await testee.Start(); Assert.AreEqual(ActivityStatus.Completed, testee.Status); Assert.AreEqual(20, variable1.GetValueAsObject()); Assert.AreEqual(20, variable2.GetValueAsObject()); testee.Reset(); Assert.AreEqual(ActivityStatus.Created, testee.Status); }
public async Task Test___Method_Stop___Status_Executing___Finally() { var variable1 = new AnyVariable <int>() { Value = 0 }; var duration = new AnyVariable <int>() { Value = 1000 }; var testee = new TryCatchActivity() { Try = new AssignActivity() { To = variable1, Value = new AnyVariable <int>() { Value = 20 } }, Catch = new NullActivity(), Finally = new DelayActivity() { Duration = duration } }; var task = testee.Start(); Assert.AreEqual(ActivityStatus.Executing, testee.Status); testee.Stop(); await task; Assert.AreEqual(ActivityStatus.Stopped, testee.Status); Assert.AreEqual(20, variable1.GetValueAsObject()); }