public void CancellationScopeInPick() { // CancellationScope does not have test OM CancellationScope cancel = new CancellationScope() { DisplayName = "TestCancellationScope", Body = new TestSequence() { Activities = { new TestDelay("LongDelay", new TimeSpan(0, 0, 5)) } }.ProductActivity, CancellationHandler = new TestSequence() { Activities = { new TestWriteLine() { Message = "Cancelled" } } }.ProductActivity }; TestCustomActivity testCancel = TestCustomActivity <CancellationScope> .CreateFromProduct(cancel); testCancel.ActivitySpecificTraces.Add( new UnorderedTraces() { Steps = { new UserTrace("Cancelled"), } }); TestPick pick = new TestPick() { Branches = { new TestPickBranch() { Trigger = new TestDelay("ShortDelay", new TimeSpan(0, 0, 1)) }, new TestPickBranch() { Trigger = testCancel } } }; ExpectedTrace expectedTrace = pick.GetExpectedTrace(); expectedTrace.AddVerifyTypes(typeof(UserTrace)); TestRuntime.RunAndValidateWorkflow(pick, expectedTrace); }
public void RethrowFromCatchHandlerOfPrivateActivity() { string message = "this is expected uncaught exception"; TestCustomActivity <TestRethrowInPrivateChildren> rethrowAct = new TestCustomActivity <TestRethrowInPrivateChildren>() { ExpectedOutcome = Outcome.UncaughtException(), }; rethrowAct.CustomActivityTraces.Add(new ActivityTrace("Rethrow", CoreWf.ActivityInstanceState.Executing)); rethrowAct.CustomActivityTraces.Add(new ActivityTrace("Rethrow", CoreWf.ActivityInstanceState.Faulted)); TestTryCatch ttc = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <TestCaseException> { ExceptionExpression = (context => new TestCaseException(message)), ExpectedOutcome = Outcome.CaughtException(typeof(TestCaseException)), } } }, Catches = { new TestCatch <TestCaseException> { Body = rethrowAct } } }; //The validation error has a prefix: string validationError = string.Format(ErrorStrings.ValidationErrorPrefixForHiddenActivity, "2: " + rethrowAct.DisplayName) + string.Format(ErrorStrings.RethrowMustBeAPublicChild, "Rethrow"); TestRuntime.ValidateInstantiationException(ttc, validationError); }
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); }
public void DifferentArguments() { //Testing Different argument types for If.Condition // DelegateInArgument // DelegateOutArgument // Activity<T> // Variable<T> , Activity<T> and Expression is already implemented. DelegateInArgument <bool> delegateInArgument = new DelegateInArgument <bool>("Condition"); DelegateOutArgument <bool> delegateOutArgument = new DelegateOutArgument <bool>("Output"); TestCustomActivity <InvokeFunc <bool, bool> > invokeFunc = TestCustomActivity <InvokeFunc <bool, bool> > .CreateFromProduct( new InvokeFunc <bool, bool> { Argument = true, Func = new ActivityFunc <bool, bool> { Argument = delegateInArgument, Result = delegateOutArgument, Handler = new System.Activities.Statements.Sequence { DisplayName = "Sequence1", Activities = { new System.Activities.Statements.If { DisplayName = "If1", Condition = delegateInArgument, Then = new System.Activities.Statements.Sequence { DisplayName = "Sequence2", Activities = { new System.Activities.Statements.Assign <bool> { DisplayName = "Assign1", Value = delegateInArgument, To = delegateOutArgument, }, new System.Activities.Statements.If { DisplayName = "If2", Condition = delegateOutArgument, Then = new System.Activities.Statements.WriteLine { DisplayName = "W1", Text = "Tested DelegateIn and DelegateOut arguments in If condition" }, } } } } }, } } } ); TestSequence sequenceForTracing = new TestSequence { DisplayName = "Sequence1", Activities = { new TestIf(HintThenOrElse.Then) { DisplayName = "If1", ThenActivity = new TestSequence { DisplayName = "Sequence2", Activities = { new TestAssign <bool> { DisplayName = "Assign1" }, new TestIf(HintThenOrElse.Then) { DisplayName = "If2", ThenActivity = new TestSequence("W1"), } } } } } }; invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace); TestIf root = new TestIf(HintThenOrElse.Then) { ConditionActivity = invokeFunc, ThenActivity = new TestWriteLine { Message = "True", HintMessage = "True" }, ElseActivity = new TestWriteLine { Message = "False", HintMessage = "This is not expected" }, }; TestRuntime.RunAndValidateWorkflow(root); }
public void DifferentArguments() { //Testing Different argument types for DoWhile.Condition // DelegateInArgument // DelegateOutArgument // Variable<T> , Activity<T> and Expression is already implemented. DelegateInArgument <bool> delegateInArgument = new DelegateInArgument <bool>("Condition"); DelegateOutArgument <bool> delegateOutArgument = new DelegateOutArgument <bool>("Output"); TestCustomActivity <InvokeFunc <bool, bool> > invokeFunc = TestCustomActivity <InvokeFunc <bool, bool> > .CreateFromProduct( new InvokeFunc <bool, bool> { Argument = true, Func = new ActivityFunc <bool, bool> { Argument = delegateInArgument, Result = delegateOutArgument, Handler = new Microsoft.CoreWf.Statements.Sequence { DisplayName = "sequence1", Activities = { new Microsoft.CoreWf.Statements.DoWhile { DisplayName = "DoWhile1", Condition = ExpressionServices.Convert <bool>(ctx => delegateInArgument.Get(ctx)), Body = new Microsoft.CoreWf.Statements.Assign <bool> { DisplayName = "Assign1", To = delegateInArgument, Value = new Not <bool, bool> { DisplayName = "Not1", Operand = delegateInArgument } }, }, new Microsoft.CoreWf.Statements.Assign <bool> { DisplayName = "Assign2", To = delegateOutArgument, Value = new Not <bool, bool> { DisplayName = "Not2", Operand = delegateInArgument }, }, new Microsoft.CoreWf.Statements.DoWhile { DisplayName = "DoWhile2", Condition = ExpressionServices.Convert <bool>(ctx => !delegateOutArgument.Get(ctx)), Body = new Microsoft.CoreWf.Statements.Assign <bool> { DisplayName = "Assign3", To = delegateOutArgument, Value = new Not <bool, bool> { DisplayName = "Not3", Operand = delegateInArgument } }, }, }, } } } ); TestSequence sequenceForTracing = new TestSequence { DisplayName = "sequence1", Activities = { new TestDoWhile { DisplayName = "DoWhile1", ActivitySpecificTraces = { new OrderedTraces() { Steps = { new ActivityTrace("Assign1", ActivityInstanceState.Executing), new ActivityTrace("Not1", ActivityInstanceState.Executing), new ActivityTrace("Not1", ActivityInstanceState.Closed), new ActivityTrace("Assign1", ActivityInstanceState.Closed), new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Executing), new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Closed), } }, } }, new TestAssign <bool> { DisplayName = "Assign2", ValueActivity = new Test.Common.TestObjects.Activities.Expressions.TestNot <bool, bool>{ DisplayName = "Not2" } }, new TestDoWhile { DisplayName = "DoWhile2", ActivitySpecificTraces = { new OrderedTraces() { Steps = { new ActivityTrace("Assign3", ActivityInstanceState.Executing), new ActivityTrace("Not3", ActivityInstanceState.Executing), new ActivityTrace("Not3", ActivityInstanceState.Closed), new ActivityTrace("Assign3", ActivityInstanceState.Closed), new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Executing), new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Closed), } }, } }, } }; invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace); TestIf root = new TestIf(HintThenOrElse.Then) { ConditionActivity = invokeFunc, ThenActivity = new TestWriteLine { Message = "True", HintMessage = "True" }, ElseActivity = new TestWriteLine { Message = "False", HintMessage = "This is not expected" }, }; TestRuntime.RunAndValidateWorkflow(root); }
public void SetDelegateArgument() { // for using delegate argument TheStruct valueType = new TheStruct(); int indiceValue = 2; DelegateInArgument <int> indice = new DelegateInArgument <int>(); Variable <TheStruct> var = VariableHelper.CreateInitialized <TheStruct>("var", valueType); TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>() { OperandLocationVariable = var, }; valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, (env) => indice.Get(env))); int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypeIndexerReference, Value = value }; TestSequence seq = new TestSequence() { Activities = { testAssign, new TestWriteLine { MessageExpression = ((ctx) => var.Get(ctx)[indiceValue].ToString()) } } }; CoreWf.Statements.Sequence outerSeq = new CoreWf.Statements.Sequence() { Variables = { var }, Activities = { new InvokeAction <int>() { Argument = indiceValue, Action = new ActivityAction <int>() { Argument = indice, Handler = seq.ProductActivity } } } }; TestCustomActivity testActivity = TestCustomActivity <CoreWf.Statements.Sequence> .CreateFromProduct(outerSeq); UnorderedTraces traces = new UnorderedTraces() { Steps = { new UserTrace(value.ToString()) } }; testActivity.ActivitySpecificTraces.Add(traces); ExpectedTrace expectedTrace = testActivity.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(ActivityTrace)); TestRuntime.RunAndValidateWorkflow(testActivity, expectedTrace); }