public void PassEnumTypeAsOperand()
        {
            Variable <WeekDay> weekDayVariable         = new Variable <WeekDay>("weekDayVariable");
            TestFieldReference <WeekDay, int> fieldRef = new TestFieldReference <WeekDay, int>
            {
                OperandVariable = weekDayVariable,
                FieldName       = "Monday"
            };
            TestSequence testSequence = new TestSequence
            {
                Variables =
                {
                    weekDayVariable,
                },
                Activities =
                {
                    new TestAssign <WeekDay> {
                        ToVariable = weekDayVariable, ValueExpression = (context => WeekDay.Monday)
                    },
                    fieldRef,
                }
            };

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(
                                string.Format(ErrorStrings.TargetTypeCannotBeEnum, typeof(FieldReference <WeekDay, int>).Name, fieldRef.DisplayName),
                                fieldRef.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(testSequence, constraints, string.Format(ErrorStrings.TargetTypeCannotBeEnum, typeof(FieldReference <WeekDay, int>).Name, fieldRef.DisplayName));
        }
        public void TrySettingValueOfFieldNameNull()
        {
            Variable <PublicType> publicTypeVariable      = new Variable <PublicType>("publicTypeVariable");
            TestFieldReference <PublicType, int> fieldRef = new TestFieldReference <PublicType, int> {
                OperandVariable = publicTypeVariable
            };
            TestSequence testSequence = new TestSequence
            {
                Variables =
                {
                    publicTypeVariable,
                },
                Activities =
                {
                    new TestAssign <PublicType> {
                        ToVariable = publicTypeVariable, ValueExpression = (context => new PublicType())
                    },
                    fieldRef
                }
            };

            string exceptionString = string.Format(ErrorStrings.ActivityPropertyMustBeSet, "FieldName", fieldRef.DisplayName);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(
                    exceptionString,
                    fieldRef.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(testSequence, constraints, exceptionString);
        }
        public void SetStaticFieldOnAStruct()
        {
            TestFieldReference <TheStruct, int> fieldReference = new TestFieldReference <TheStruct, int> {
                FieldName = "staticField"
            };

            TestSequence seq = new TestSequence
            {
                Activities =
                {
                    new TestAssign <int> {
                        ToLocation = fieldReference, Value = 22
                    },
                    new TestWriteLine    {
                        MessageExpression = e => TheStruct.staticField.ToString(), HintMessage = "22"
                    }
                }
            };

            string error = string.Format(ErrorStrings.TargetTypeIsValueType, typeof(FieldReference <TheStruct, int>).Name, fieldReference.DisplayName);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(
                                error,
                                fieldReference.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }
        public void SetLeftOperandNull()
        {
            Variable <bool> var = new Variable <bool> {
                Default = true
            };
            TestOrElse orElse = new TestOrElse {
                Right = var
            };

            TestSequence seq = new TestSequence
            {
                Variables  = { var },
                Activities = { orElse }
            };

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(
                                string.Format(ErrorStrings.BinaryExpressionActivityRequiresArgument,
                                              "Left",
                                              "OrElse",
                                              orElse.DisplayName),
                                orElse.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(
                seq,
                constraints,
                string.Format(ErrorStrings.BinaryExpressionActivityRequiresArgument, "Left", "OrElse", orElse.DisplayName));
        }
Beispiel #5
0
        public void EmptyAssignmentNonGeneric()
        {
            string            hello = "Hello World";
            Variable <string> word  = new Variable <string>
            {
                Default = null
            };
            TestAssignNG assign = new TestAssignNG(typeof(string));
            TestSequence seq    = new TestSequence
            {
                Variables  = { word },
                Activities =
                {
                    assign,
                    new TestWriteLine
                    {
                        MessageVariable = word,
                        HintMessage     = hello,
                    }
                },
            };
            List <TestConstraintViolation> errors = new List <TestConstraintViolation> {
                new TestConstraintViolation(string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Value"), assign.ProductActivity, false), new TestConstraintViolation(string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "To"), assign.ProductActivity, false)
            };

            TestRuntime.ValidateWorkflowErrors(seq, errors, string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Value"));
        }
Beispiel #6
0
        public void SetOperandNull()
        {
            TestNot <int, int> not = new TestNot <int, int>();

            string errorMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Operand");

            TestRuntime.ValidateWorkflowErrors(not, new List <TestConstraintViolation>(), typeof(ArgumentException), errorMessage);
        }
Beispiel #7
0
        public void SetIndexNull()
        {
            TestArrayItemValue <string> testArray = new TestArrayItemValue <string>
            {
                ArrayExpression = context => new string[] { "x" }
            };
            string errorMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Index");

            TestRuntime.ValidateWorkflowErrors(testArray, new List <TestConstraintViolation>(), typeof(ArgumentException), errorMessage);
        }
Beispiel #8
0
        public void SetLeftOperandNull()
        {
            TestLessThanOrEqual <int, int, bool> lessThanOrEqual = new TestLessThanOrEqual <int, int, bool> {
                Right = 10
            };

            string errorMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Left");

            TestRuntime.ValidateWorkflowErrors(lessThanOrEqual, new List <TestConstraintViolation>(), typeof(ArgumentException), errorMessage);
        }
Beispiel #9
0
        public void SetLeftOperandNull()
        {
            TestOr <int, int, int> intOr = new TestOr <int, int, int> {
                Right = 3
            };

            string errorMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Left");

            TestRuntime.ValidateWorkflowErrors(intOr, new List <TestConstraintViolation>(), typeof(ArgumentException), errorMessage);
        }
Beispiel #10
0
        public void SetRightOperandNull()
        {
            TestGreaterThan <int, int, bool> greaterThan = new TestGreaterThan <int, int, bool> {
                Left = 10
            };

            string errorMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Right");

            TestRuntime.ValidateWorkflowErrors(greaterThan, new List <TestConstraintViolation>(), typeof(ArgumentException), errorMessage);
        }
Beispiel #11
0
        public void RightOperandNull()
        {
            TestDivide <int, int, int> div = new TestDivide <int, int, int>
            {
                Left = 12
            };

            string errorMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Right");

            TestRuntime.ValidateWorkflowErrors(div, new List <TestConstraintViolation>(), typeof(ArgumentException), errorMessage);
        }
Beispiel #12
0
        public void NewArrayWithArrayType()
        {
            TestNewArray <Array> arr = new TestNewArray <Array>();

            string error = ErrorStrings.NewArrayRequiresArrayTypeAsResultType;

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(error, arr.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(arr, constraints, error);
        }
Beispiel #13
0
        public void TryCastingUnrelatedTypes()
        {
            TestCast <string, int> cast = new TestCast <string, int> {
                Operand = "Hello"
            };

            string errorMessage = TestExpressionTracer.GetExceptionMessage <string, int>(System.Linq.Expressions.ExpressionType.Convert);

            TestRuntime.ValidateWorkflowErrors(cast, new List <TestConstraintViolation>()
            {
                new TestConstraintViolation(errorMessage, cast.ProductActivity, false)
            }, errorMessage);
        }
Beispiel #14
0
        public void TryGreaterThanOnIncompatibleTypes()
        {
            TestGreaterThan <int, string, bool> greaterThan = new TestGreaterThan <int, string, bool> {
                Left = 1, Right = "1"
            };

            string error = TestExpressionTracer.GetExceptionMessage <int, string, bool>(System.Linq.Expressions.ExpressionType.GreaterThan);

            TestRuntime.ValidateWorkflowErrors(greaterThan, new List <TestConstraintViolation>()
            {
                new TestConstraintViolation(error, greaterThan.ProductActivity)
            }, error);
        }
Beispiel #15
0
        public void TryLessThanOrEqualOnIncompatibleTypes()
        {
            TestLessThanOrEqual <int, string, bool> lessThanOrEqual = new TestLessThanOrEqual <int, string, bool> {
                Left = 1, Right = "1"
            };

            string error = TestExpressionTracer.GetExceptionMessage <int, string, bool>(System.Linq.Expressions.ExpressionType.LessThanOrEqual);

            TestRuntime.ValidateWorkflowErrors(lessThanOrEqual, new List <TestConstraintViolation>()
            {
                new TestConstraintViolation(error, lessThanOrEqual.ProductActivity)
            }, error);
        }
Beispiel #16
0
        public void NewAnArrayWithTypeArgumentNotIntegral()
        {
            TestNewArray <int[]> testNewArray = new TestNewArray <int[]>();

            testNewArray.Bounds.Add(new InArgument <string>("3"));

            string error = ErrorStrings.NewArrayBoundsRequiresIntegralArguments;

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(error, testNewArray.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(testNewArray, constraints, error);
        }
Beispiel #17
0
        public void NewAnArrayWithTypeArgumentULong()
        {
            TestNewArray <int[]> testNewArray = new TestNewArray <int[]>();

            testNewArray.Bounds.Add(new InArgument <ulong>(3));

            string error = string.Format(ErrorStrings.ConstructorInfoNotFound, typeof(int[]).Name);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(error, testNewArray.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(testNewArray, constraints, error);
        }
Beispiel #18
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);
        }
Beispiel #19
0
        public void StartNodeNullNodeCollectionNotNull()
        {
            TestFlowchart flowchart = new TestFlowchart();

            flowchart.AddLink(new TestWriteLine("One", "One"), new TestWriteLine("Two", "Two"));

            ((System.Activities.Statements.Flowchart)flowchart.ProductActivity).StartNode = null;

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(string.Format(ErrorStrings.FlowchartMissingStartNode, flowchart.DisplayName), flowchart.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(flowchart, constraints, string.Format(ErrorStrings.FlowchartMissingStartNode, flowchart.DisplayName));
        }
Beispiel #20
0
        public void ConstructAnObjectWithTypeHavingNoParameterLessConstructorWithoutProvidingTypes()
        {
            TestNew <ParameteredConstructorType> myNew = new TestNew <ParameteredConstructorType>();

            TestSequence seq = GetTraceableTestNew <ParameteredConstructorType>(myNew, "null");

            string error = string.Format(ErrorStrings.ConstructorInfoNotFound, typeof(ParameteredConstructorType).Name);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(error, myNew.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }
Beispiel #21
0
        public void ConstructObjectByProvidingLessParameters()
        {
            TestNew <Complex> myNew = new TestNew <Complex>();

            myNew.Arguments.Add(new TestArgument <int>(Direction.In, "Real", 1));

            string error = string.Format(ErrorStrings.ConstructorInfoNotFound, typeof(Complex).Name);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(error, myNew.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(myNew, constraints, error);
        }
Beispiel #22
0
        private void TrySettingInvalidProperty(TestPropertyReference <PublicType, int> propRef, string propName)
        {
            TestAssign <int> assign = new TestAssign <int> {
                ToLocation = propRef, Value = 10, ExpectedOutcome = Outcome.UncaughtException()
            };

            string error = string.Format(ErrorStrings.MemberNotFound, propName, typeof(PublicType).Name);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(
                                error,
                                propRef.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(assign, constraints, error);
        }
        public void VerifyValidationException()
        {
            string wfName = "TerminatingWorkflow";

            TestTerminateWorkflow terminate = new TestTerminateWorkflow(wfName)
            {
                // Not setting Reason and Exception
            };

            string exceptionMessage = string.Format(ErrorStrings.OneOfTwoPropertiesMustBeSet, "Reason", "Exception", "TerminateWorkflow", wfName);
            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(exceptionMessage, terminate.ProductActivity, false));

            TestRuntime.ValidateWorkflowErrors(terminate, constraints, exceptionMessage);
        }
Beispiel #24
0
        public void TryAccessingPropertyNotField()
        {
            TestFieldValue <PublicType, int> fieldVal = new TestFieldValue <PublicType, int>
            {
                OperandExpression = context => new PublicType(),
                FieldName         = "PublicProperty",
            };

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(
                                string.Format(ErrorStrings.MemberNotFound, "PublicProperty", typeof(PublicType).Name),
                                fieldVal.ProductActivity));

            TestRuntime.ValidateWorkflowErrors(fieldVal, constraints, string.Format(ErrorStrings.MemberNotFound, "PublicProperty", typeof(PublicType).Name));
        }
        public void TrySetItemNullOperand()
        {
            //
            //  Test case description:
            //  Try executing ValueTypeIndexerReference activity without initializing indices. Validation exception
            //  expected.

            TheStruct valueType = new TheStruct();

            Variable <TheStruct> var = new Variable <TheStruct>()
            {
                Default = valueType, Name = "var"
            };
            TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>()
            {
                Indices =
                {
                    new TestArgument <int>(Direction.In, null, 2)
                }
            };

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeIndexerReference, Value = value
            };

            TestSequence seq = new TestSequence()
            {
                Variables  = { var },
                Activities =
                {
                    testAssign,
                }
            };

            string error = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "OperandLocation", valueTypeIndexerReference.ProductActivity.GetType().Name, valueTypeIndexerReference.DisplayName);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(
                    error,
                    valueTypeIndexerReference.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }
        public void SetUninitializedIndices()
        {
            //
            //  Test case description:
            //  Try executing ValueTypeIndexerReference activity without initializing indices. Validation exception
            //  expected.

            TheStruct valueType = new TheStruct();

            Variable <TheStruct> var = new Variable <TheStruct>()
            {
                Default = valueType, Name = "var"
            };
            TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>()
            {
                OperandLocationVariable = var,
            };

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeIndexerReference, Value = value
            };

            TestSequence seq = new TestSequence()
            {
                Variables  = { var },
                Activities =
                {
                    testAssign,
                    new TestWriteLine {
                        MessageExpression = ((ctx) => var.Get(ctx)[1].ToString()),HintMessage                                                     = value.ToString()
                    }
                }
            };

            string error = string.Format(ErrorStrings.IndicesAreNeeded, valueTypeIndexerReference.ProductActivity.GetType().Name, valueTypeIndexerReference.DisplayName);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(
                    error,
                    valueTypeIndexerReference.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }
        public void TrySettingReadOnlyField()
        {
            //
            //  Test case description:
            //  Try setting a read only field. Exception expected.

            TheStruct valueType = new TheStruct();

            Variable <TheStruct> var = new Variable <TheStruct>()
            {
                Default = valueType, Name = "var"
            };
            TestValueTypeFieldReference <TheStruct, int> valueTypeFieldReference = new TestValueTypeFieldReference <TheStruct, int>()
            {
                FieldName = "readonlyField",
                OperandLocationVariable = var,
            };

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeFieldReference, Value = value
            };

            TestSequence seq = new TestSequence()
            {
                Variables  = { var },
                Activities =
                {
                    testAssign,
                    new TestWriteLine {
                        MessageExpression = ((ctx) => var.Get(ctx).readonlyField.ToString()),HintMessage                                                                = value.ToString()
                    }
                }
            };

            string error = string.Format(ErrorStrings.MemberIsReadOnly, "readonlyField", typeof(TheStruct).Name);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(
                    error,
                    valueTypeFieldReference.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }
        public void TrySettingNullFieldName()
        {
            //
            //  Test case description:
            //  Try setting a null OperandLocation. Validation exception expected.

            TheStruct valueType = new TheStruct();

            Variable <TheStruct> var = new Variable <TheStruct>()
            {
                Default = valueType, Name = "var"
            };
            TestValueTypeFieldReference <TheStruct, int> valueTypeFieldReference = new TestValueTypeFieldReference <TheStruct, int>()
            {
                OperandLocationVariable = var
            };

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeFieldReference, Value = value
            };

            TestSequence seq = new TestSequence()
            {
                Variables  = { var },
                Activities =
                {
                    testAssign,
                    new TestWriteLine {
                        MessageExpression = ((ctx) => var.Get(ctx).publicField.ToString()),HintMessage                                                              = value.ToString()
                    }
                }
            };

            string error = string.Format(ErrorStrings.ActivityPropertyMustBeSet, "FieldName", valueTypeFieldReference.DisplayName);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(
                    error,
                    valueTypeFieldReference.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }
        public void TrySetTypeWithoutIndexer()
        {
            //
            //  Test case description:
            //  Try setting indexer on type that does not support ‘this’ property. Validation exception is expected.

            int valueType = 0;

            Variable <int> var = new Variable <int>()
            {
                Default = valueType, Name = "var"
            };
            TestValueTypeIndexerReference <int, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <int, int>()
            {
                OperandLocationVariable = var,
            };

            valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, 2));

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeIndexerReference,
                Value      = value,
            };

            TestSequence seq = new TestSequence()
            {
                Variables  = { var },
                Activities =
                {
                    testAssign
                }
            };

            string error = string.Format(ErrorStrings.SpecialMethodNotFound, "set_Item", typeof(int).Name);

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(
                    error,
                    valueTypeIndexerReference.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }
Beispiel #30
0
        public void TrySettingPropertyWithoutSetter()
        {
            //
            //  Test case description:
            //  Try setting a property which does not have a setter. Exception expected.

            TheStruct valueType = new TheStruct();

            Variable <TheStruct> var = new Variable <TheStruct>()
            {
                Default = valueType, Name = "var"
            };
            TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>()
            {
                PropertyName            = "PropertyWithoutSetter",
                OperandLocationVariable = var,
            };

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation      = valueTypePropertyReference,
                Value           = value,
                ExpectedOutcome = Outcome.UncaughtException(typeof(InvalidOperationException)),
            };

            TestSequence seq = new TestSequence()
            {
                Variables  = { var },
                Activities =
                {
                    testAssign,
                }
            };

            string error = string.Format(ErrorStrings.MemberIsReadOnly, "PropertyWithoutSetter", typeof(TheStruct));

            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>
            {
                new TestConstraintViolation(
                    error,
                    valueTypePropertyReference.ProductActivity)
            };

            TestRuntime.ValidateWorkflowErrors(seq, constraints, error);
        }