Ejemplo n.º 1
0
        public void SwitchDefault()
        {
            //  SwitchDefaultSimple switch case default
            //  Test case description:
            //  Simple switch case default
            TestSwitch <int> switchAct        = new TestSwitch <int>();
            Variable <int>   switchExpression = new Variable <int>("switchExpression", 444);
            TestSequence     seq = new TestSequence();

            seq.Variables.Add(switchExpression);

            switchAct.ExpressionVariable = switchExpression;
            switchAct.AddCase(12, new TestProductWriteline {
                Text = "in case 12"
            });
            switchAct.AddCase(23, new TestProductWriteline {
                Text = "in case 23"
            });
            switchAct.AddCase(123, new TestProductWriteline {
                Text = "in case 123"
            });
            switchAct.AddCase(234, new TestProductWriteline {
                Text = "in case 234"
            });
            switchAct.Default = new TestProductWriteline {
                Text = "in default"
            };

            switchAct.Hints.Add(-1);
            seq.Activities.Add(switchAct);
            TestRuntime.RunAndValidateWorkflow(seq);
        }
Ejemplo n.º 2
0
        public void SwitchStandAlone()
        {
            //  SwitchNoDefaultSimple switch case scenario
            //  Test case description:
            //  Simple switch case scenario

            TestSwitch <int> switchAct = new TestSwitch <int>
            {
                DisplayName = "standAloneSwitch",
                Expression  = 23
            };

            switchAct.AddCase(12, new TestProductWriteline {
                Text = "in case 12"
            });
            switchAct.AddCase(23, new TestProductWriteline {
                Text = "in case 23"
            });
            switchAct.AddCase(123, new TestProductWriteline {
                Text = "in case 123"
            });
            switchAct.AddCase(234, new TestProductWriteline {
                Text = "in case 234"
            });

            switchAct.Hints.Add(1);
            TestRuntime.RunAndValidateWorkflow(switchAct);
        }
Ejemplo n.º 3
0
        public void SwitchWithEmptyCase()
        {
            TestSwitch <string> switchAct = new TestSwitch <string>();

            switchAct.AddCase("12", new TestProductWriteline {
                Text = "in case 12"
            });
            switchAct.AddCase("", new TestProductWriteline {
                Text = "in case 12"
            });
            switchAct.Hints.Add(1);
            switchAct.Expression = "";
            TestRuntime.RunAndValidateWorkflow(switchAct);
        }
Ejemplo n.º 4
0
        public void ThrowExcInCaseWhichWontExecute()
        {
            TestSwitch <float> switchAct = new TestSwitch <float>();

            switchAct.AddCase(345678, new TestWriteLine("Writeline")
            {
                Message = "345678"
            });
            switchAct.AddCase(123, new TestThrow <InvalidCastException>("Throw invalid cast"));
            switchAct.Expression = 345678;
            switchAct.Hints.Add(0);

            TestRuntime.RunAndValidateWorkflow(switchAct);
        }
Ejemplo n.º 5
0
        public void CompositeProcedurals()
        {
            Variable <bool> cond = new Variable <bool> {
                Default = true
            };
            Variable <string> value = new Variable <string> {
                Default = "Apple"
            };
            DelegateInArgument <string> arg = new DelegateInArgument <string> {
                Name = "Apple"
            };

            string[] values = { "a", "b" };

            TestSwitch <string> switchAct = new TestSwitch <string>
            {
                ExpressionVariable = value
            };

            switchAct.AddCase("Apple", new TestWriteLine("Apple", "this is an apple"));
            switchAct.AddCase("Orange", new TestWriteLine("Orange", "this is an orange"));
            switchAct.Hints.Add(0);

            TestIf ifAct = new TestIf(HintThenOrElse.Then)
            {
                ConditionVariable = cond,
                ThenActivity      = new TestWriteLine("W", "Yes thats true"),
                ElseActivity      = new TestWriteLine("W", "No thats not true")
            };

            TestForEach <string> forEachAct = new TestForEach <string>
            {
                Values             = values,
                CurrentVariable    = arg,
                HintIterationCount = 2,
                Body = new TestWriteLine {
                    DisplayName = "w1", MessageExpression = context => arg.Get(context), HintMessageList = { "a", "b" }
                }
            };

            TestSequence seq = new TestSequence
            {
                Variables  = { cond, value },
                Activities = { switchAct, ifAct, forEachAct }
            };

            TestRuntime.RunAndValidateWorkflow(seq);
        }
