Exemple #1
0
        /// <summary>
        /// Create internal states
        /// </summary>
        /// <param name="metadata">NativeActivityMetadata reference.</param>
        private void ProcessStates(NativeActivityMetadata metadata)
        {
            // remove duplicate state in the collection during evaluation
            IEnumerable <State> distinctStates = _states.Distinct();

            foreach (State state in distinctStates)
            {
                InternalState internalState = state.InternalState;
                _internalStates.Add(internalState);

                DelegateInArgument <StateMachineEventManager> eventManager = new DelegateInArgument <Statements.StateMachineEventManager>();
                internalState.EventManager = eventManager;

                ActivityFunc <StateMachineEventManager, string> activityFunc = new ActivityFunc <StateMachineEventManager, string>
                {
                    Argument = eventManager,
                    Handler  = internalState,
                };

                if (state.Reachable)
                {
                    // If this state is not reached, we should not add it as child because it's even not well validated.
                    metadata.AddDelegate(activityFunc, /* origin = */ state);
                }

                _internalStateFuncs.Add(activityFunc);
            }
        }
Exemple #2
0
        public void ManualResumptionActivity_GetChildrenNodes_ShouldReturnChildNode()
        {
            var activity         = CreateWorkflow();
            var activityFunction = new ActivityFunc <string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler     = activity,
            };

            var manualResumptionActivity = new ManualResumptionActivity()
            {
                SuspensionId           = "15",
                OverrideInputVariables = true,
                OverrideDataFunc       = activityFunction,
                Response = "[[result]]"
            };

            Assert.AreEqual("Manual Resumption", manualResumptionActivity.DisplayName);
            Assert.AreEqual("15", manualResumptionActivity.SuspensionId);
            Assert.IsTrue(manualResumptionActivity.OverrideInputVariables);
            Assert.AreEqual("TestService", manualResumptionActivity.OverrideDataFunc.DisplayName);

            var result = manualResumptionActivity.GetChildrenNodes().ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(activity, result[0]);
        }
 /// <summary>
 /// Create internal states
 /// </summary>
 public static void ProcessChildStates(NativeActivityMetadata metadata, Collection<State> childStates,
     Collection<InternalState> internalStates, Collection<ActivityFunc<string, StateMachineEventManager, string>> internalStateFuncs)
 {
     foreach (State state in childStates)
     {
         InternalState internalState = state.InternalState;
         internalStates.Add(internalState);
         DelegateInArgument<string> toStateId = new DelegateInArgument<string>();
         DelegateInArgument<StateMachineEventManager> eventManager = new DelegateInArgument<StateMachineEventManager>();
         internalState.ToState = toStateId;
         internalState.EventManager = eventManager;
         ActivityFunc<string, StateMachineEventManager, string> activityFunc = new ActivityFunc<string, StateMachineEventManager, string>
         {
             Argument1 = toStateId,
             Argument2 = eventManager,
             Handler = internalState,
         };
         if (state.Reachable)
         {
             //If this state is not reached, we should not add it as child because it's even not well validated.
             metadata.AddDelegate(activityFunc);
         }
         internalStateFuncs.Add(activityFunc);
     }
 }
 /// <summary>
 /// Create internal states
 /// </summary>
 public static void ProcessChildStates(NativeActivityMetadata metadata, Collection <State> childStates,
                                       Collection <InternalState> internalStates, Collection <ActivityFunc <string, StateMachineEventManager, string> > internalStateFuncs)
 {
     foreach (State state in childStates)
     {
         InternalState internalState = state.InternalState;
         internalStates.Add(internalState);
         DelegateInArgument <string> toStateId = new DelegateInArgument <string>();
         DelegateInArgument <StateMachineEventManager> eventManager = new DelegateInArgument <StateMachineEventManager>();
         internalState.ToState      = toStateId;
         internalState.EventManager = eventManager;
         ActivityFunc <string, StateMachineEventManager, string> activityFunc = new ActivityFunc <string, StateMachineEventManager, string>
         {
             Argument1 = toStateId,
             Argument2 = eventManager,
             Handler   = internalState,
         };
         if (state.Reachable)
         {
             //If this state is not reached, we should not add it as child because it's even not well validated.
             metadata.AddDelegate(activityFunc);
         }
         internalStateFuncs.Add(activityFunc);
     }
 }
        DsfForEachActivity SetupArguments(string currentDl, string testData, enForEachType type, bool isInputMapping = false, string inputMapping = null, string from = null, string to = null, string csvIndexes = null, string numberExecutions = null)
        {
            var activityFunction = new ActivityFunc <string, bool>();
            var activity         = inputMapping != null?CreateWorkflow(inputMapping, isInputMapping) : CreateWorkflow();

            activityFunction.Handler = activity;
            var id = Guid.NewGuid().ToString();
            var dsfForEachActivity = new DsfForEachActivity
            {
                DataFunc       = activityFunction,
                ForEachType    = type,
                NumOfExections = numberExecutions,
                From           = @from,
                To             = to,
                CsvIndexes     = csvIndexes,
                UniqueID       = id
            };

            TestStartNode = new FlowStep
            {
                Action = dsfForEachActivity
            };

            CurrentDl = testData;
            TestData  = currentDl;
            return(dsfForEachActivity);
        }
