예제 #1
0
파일: Program.cs 프로젝트: np-albus/WFLite
        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();
        }
예제 #2
0
        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());
        }
예제 #3
0
        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);
        }
예제 #4
0
        public void Test___Method_Reset___Status_Stopped()
        {
            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
                }
            };

            testee.Stop();

            Assert.AreEqual(ActivityStatus.Stopped, testee.Status);

            testee.Reset();

            Assert.AreEqual(ActivityStatus.Created, testee.Status);
        }
예제 #5
0
        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());
        }