Ejemplo n.º 6
0
        public void SwitchWithEnums()
        {
            TestSwitch <OrderStatus> order = new TestSwitch <OrderStatus>();

            order.AddCase(OrderStatus.NewOrder, new TestWriteLine("We have received a new order")
            {
                Message = "New Order"
            });
            order.AddCase(OrderStatus.Processing, new TestWriteLine("Order is in processing state")
            {
                Message = "Processing"
            });
            order.AddCase(OrderStatus.Shipped, new TestSequence {
                Activities = { new TestWriteLine("Order is shipped to you")
                               {
                                   Message = "Order shipped"
                               } }
            });
            order.Hints.Add(0);
            order.Hints.Add(1);
            order.Hints.Add(2);

            List <OrderStatus> values = new List <OrderStatus>()
            {
                OrderStatus.NewOrder, OrderStatus.Processing, OrderStatus.Shipped
            };
            DelegateInArgument <OrderStatus> var = new DelegateInArgument <OrderStatus> {
                Name = "var"
            };

            TestForEach <OrderStatus> forEachAct = new TestForEach <OrderStatus>("ForEachAct")
            {
                Values          = values,
                CurrentVariable = var
            };
            TestSequence seq = new TestSequence("Seq in For Each");

            seq.Activities.Add(order);
            forEachAct.Body            = seq;
            order.ExpressionExpression = (env) => (OrderStatus)var.Get(env);

            forEachAct.HintIterationCount = 3;

            TestRuntime.RunAndValidateWorkflow(forEachAct);
        }
Ejemplo n.º 7
0
        public void SwitchWithNoExpressionSet()
        {
            TestSwitch <string> switchAct = new TestSwitch <string>();

            switchAct.Hints.Add(-1);
            switchAct.AddCase("1", new TestProductWriteline {
                Text = "in case 1"
            });
            ((CoreWf.Statements.Switch <string>)switchAct.ProductActivity).Expression = null;

            string exceptionMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Expression");

            TestRuntime.ValidateWorkflowErrors(switchAct, new List <TestConstraintViolation>(), typeof(ArgumentException), exceptionMessage);
        }
Ejemplo n.º 8
0
        public void SwitchWithWorkflowInvoker()
        {
            TestSwitch <int> switchAct = new TestSwitch <int>();

            switchAct.AddCase(12, new TestProductWriteline {
                Text = "in case 12"
            });
            switchAct.AddCase(23, new TestProductWriteline {
                Text = "in case 23"
            });
            switchAct.AddCase(123, new TestProductWriteline {
                Text = "in case 123"
            });
            switchAct.AddCase(234, new TestProductWriteline {
                Text = "in case 234"
            });
            switchAct.Hints.Add(2);

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("Expression", 123);
            TestRuntime.RunAndValidateUsingWorkflowInvoker(switchAct, dic, null, null);
        }
Ejemplo n.º 9
0
        public void SwitchEvaluatingNullCase()
        {
            TestSwitch <string> sw = new TestSwitch <string>();
            string s = null;

            sw.AddCase(null, new TestWriteLine()
            {
                Message = "Hi"
            });
            sw.Hints.Add(0);
            sw.Expression = s;

            TestRuntime.RunAndValidateWorkflow(sw);
        }
Ejemplo n.º 10
0
        public void ThrowExceptionInCase()
        {
            TestSwitch <float> switchAct = new TestSwitch <float>();

            switchAct.DisplayName = "Switch Act";
            switchAct.AddCase(123, new TestThrow <InvalidCastException>("THrow invalid cast")
            {
                ExpectedOutcome = Outcome.UncaughtException(typeof(InvalidCastException))
            });
            switchAct.Expression = 123;
            switchAct.Hints.Add(0);

            TestRuntime.RunAndValidateAbortedException(switchAct, typeof(InvalidCastException), new Dictionary <string, string>());
        }
Ejemplo n.º 11
0
        public void ThrowWithCaseInfinity()
        {
            TestSwitch <float> switchAct = new TestSwitch <float>();
            Variable <float>   temp      = VariableHelper.CreateInitialized <float>("temp", 3);
            float        temp1           = 1;
            float        temp2           = 0;
            TestSequence seq             = new TestSequence();

            seq.Activities.Add(switchAct);
            seq.Variables.Add(temp);

            switchAct.AddCase(123, new TestWriteLine("Seq")
            {
                Message = ""
            });
            switchAct.AddCase(temp1 / temp2, new TestWriteLine()
            {
                Message = "Infinity is the value"
            });
            switchAct.ExpressionExpression = (env) => (float)(1 / (temp.Get(env) - 3));
            switchAct.Hints.Add(1);

            TestRuntime.RunAndValidateWorkflow(seq);
        }