Exemple #6
0
        /// <summary>
        /// Creates a new <see cref="PickBranch"/> with the given <paramref name="trigger"/> and <paramref name="action"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="trigger"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static PickBranch PickBranch <T>(ActivityFunc <T> trigger, ActivityAction <T> action)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var arg = new Variable <T>();

            return(new PickBranch()
            {
                Variables = { arg },
                Trigger = new InvokeFunc <T>()
                {
                    Func = trigger,
                    Result = arg,
                },
                Action = new InvokeAction <T>()
                {
                    Action = action,
                    Argument = arg,
                }
            });
        }
        /// <summary>
        /// Creates a for loop.
        /// </summary>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="initial"></param>
        /// <param name="condition"></param>
        /// <param name="increment"></param>
        /// <param name="createAction"></param>
        /// <returns></returns>
        public static For <TValue> For <TValue>(
            InArgument <TValue> initial,
            ActivityFunc <TValue, bool> condition,
            ActivityFunc <TValue, TValue> increment,
            Func <DelegateInArgument <TValue>, Activity> createAction)
        {
            if (initial == null)
            {
                throw new ArgumentNullException(nameof(initial));
            }
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }
            if (increment == null)
            {
                throw new ArgumentNullException(nameof(increment));
            }
            if (createAction == null)
            {
                throw new ArgumentNullException(nameof(createAction));
            }

            return(new For <TValue>()
            {
                Initial = initial,
                Condition = condition,
                Increment = increment,
                Action = Delegate(createAction),
            });
        }
Exemple #8
0
        public void WhenTheToolIsExecuted(string activityName)
        {
            BuildDataList();

            scenarioContext.TryGetValue(activityName, out DsfForEachActivity forEachActivity);

            var sequence     = SetupSequence();
            var activityFunc = new ActivityFunc <string, bool> {
                Handler = sequence
            };

            forEachActivity.DataFunc = activityFunc;

            TestStartNode = new FlowStep
            {
                Action = forEachActivity
            };

            PerformExecution();

            scenarioContext.TryGetValue("DebugStates", out List <IDebugState> debugStates);

            if (debugStates.Count > 0)
            {
                var sequenceDebugState   = debugStates.Where(state => state.DisplayName == sequence.DisplayName);
                var debugStateOfSequence = sequenceDebugState as IDebugState[] ?? sequenceDebugState.ToArray();
                Assert.IsTrue(debugStateOfSequence.Any());
                Assert.IsTrue(debugStateOfSequence.All(state => state.ParentID.GetValueOrDefault().ToString() == forEachActivity.UniqueID));
            }

            scenarioContext.TryGetValue("activityList", out Dictionary <string, Activity> activityList);
            activityList.Add(activityName, forEachActivity);
        }
        /// <summary>
        /// Creates a for loop.
        /// </summary>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="initial"></param>
        /// <param name="condition"></param>
        /// <param name="increment"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static For <TValue> For <TValue>(
            InArgument <TValue> initial,
            ActivityFunc <TValue, bool> condition,
            ActivityFunc <TValue, TValue> increment,
            Func <TValue, Task> action)
        {
            if (initial == null)
            {
                throw new ArgumentNullException(nameof(initial));
            }
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }
            if (increment == null)
            {
                throw new ArgumentNullException(nameof(increment));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            return(new For <TValue>()
            {
                Initial = initial,
                Condition = condition,
                Increment = increment,
                Action = Delegate <TValue>(arg => Invoke(action, arg)),
            });
        }
Exemple #10
0
        public void ManualResumptionActivity_Initialize_With_Values_OverrideInputVariables_False()
        {
            var activity         = CreateWorkflow();
            var activityFunction = new ActivityFunc <string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler     = activity,
            };

            var manualResumptionActivity = new ManualResumptionActivity()
            {
                SuspensionId           = "15",
                OverrideInputVariables = false,
                OverrideDataFunc       = activityFunction,
                Response = "[[result]]"
            };

            Assert.AreEqual("Manual Resumption", manualResumptionActivity.DisplayName);
            Assert.AreEqual("15", manualResumptionActivity.SuspensionId);
            Assert.IsFalse(manualResumptionActivity.OverrideInputVariables);
            Assert.AreEqual("TestService", manualResumptionActivity.OverrideDataFunc.DisplayName);

            var result = manualResumptionActivity.GetOutputs();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(null, result[0]);
        }
