Пример #1
0
        public void CastBaseTypeToDerivedType()
        {
            Variable <Base> operand = new Variable <Base>()
            {
                Name = "Operand"
            };
            Variable <Derived> result = new Variable <Derived>()
            {
                Name = "Derived"
            };
            Variable <string> output = new Variable <string>()
            {
                Name = "Output"
            };

            TestInvokeMethod invokeMethod = new TestInvokeMethod
            {
                TargetObjectVariable = result,
                MethodName           = "MethodInDerivedType"
            };

            invokeMethod.SetResultVariable <string>(output);

            //Base b = new Derived();
            //string result = ((Derived)b).MethodInDerivedType
            TestSequence seq = new TestSequence
            {
                Variables  = { operand, result, output },
                Activities =
                {
                    new TestAssign <Base> {
                        ToVariable = operand, ValueExpression = (context => new Derived())
                    },
                    new TestCast <Base, Derived>
                    {
                        OperandVariable = operand,
                        Result          = result
                    },
                    invokeMethod,
                    new TestWriteLine
                    {
                        MessageExpression = (e => output.Get(e)),
                        HintMessage       = "Ola"
                    }
                }
            };

            TestRuntime.RunAndValidateWorkflow(seq);
        }
Пример #2
0
        public void UseBaseTypeAsDerivedType()
        {
            Variable <Derived> result = new Variable <Derived>()
            {
                Name = "Result"
            };
            Variable <string> output = new Variable <string>()
            {
                Name = "Output"
            };

            TestInvokeMethod invokeMethod = new TestInvokeMethod
            {
                TargetObjectVariable = result,
                MethodName           = "MethodInDerivedType"
            };

            invokeMethod.SetResultVariable <string>(output);

            //Base b = new Derived();
            //string result = (b as Derived).MethodInDerivedType
            TestSequence seq = new TestSequence
            {
                Variables  = { result, output },
                Activities =
                {
                    new TestAs <Base, Derived>
                    {
                        OperandExpression = context => new Derived(),
                        Result            = result
                    },
                    invokeMethod,
                    new TestWriteLine
                    {
                        MessageExpression = (e => output.Get(e)),
                        HintMessage       = "Ola"
                    }
                }
            };

            TestRuntime.RunAndValidateWorkflow(seq);
        }