Ejemplo n.º 12
0
        public void SwitchThrowInDefault()
        {
            TestSwitch <float> switchAct = new TestSwitch <float>();

            switchAct.AddCase(123, new TestThrow <InvalidCastException>("Throw invalid cast")
            {
                ExpectedOutcome = Outcome.None
            });
            switchAct.Default = new TestThrow <TestCaseException>("Op cancelled")
            {
                ExpectedOutcome = Outcome.UncaughtException(typeof(TestCaseException))
            };
            switchAct.Expression = 456;
            switchAct.Hints.Add(-1);
            TestRuntime.RunAndValidateAbortedException(switchAct, typeof(TestCaseException), new Dictionary <string, string>());
        }
Ejemplo n.º 13
0
        public void ThrowExceptionInExpression()
        {
            TestSwitch <int> switchAct = new TestSwitch <int>();
            Variable <int>   temp      = VariableHelper.CreateInitialized <int>("temp", 3);
            TestSequence     seq       = new TestSequence();

            seq.Activities.Add(switchAct);
            seq.Variables.Add(temp);

            switchAct.AddCase(123, new TestSequence("Seq"));
            switchAct.ExpressionExpression = (env) => (int)(1 / (temp.Get(env) - 3));
            switchAct.Hints.Add(-1);
            switchAct.ExpectedOutcome = Outcome.UncaughtException(typeof(DivideByZeroException));

            TestRuntime.RunAndValidateAbortedException(seq, typeof(DivideByZeroException), new Dictionary <string, string>());
        }
Ejemplo n.º 14
0
        public void DifferentArguments()
        {
            //Testing Different argument types for Switch.Expression
            // DelegateInArgument
            // DelegateOutArgument
            // Activity<T>
            // Variable<T> , Activity<T> and Expression is already implemented.

            DelegateInArgument <string>  delegateInArgument  = new DelegateInArgument <string>("Input");
            DelegateOutArgument <string> delegateOutArgument = new DelegateOutArgument <string>("Output");

            TestCustomActivity <InvokeFunc <string, string> > invokeFunc = TestCustomActivity <InvokeFunc <string, string> > .CreateFromProduct(
                new InvokeFunc <string, string>
            {
                Argument = "PassedInValue",
                Func     = new ActivityFunc <string, string>
                {
                    Argument = delegateInArgument,
                    Result   = delegateOutArgument,
                    Handler  = new CoreWf.Statements.Sequence
                    {
                        DisplayName = "Sequence1",
                        Activities  =
                        {
                            new CoreWf.Statements.Switch <string>
                            {
                                DisplayName = "Switch1",
                                Expression  = delegateInArgument,
                                Cases       =
                                {
                                    {
                                        "PassedInValue",
                                        new CoreWf.Statements.Assign <string>
                                        {
                                            DisplayName = "Assign1",
                                            To          = delegateOutArgument,
                                            Value       = "OutValue",
                                        }
                                    },
                                },
                                Default = new Test.Common.TestObjects.CustomActivities.WriteLine{
                                    DisplayName = "W1", Message = "This should not be printed"
                                },
                            },
                            new CoreWf.Statements.Switch <string>
                            {
                                DisplayName = "Switch2",
                                Expression  = delegateOutArgument,
                                Cases       =
                                {
                                    {
                                        "OutValue",
                                        new Test.Common.TestObjects.CustomActivities.WriteLine {
                                            DisplayName = "W2", Message = delegateOutArgument
                                        }
                                    }
                                },
                                Default = new Test.Common.TestObjects.CustomActivities.WriteLine{
                                    DisplayName = "W3", Message = "This should not be printed"
                                },
                            }
                        }
                    }
                }
            }
                );

            TestSwitch <string> switch1 = new TestSwitch <string>
            {
                DisplayName = "Switch1",
                Hints       = { 0 }
            };

            switch1.AddCase("PassedInValue", new TestAssign <string> {
                DisplayName = "Assign1"
            });
            switch1.Default = new TestWriteLine {
                DisplayName = "W1"
            };

            TestSwitch <string> switch2 = new TestSwitch <string>
            {
                DisplayName = "Switch2",
                Hints       = { 0 }
            };

            switch2.AddCase("OutValue", new TestWriteLine {
                DisplayName = "W2", HintMessage = "OutValue"
            });
            switch2.Default = new TestWriteLine {
                DisplayName = "W3"
            };

            TestSequence sequenceForTracing = new TestSequence
            {
                DisplayName = "Sequence1",
                Activities  =
                {
                    switch1,
                    switch2,
                }
            };

            invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace);

            TestRuntime.RunAndValidateWorkflow(invokeFunc);
        }