Exemple #11
0
        public void ManualResumptionActivity_GetFindMissingType_GivenIsNew_ShouldSetManualResumptionActivity()
        {
            //---------------Set up test pack-------------------

            var activity         = CreateWorkflow();
            var activityFunction = new ActivityFunc <string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler     = activity,
            };

            var manualResumptionActivity = new ManualResumptionActivity()
            {
                SuspensionId           = "15",
                OverrideInputVariables = true,
                OverrideDataFunc       = activityFunction,
                Response = "[[result]]"
            };
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var enFindMissingType = manualResumptionActivity.GetFindMissingType();

            //---------------Test Result -----------------------
            Assert.AreEqual(enFindMissingType.ManualResumption, enFindMissingType);
        }
Exemple #12
0
        public void SuspendExecutionActivity_GetChildrenNodes_ShouldReturnChildNodes()
        {
            var activity = CreateWorkflow();
            var activityFunction = new ActivityFunc<string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler = activity,
            };

            var suspendExecutionActivity = new SuspendExecutionActivity
            {
                SuspendOption = enSuspendOption.SuspendForDays,
                PersistValue = "15",
                AllowManualResumption = true,
                SaveDataFunc = activityFunction,
                Response = "[[result]]"
            };

            Assert.AreEqual("Suspend Execution", suspendExecutionActivity.DisplayName);
            Assert.AreEqual("15", suspendExecutionActivity.PersistValue);
            Assert.AreEqual(enSuspendOption.SuspendForDays, suspendExecutionActivity.SuspendOption);
            Assert.IsTrue(suspendExecutionActivity.AllowManualResumption);
            Assert.AreEqual("TestService", suspendExecutionActivity.SaveDataFunc.DisplayName);

            var result = suspendExecutionActivity.GetChildrenNodes().ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(activity, result[0]);
        }
 public ReceiveResponse()
 {
     responseResultWaiter    = TaskFuncTaskWaiter.CreateActivityDelegate();
     responseResultEvaluator = TaskFuncEvaluator.CreateActivityDelegate();
     Constraints.Add(OperationActivityHelper.VerifyParentIsWorkflowActivity());
     Constraints.Add(OperationActivityHelper.VerifyParentIsSendRequestReceiveResponseScope());
 }
Exemple #14
0
 public DsfSelectAndApplyActivity()
 {
     DisplayName       = "Select and apply";
     ApplyActivityFunc = new ActivityFunc <string, bool>
     {
         DisplayName = "Data Action",
         Argument    = new DelegateInArgument <string>($"explicitData_{DateTime.Now:yyyyMMddhhmmss}")
     };
 }
 public DsfForEachActivity()
 {
     DataFunc = new ActivityFunc <string, bool>
     {
         DisplayName = "Data Action",
         Argument    = new DelegateInArgument <string>(string.Format("explicitData_{0}", DateTime.Now.ToString("yyyyMMddhhmmss")))
     };
     DisplayName = "For Each";
 }
Exemple #16
0
 public DsfForEachActivity()
 {
     DataFunc = new ActivityFunc <string, bool>
     {
         DisplayName = "Data Action",
         Argument    = new DelegateInArgument <string>($"explicitData_{DateTime.Now:yyyyMMddhhmmss}")
     };
     DisplayName = "For Each";
 }
 public ManualResumptionActivity(PersistenceSettings config, IPersistenceExecution resumeExecution)
 {
     DisplayName      = "Manual Resumption";
     OverrideDataFunc = new ActivityFunc <string, bool>
     {
         DisplayName = "Data Action",
         Argument    = new DelegateInArgument <string>($"explicitData_{DateTime.Now:yyyyMMddhhmmss}"),
     };
     _persistenceEnabled = config.Enable;
     _scheduler          = resumeExecution;
 }
 public SuspendExecutionActivity(PersistenceSettings config, IPersistenceExecution suspendExecution)
 {
     DisplayName  = "Suspend Execution";
     SaveDataFunc = new ActivityFunc <string, bool>
     {
         DisplayName = "Data Action",
         Argument    = new DelegateInArgument <string>($"explicitData_{DateTime.Now:yyyyMMddhhmmss}"),
     };
     _persistenceEnabled = config.Enable;
     _scheduler          = suspendExecution;
 }
Exemple #19
0
        /// <summary>
        /// Returns an <see cref="Activity"/> that invokes the function with the specified arguments.
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="func"></param>
        /// <param name="displayName"></param>
        /// <returns></returns>
        public static InvokeFunc <TResult> InvokeFunc <TResult>(ActivityFunc <TResult> func, string displayName = null)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            return(new InvokeFunc <TResult>()
            {
                DisplayName = displayName,
                Func = func,
            });
        }
