Ejemplo n.º 1
0
        public async Task <IActionResult> Get([FromQuery(Name = "condition")] bool condition = true)  // false: Not Found
        {
            var actionResult = new AnyVariable <IActionResult>();

            var activity = new IfActivity()
            {
                Condition = new TrueCondition()
                {
                    Value = new AnyVariable <bool>()
                    {
                        Value = condition
                    }
                },
                Then = new AssignActivity()
                {
                    To    = actionResult,
                    Value = new OkObjectResultVariable()
                    {
                        Value = new AnyVariable()
                        {
                            Value = "Hello World!"
                        }
                    }
                },
                Else = new AssignActivity()
                {
                    To    = actionResult,
                    Value = new NotFoundResultVariable()
                }
            };

            await activity.Start();

            return(actionResult.GetValue());
        }
Ejemplo n.º 2
0
        public void Test___Method_Stop___Status_Created()
        {
            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());
        }
Ejemplo n.º 3
0
        public async Task Test___Method_Start___Status_Created___Cases___Generic()
        {
            var to = new AnyVariable();

            var testee = new SwitchActivity <int>()
            {
                Value = new AnyVariable <int>()
                {
                    Value = 1
                },
                Cases = new Dictionary <int, IActivity>()
                {
                    { 1, new AssignActivity()
                      {
                          To = to, Value = new AnyVariable()
                          {
                              Value = 100
                          }
                      } },
                    { 2, new AssignActivity()
                      {
                          To = to, Value = new AnyVariable()
                          {
                              Value = 1000
                          }
                      } }
                }
            };

            await testee.Start();

            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
            Assert.AreEqual(100, to.GetValue());
        }
Ejemplo n.º 4
0
        public void Test___Method_Reset___Status_Stopped()
        {
            var elapsed = new AnyVariable <long>()
            {
                Value = 0
            };

            var testee = new StopwatchActivity()
            {
                Activity = new DelayActivity()
                {
                    Duration = new AnyVariable <int>()
                    {
                        Value = 1000
                    }
                },
                Elapsed = elapsed
            };

            testee.Stop();

            Assert.AreEqual(ActivityStatus.Stopped, testee.Status);
            Assert.AreEqual(0L, elapsed.GetValue());

            testee.Reset();

            Assert.AreEqual(ActivityStatus.Created, testee.Status);
        }
Ejemplo n.º 5
0
        public async Task Test___Method_Start___Encoding_UTF8()
        {
            var path = Path.Combine(Path.GetTempPath(), GetType().Name, "foo.txt");

            File.WriteAllText(path, "bar");

            var contents = new AnyVariable <string>();

            var testee = new FileReadAllTextActivity()
            {
                Path = new AnyVariable <string>()
                {
                    Value = path
                },
                Contents = contents,
                Encoding = new AnyVariable <Encoding>()
                {
                    Value = Encoding.UTF8
                }
            };

            await testee.Start();

            Assert.AreEqual("bar", contents.GetValue());
            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
        }
Ejemplo n.º 6
0
        public void Test___Method_GetValue___Generic_Method___enum_to_int()
        {
            var testee = new AnyVariable <ActivityStatus>()
            {
                Value = ActivityStatus.Created
            };

            Assert.AreEqual(0, testee.GetValue <int>());
        }
Ejemplo n.º 7
0
        public void Test___Method_GetValue___Generic_Method___int_to_string()
        {
            var testee = new AnyVariable <int>()
            {
                Value = 10
            };

            Assert.AreEqual("10", testee.GetValue <string>());
        }
Ejemplo n.º 8
0
        public async Task Test___Method_ToActivity___async()
        {
            var value = new AnyVariable <int>();

            var testee = new Func <CancellationToken, Task <bool> >(async(cancellationToken) =>
            {
                value.SetValue(10);
                return(await Task.FromResult(true));
            });

            await testee.ToActivity().Start();

            Assert.AreEqual(10, value.GetValue());
        }