Exemple #20
0
 public GateActivity()
     : base(nameof(Gate))
 {
     DisplayName = nameof(Gate);
     if (GateOptions is null)
     {
         GateOptions = new GateOptions();
     }
     DataFunc = new ActivityFunc <string, bool>
     {
         DisplayName = "Data Action",
         Argument    = new DelegateInArgument <string>($"explicitData_{DateTime.Now:yyyyMMddhhmmss}")
     };
 }
        public RedisCacheActivity(IResourceCatalog resourceCatalog, ResponseManager responseManager, RedisCacheBase redisCache)
        {
            ResponseManager = responseManager;
            _redisCache     = redisCache;
            ResourceCatalog = resourceCatalog;

            DisplayName  = "Redis Cache";
            ActivityFunc = new ActivityFunc <string, bool>
            {
                DisplayName = "Data Action",
                Argument    = new DelegateInArgument <string>($"explicitData_{DateTime.Now:yyyyMMddhhmmss}")
            };

            _serializer = new Dev2JsonSerializer();
        }
Exemple #22
0
        public void SuspendExecututionActivity_GetFindMissingType_GivenIsNew_ShouldSetManualResumptionActivity()
        {
            //---------------Set up test pack-------------------

            var activity = CreateWorkflow();
            var activityFunction = new ActivityFunc<string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler = activity,
            };

            var suspendExecutionActivity = new SuspendExecutionActivity();

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var enFindMissingType = suspendExecutionActivity.GetFindMissingType();
            //---------------Test Result -----------------------
            Assert.AreEqual(enFindMissingType.SuspendExecution, enFindMissingType);
        }
 private void ProcessStates(NativeActivityMetadata metadata)
 {
     foreach (System.Activities.Statements.State state in this.states.Distinct <System.Activities.Statements.State>())
     {
         InternalState internalState = state.InternalState;
         this.internalStates.Add(internalState);
         DelegateInArgument <StateMachineEventManager> argument = new DelegateInArgument <StateMachineEventManager>();
         internalState.EventManager = argument;
         ActivityFunc <StateMachineEventManager, string> activityDelegate = new ActivityFunc <StateMachineEventManager, string> {
             Argument = argument,
             Handler  = internalState
         };
         if (state.Reachable)
         {
             metadata.AddDelegate(activityDelegate);
         }
         this.internalStateFuncs.Add(activityDelegate);
     }
 }
Exemple #24
0
        public void WhenTheToolIsExecuted(string activityName)
        {
            BuildDataList();

            scenarioContext.TryGetValue(activityName, out DsfForEachActivity forEachActivity);

            var sequence     = SetupSequence();
            var activityFunc = new ActivityFunc <string, bool> {
                Handler = sequence
            };

            forEachActivity.DataFunc = activityFunc;

            TestStartNode = new FlowStep
            {
                Action = forEachActivity
            };

            PerformExecution();

            scenarioContext.TryGetValue("DebugStates", out List <IDebugState> debugStates);

            if (debugStates.Count > 0)
            {
                var sequenceDebugState   = debugStates.Where(state => state.DisplayName == sequence.DisplayName);
                var debugStateOfSequence = sequenceDebugState as IDebugState[] ?? sequenceDebugState.ToArray();
                Assert.IsTrue(debugStateOfSequence.Any());
                var forEachDebug = debugStates.Where(state => state.DisplayName == activityName).ToArray();
                for (var j = 0; j < forEachDebug.Length; j++)
                {
                    for (var i = 0; i < debugStateOfSequence.Length; i++)
                    {
                        Assert.AreEqual(debugStateOfSequence[i].ParentID, forEachDebug[j].ID);
                    }
                }
            }

            scenarioContext.TryGetValue("activityList", out Dictionary <string, Activity> activityList);
            activityList.Add(activityName, forEachActivity);
        }
Exemple #25
0
        public bool Equals(ActivityFunc <string, bool> x, ActivityFunc <string, bool> y)
        {
            if (x == null && y == null)
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            IEqualityComparer <DelegateArgument> argumentComparer = new DelegateArgumentComparer();
            var argumentsAreEqual = argumentComparer.Equals(x.Argument, y.Argument);
            var resultAreEqual    = argumentComparer.Equals(x.Result, y.Result);

            var @equals = string.Equals(x.DisplayName, y.DisplayName);
            var handlerActivityIsEqual = CommonEqualityOps.AreObjectsEqualUnSafe(x.Handler, y.Handler);


            //var handlerActivityIsEqual = x.Handler?.Equals(y.Handler) ?? true;//All activities have an implemantation of Equals at this stage :)
            return(equals && argumentsAreEqual && resultAreEqual && handlerActivityIsEqual);
        }
 private void ProcessStates(NativeActivityMetadata metadata)
 {
     foreach (System.Activities.Statements.State state in this.states.Distinct<System.Activities.Statements.State>())
     {
         InternalState internalState = state.InternalState;
         this.internalStates.Add(internalState);
         DelegateInArgument<StateMachineEventManager> argument = new DelegateInArgument<StateMachineEventManager>();
         internalState.EventManager = argument;
         ActivityFunc<StateMachineEventManager, string> activityDelegate = new ActivityFunc<StateMachineEventManager, string> {
             Argument = argument,
             Handler = internalState
         };
         if (state.Reachable)
         {
             metadata.AddDelegate(activityDelegate);
         }
         this.internalStateFuncs.Add(activityDelegate);
     }
 }
Exemple #27
0
        private DsfForEachActivity SetupArguments(string currentDl, string testData, enForEachType type, bool isInputMapping = false, string inputMapping = null, string from = null, string to = null, string csvIndexes = null, string numberExecutions = null)
        {
            var activityFunction = new ActivityFunc<string, bool>();
            DsfActivity activity = inputMapping != null ? CreateWorkflow(inputMapping, isInputMapping) : CreateWorkflow();

            activityFunction.Handler = activity;
            var id = Guid.NewGuid().ToString();
            DsfForEachActivity dsfForEachActivity = new DsfForEachActivity
                {
                    DataFunc = activityFunction, ForEachType = type, NumOfExections = numberExecutions, From = @from, To = to, CsvIndexes = csvIndexes, UniqueID = id
                };
            TestStartNode = new FlowStep
            {
                Action = dsfForEachActivity
            };

            CurrentDl = testData;
            TestData = currentDl;
            return dsfForEachActivity;
        }
        public void WhenTheToolIsExecuted(string activityName)
        {
            BuildDataList();

            DsfForEachActivity forEachActivity;
            ScenarioContext.Current.TryGetValue(activityName, out forEachActivity);

            var sequence = SetupSequence();
            var activityFunc = new ActivityFunc<string, bool> { Handler = sequence };
            forEachActivity.DataFunc = activityFunc;

            TestStartNode = new FlowStep
            {
                Action = forEachActivity
            };

            PerformExecution();

            List<IDebugState> debugStates;
            ScenarioContext.Current.TryGetValue("DebugStates", out debugStates);

            if(debugStates.Count > 0)
            {
                var sequenceDebugState = debugStates.Where(state => state.DisplayName == sequence.DisplayName);
                var debugStateOfSequence = sequenceDebugState as IDebugState[] ?? sequenceDebugState.ToArray();
                Assert.IsTrue(debugStateOfSequence.Any());
                Assert.IsTrue(debugStateOfSequence.All(state => state.ParentID.ToString() == forEachActivity.UniqueID));
            }

            Dictionary<string, Activity> activityList;
            ScenarioContext.Current.TryGetValue("activityList", out activityList);
            activityList.Add(activityName, forEachActivity);
        }
Exemple #29
0
        public void AddActivityToActivityList(string parentName, string activityName, Activity activity)
        {
            if (!_scenarioContext.TryGetValue("activityList", out Dictionary <string, Activity> activityList))
            {
                activityList = new Dictionary <string, Activity>();
                _scenarioContext.Add("activityList", activityList);
            }

            if (activityList.TryGetValue(parentName, out Activity parentActivity))
            {
                if (parentActivity is DsfSequenceActivity)
                {
                    var seq = parentActivity as DsfSequenceActivity;
                    seq.Activities.Add(activity);
                }
                else if (parentActivity is DsfForEachActivity)
                {
                    var forEachActivity = parentActivity as DsfForEachActivity;
                    var activityFunc    = new ActivityFunc <string, bool> {
                        Handler = activity
                    };
                    forEachActivity.DataFunc = activityFunc;
                }
            }
            else
            {
                var findAllForEach = activityList.FirstOrDefault(pair =>
                {
                    var forEachActivity = pair.Value as DsfForEachActivity;
                    if (forEachActivity == null)
                    {
                        return(false);
                    }

                    return(forEachActivity.DataFunc.Handler != null && forEachActivity.DataFunc != null && forEachActivity.DataFunc.Handler as DsfForEachActivity != null);
                });
                if (findAllForEach.Value is DsfForEachActivity forEachParentActivity)
                {
                    var activityFunc = new ActivityFunc <string, bool> {
                        Handler = activity
                    };
                    DsfForEachActivity foundCorrectParentForEach = null;
                    while (forEachParentActivity != null)
                    {
                        if (forEachParentActivity.DataFunc?.Handler != null && forEachParentActivity.DataFunc.Handler.DisplayName == parentName)
                        {
                            foundCorrectParentForEach = forEachParentActivity.DataFunc.Handler as DsfForEachActivity;
                            break;
                        }
                        if (forEachParentActivity.DataFunc != null)
                        {
                            forEachParentActivity = forEachParentActivity.DataFunc.Handler as DsfForEachActivity;
                        }
                        else
                        {
                            forEachParentActivity = null;
                        }
                    }
                    if (foundCorrectParentForEach != null)
                    {
                        foundCorrectParentForEach.DataFunc = activityFunc;
                    }
                }
                else
                {
                    activityList.Add(activityName, activity);
                }
            }
        }