Ejemplo n.º 9
0
        public async Task Test___Method_ToActivity___sync()
        {
            var value = new AnyVariable <int>();

            var testee = new Func <bool>(() =>
            {
                value.SetValue(10);
                return(true);
            });

            await testee.ToActivity().Start();

            Assert.AreEqual(10, value.GetValue());
        }
Ejemplo n.º 10
0
        public async Task Test___Method_Start()
        {
            var path = Path.Combine(Path.GetTempPath(), GetType().Name, "foo.txt");

            File.WriteAllLines(path, new string[] { "bar", "baz" });

            var contents = new AnyVariable <string[]>();

            var testee = new FileReadAllLinesActivity()
            {
                Path = new AnyVariable <string>()
                {
                    Value = path
                },
                Contents = contents
            };

            await testee.Start();

            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
            Assert.AreEqual("bar", contents.GetValue()[0]);
            Assert.AreEqual("baz", contents.GetValue()[1]);
        }
Ejemplo n.º 11
0
        public async Task Test___Method_Start()
        {
            var exitCode = new AnyVariable <int>();

            var testee = new ProcessExecuteActivity()
            {
                StartInfo = new ProcessStartInfoVariable()
                {
                    FileName        = new AnyVariable <string>("cmd.exe"),
                    Arguments       = new AnyVariable <string>("/Ccd"),
                    CreateNoWindow  = new AnyVariable <bool>(true),
                    UseShellExecute = new AnyVariable <bool>(false)
                },
                ExitCode = exitCode
            };

            await testee.Start();

            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
            Assert.AreEqual(0, exitCode.GetValue());
        }
Ejemplo n.º 12
0
        public async Task Test___Method_Start()
        {
            var path = Path.Combine(Path.GetTempPath(), GetType().Name, "foo.txt");

            File.WriteAllBytes(path, Encoding.UTF8.GetBytes("bar"));

            var bytes = new AnyVariable <byte[]>();

            var testee = new FileReadAllBytesActivity()
            {
                Path = new AnyVariable <string>()
                {
                    Value = path
                },
                Bytes = bytes
            };

            await testee.Start();

            Assert.AreEqual("bar", Encoding.UTF8.GetString(bytes.GetValue()));
            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
        }
Ejemplo n.º 13
0
        public async Task Test___Method_Start___Status_Created___Generic()
        {
            var to = new AnyVariable <int>()
            {
                Value = 0
            };
            var value = new AnyVariable <int>()
            {
                Value = 10
            };

            var testee = new AssignActivity <int>()
            {
                To    = to,
                Value = value
            };

            await testee.Start();

            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
            Assert.AreEqual(10, to.GetValue());
        }
Ejemplo n.º 14
0
        public async Task Test___Method_Start()
        {
            var elapsed    = new AnyVariable <long>();
            var lockObject = new LockVariable();

            var testee = new StopwatchActivity()
            {
                Elapsed  = elapsed,
                Activity = new ParallelActivity()
                {
                    Activities = new List <IActivity>()
                    {
                        new LockActivity()
                        {
                            LockObject = lockObject,
                            Activity   = new DelayActivity()
                            {
                                Duration = new AnyVariable <int>(1000)
                            }
                        },
                        new LockActivity()
                        {
                            LockObject = lockObject,
                            Activity   = new DelayActivity()
                            {
                                Duration = new AnyVariable <int>(1000)
                            }
                        }
                    }
                }
            };

            await testee.Start();

            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
            Assert.IsTrue(2000 <= elapsed.GetValue());
        }
Ejemplo n.º 15
0
        public async Task Test___Method_Start___Status_Created()
        {
            var elapsed = new AnyVariable <long>()
            {
                Value = 0
            };

            var testee = new StopwatchActivity()
            {
                Activity = new DelayActivity()
                {
                    Duration = new AnyVariable <int>()
                    {
                        Value = 1000
                    }
                },
                Elapsed = elapsed
            };

            await testee.Start();

            Assert.AreEqual(ActivityStatus.Completed, testee.Status);
            Assert.AreNotEqual(0L, elapsed.GetValue());
        }