Exemple #30
0
        public void SuspendExecutionActivity_Execute_SuspendForSeconds_SaveSuspendIDIntoEnv_Success()
        {
            //------------Setup for test--------------------------
            var workflowName = "workflowName";
            var url = "http://localhost:3142/secure/WorkflowResume";
            var resourceId = Guid.NewGuid();
            var nextNodeId = Guid.NewGuid();
            var workflowInstanceId = Guid.NewGuid();
            var env = CreateExecutionEnvironment();
            env.Assign("[[UUID]]", "public", 0);
            env.Assign("[[JourneyName]]", "whatever", 0);

            var mockStateNotifier = new Mock<IStateNotifier>();
            mockStateNotifier.Setup(stateNotifier => stateNotifier.LogActivityExecuteState(It.IsAny<IDev2Activity>()));

            var environmentId = Guid.Empty;
            User = GlobalConstants.GenericPrincipal;
            var dataObject = new DsfDataObject(CurrentDl, ExecutionId)
            {
                ServiceName = workflowName,
                ResourceID = resourceId,
                WorkflowInstanceId = workflowInstanceId,
                WebUrl = url,
                ServerID = Guid.NewGuid(),
                ExecutingUser = User,
                IsDebug = true,
                EnvironmentID = environmentId,
                Environment = env,
                IsRemoteInvokeOverridden = false,
                DataList = new StringBuilder(CurrentDl),
                IsServiceTestExecution = true
            };

            var mockActivity = new Mock<IDev2Activity>();
            mockActivity.Setup(o => o.UniqueID).Returns(nextNodeId.ToString());
            var dev2Activities = new List<IDev2Activity> {mockActivity.Object};
            var activity = CreateWorkflow();
            var activityFunction = new ActivityFunc<string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler = activity,
            };
            var config = new PersistenceSettings
            {
                Enable = true
            };
            var suspendExecutionActivity = new SuspendExecutionActivity(config, new Mock<IPersistenceExecution>().Object)
            {
                SuspendOption = enSuspendOption.SuspendForSeconds,
                PersistValue = "20",
                AllowManualResumption = true,
                SaveDataFunc = activityFunction,
                //Result = "[[SuspendID]]",
                NextNodes = dev2Activities
            };

            suspendExecutionActivity.SetStateNotifier(mockStateNotifier.Object);
            //------------Execute Test---------------------------
            suspendExecutionActivity.Execute(dataObject, 0);

            //------------Assert Results-------------------------
            Assert.AreEqual(0, env.Errors.Count);
            GetScalarValueFromEnvironment(env, "SuspendID", out string suspendId, out string error);
            Assert.AreEqual(suspendId, suspendExecutionActivity.Response);
        }
Exemple #31
0
        public void SuspendExecutionActivity_Execute_EncryptData_False()
        {
            //------------Setup for test--------------------------
            var workflowName = "workflowName";
            var url = "http://localhost:3142/secure/WorkflowResume";
            var resourceId = Guid.NewGuid();
            var nextNodeId = Guid.NewGuid();
            var workflowInstanceId = Guid.NewGuid();
            var env = CreateExecutionEnvironment();
            env.Assign("[[UUID]]", "public", 0);
            env.Assign("[[JourneyName]]", "whatever", 0);

            var mockStateNotifier = new Mock<IStateNotifier>();
            mockStateNotifier.Setup(stateNotifier => stateNotifier.LogActivityExecuteState(It.IsAny<IDev2Activity>()));

            var environmentId = Guid.Empty;
            var mockPrincipal = new Mock<ClaimsPrincipal>();
            mockPrincipal.Setup(o => o.Identity).Returns(WindowsIdentity.GetCurrent());
            var dataObject = new DsfDataObject(CurrentDl, ExecutionId)
            {
                ServiceName = workflowName,
                ResourceID = resourceId,
                WorkflowInstanceId = workflowInstanceId,
                WebUrl = url,
                ServerID = Guid.NewGuid(),
                ExecutingUser = mockPrincipal.Object,
                IsDebug = true,
                EnvironmentID = environmentId,
                Environment = env,
                IsRemoteInvokeOverridden = false,
                DataList = new StringBuilder(CurrentDl),
                IsServiceTestExecution = true
            };

            var mockActivity = new Mock<IDev2Activity>();
            mockActivity.Setup(o => o.UniqueID).Returns(nextNodeId.ToString());
            var dev2Activities = new List<IDev2Activity> {mockActivity.Object};
            var activity = CreateWorkflow();
            var activityFunction = new ActivityFunc<string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler = activity,
            };
            var suspendUntil = DateTime.Now.AddDays(1);
            var config = new PersistenceSettings
            {
                Enable = true
            };

            var currentEnvironment = dataObject.Environment.ToJson();
            var values = new Dictionary<string, StringBuilder>
            {
                {"resourceID", new StringBuilder(dataObject.ResourceID.ToString())},
                {"environment", new StringBuilder(currentEnvironment)},
                {"startActivityId", new StringBuilder(nextNodeId.ToString())},
                {"versionNumber", new StringBuilder(dataObject.VersionNumber.ToString())},
                {"currentuserprincipal", new StringBuilder(WindowsIdentity.GetCurrent().Name)}
            };

            var mockSuspendExecution = new Mock<IPersistenceExecution>();
            mockSuspendExecution.Setup(o => o.CreateAndScheduleJob(enSuspendOption.SuspendUntil, suspendUntil.ToString(), values)).Verifiable();
            var suspendExecutionActivity = new SuspendExecutionActivity(config, mockSuspendExecution.Object)
            {
                SuspendOption = enSuspendOption.SuspendUntil,
                PersistValue = suspendUntil.ToString(),
                AllowManualResumption = true,
                EncryptData = false,
                SaveDataFunc = activityFunction,
                //Result = "[[SuspendID]]",
                NextNodes = dev2Activities
            };

            suspendExecutionActivity.SetStateNotifier(mockStateNotifier.Object);
            //------------Execute Test---------------------------
            suspendExecutionActivity.Execute(dataObject, 0);

            //------------Assert Results-------------------------
            Assert.AreEqual(0, env.Errors.Count);
            GetScalarValueFromEnvironment(env, "SuspendID", out string suspendId, out string error);
            Assert.AreEqual(suspendId, suspendExecutionActivity.Response);
            //TODO: We need to improve on this verify to validate that the environment is not encrypted. Verify fails for unknown mismatch
            mockSuspendExecution.Verify(o => o.CreateAndScheduleJob(enSuspendOption.SuspendUntil, suspendUntil.ToString(), It.IsAny<Dictionary<string, StringBuilder>>()), Times.Once);
        }
Exemple #32
0
        public void SuspendExecutionActivity_Execute_PersistenceNotConfigured_FailWithMessage()
        {
            //------------Setup for test--------------------------
            var workflowName = "workflowName";
            var url = "http://localhost:3142/secure/WorkflowResume";
            var resourceId = Guid.NewGuid();
            var nextNodeId = Guid.NewGuid();
            var workflowInstanceId = Guid.NewGuid();
            var env = CreateExecutionEnvironment();
            env.Assign("[[UUID]]", "public", 0);
            env.Assign("[[JourneyName]]", "whatever", 0);

            var mockStateNotifier = new Mock<IStateNotifier>();
            mockStateNotifier.Setup(stateNotifier => stateNotifier.LogActivityExecuteState(It.IsAny<IDev2Activity>()));

            var environmentId = Guid.Empty;
            User = new Mock<IPrincipal>().Object;
            var dataObject = new DsfDataObject(CurrentDl, ExecutionId)
            {
                ServiceName = workflowName,
                ResourceID = resourceId,
                WorkflowInstanceId = workflowInstanceId,
                WebUrl = url,
                ServerID = Guid.NewGuid(),
                ExecutingUser = User,
                IsDebug = true,
                EnvironmentID = environmentId,
                Environment = env,
                IsRemoteInvokeOverridden = false,
                DataList = new StringBuilder(CurrentDl),
                IsServiceTestExecution = true
            };

            var mockActivity = new Mock<IDev2Activity>();
            mockActivity.Setup(o => o.UniqueID).Returns(nextNodeId.ToString());
            var dev2Activities = new List<IDev2Activity> {mockActivity.Object};
            var activity = CreateWorkflow();
            var activityFunction = new ActivityFunc<string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler = activity,
            };
            var suspendUntil = DateTime.Now.AddDays(1);
            var config = new PersistenceSettings
            {
                Enable = false
            };
            var suspendExecutionActivity = new SuspendExecutionActivity(config, new Mock<IPersistenceExecution>().Object)
            {
                SuspendOption = enSuspendOption.SuspendUntil,
                PersistValue = suspendUntil.ToString(),
                AllowManualResumption = true,
                SaveDataFunc = activityFunction,
                Result = "[[SuspendID]]",
                NextNodes = dev2Activities
            };

            suspendExecutionActivity.SetStateNotifier(mockStateNotifier.Object);
            //------------Execute Test---------------------------
            suspendExecutionActivity.Execute(dataObject, 0);

            //------------Assert Results-------------------------
            suspendExecutionActivity.Execute(dataObject, 0);
            //------------Assert Results-------------------------
            Assert.AreEqual(1, env.AllErrors.Count);
            var errors = env.AllErrors.ToList();
            Assert.AreEqual(ErrorResource.PersistenceSettingsNoConfigured, errors[0]);
        }
Exemple #33
0
        protected override void BuildDataList()
        {
            scenarioContext.TryGetValue("variableList", out List <Tuple <string, string> > variableList);

            if (variableList == null)
            {
                variableList = new List <Tuple <string, string> >();
                scenarioContext.Add("variableList", variableList);
            }

            variableList.Add(new Tuple <string, string>(ResultRecordsetVariable, ""));

            if (scenarioContext.TryGetValue("outMapTo", out string outMapTo))
            {
                variableList.Add(new Tuple <string, string>(outMapTo, ""));
            }

            BuildShapeAndTestData();

            var activityType = scenarioContext.Get <string>("activityType");

            dynamic activity;

            if (activityType.Equals("Tool"))
            {
                activity = new DsfRandomActivity
                {
                    Result     = ResultRecordsetVariable,
                    RandomType = enRandomType.Numbers,
                    From       = "0",
                    To         = "100"
                };
            }
            else
            {
                activity = new DsfActivity
                {
                    InputMapping  = BuildInputMappings(),
                    OutputMapping = BuildOutputMappings(),
                    ServiceName   = "SpecflowForeachActivityTest"
                };
            }

            var activityFunction = new ActivityFunc <string, bool> {
                Handler = activity
            };
            var foreachType = scenarioContext.Get <enForEachType>("foreachType");

            if (!scenarioContext.TryGetValue("recordset", out string recordSet))
            {
                recordSet = string.Empty;
            }

            if (!scenarioContext.TryGetValue("from", out string from))
            {
                from = string.Empty;
            }

            if (!scenarioContext.TryGetValue("to", out string to))
            {
                to = string.Empty;
            }

            if (!scenarioContext.TryGetValue("numberAs", out string numberAs))
            {
                numberAs = string.Empty;
            }

            var dsfForEach = new DsfForEachActivity
            {
                ForEachType    = foreachType,
                Recordset      = recordSet,
                From           = from,
                To             = to,
                CsvIndexes     = numberAs,
                NumOfExections = numberAs,
                DataFunc       = activityFunction
            };

            TestStartNode = new FlowStep
            {
                Action = dsfForEach
            };

            scenarioContext.Add("activity", dsfForEach);
        }
Exemple #34
0
        public void SuspendExecutionActivity_Execute_ServiceTestExecution_Success()
        {
            //------------Setup for test--------------------------
            var workflowName = "workflowName";
            var url = "http://localhost:3142/secure/WorkflowResume";
            var resourceId = Guid.NewGuid();
            var nextNodeId = Guid.NewGuid();
            var workflowInstanceId = Guid.NewGuid();
            var env = CreateExecutionEnvironment();
            env.Assign("[[UUID]]", "public", 0);
            env.Assign("[[JourneyName]]", "whatever", 0);

            var mockStateNotifier = new Mock<IStateNotifier>();
            mockStateNotifier.Setup(stateNotifier => stateNotifier.LogActivityExecuteState(It.IsAny<IDev2Activity>()));

            var environmentId = Guid.Empty;
            var mockPrincipal = new Mock<ClaimsPrincipal>();
            mockPrincipal.Setup(o => o.Identity).Returns(WindowsIdentity.GetCurrent());
            var dataObject = new DsfDataObject(CurrentDl, ExecutionId)
            {
                ServiceName = workflowName,
                ResourceID = resourceId,
                WorkflowInstanceId = workflowInstanceId,
                WebUrl = url,
                ServerID = Guid.NewGuid(),
                ExecutingUser = mockPrincipal.Object,
                IsDebug = true,
                EnvironmentID = environmentId,
                Environment = env,
                IsRemoteInvokeOverridden = false,
                DataList = new StringBuilder(CurrentDl),
                IsServiceTestExecution = true
            };

            var mockActivity = new Mock<IDev2Activity>();
            mockActivity.Setup(o => o.UniqueID).Returns(nextNodeId.ToString());
            var dev2Activities = new List<IDev2Activity> {mockActivity.Object};
            var activity = CreateWorkflow();
            var activityFunction = new ActivityFunc<string, bool>
            {
                DisplayName = activity.DisplayName,
                Handler = activity,
            };
            var config = new PersistenceSettings
            {
                Enable = true
            };
            var expectedSuspendId = Guid.NewGuid().ToString();
            const enSuspendOption suspendOption = enSuspendOption.SuspendForSeconds;
            var mockSuspendExecution = new Mock<IPersistenceExecution>();
            mockSuspendExecution.Setup(o =>
                o.CreateAndScheduleJob(suspendOption, It.IsAny<string>(),
                    It.IsAny<Dictionary<string, StringBuilder>>())).Returns(expectedSuspendId);

            var suspendExecutionActivity = new SuspendExecutionActivity(config, mockSuspendExecution.Object)
            {
                SuspendOption = suspendOption,
                PersistValue = "20",
                AllowManualResumption = true,
                SaveDataFunc = activityFunction,
                Result = "[[SuspendID]]",
                NextNodes = dev2Activities
            };

            suspendExecutionActivity.SetStateNotifier(mockStateNotifier.Object);
            //------------Execute Test---------------------------
            suspendExecutionActivity.Execute(dataObject, 0);

            //------------Assert Results-------------------------
            Assert.AreEqual(0, env.Errors.Count);
            Assert.AreEqual(expectedSuspendId, suspendExecutionActivity.Response);
            Assert.IsFalse(dataObject.StopExecution, "this will Stop Execution for the whole workflow, which is not ideal for the problem we are resolving");
            Assert.IsFalse(dataObject.IsDebugNested);
            Assert.AreEqual(0, dataObject.ForEachNestingLevel);
        }