public void CalculateActivity_MultRecordsetWithStar_WhenMissingValuesError_Expected_SumOf20()
        {
            TestStartNode = new FlowStep
            {
                Action = new DsfAggregateCalculateActivity {
                    Expression = "sum([[rec(*).val]],[[rec(*).val2]])", Result = "[[sumResult]]"
                }
            };

            CurrentDl = "<ADL><rec><val></val><val2/></rec><sumResult></sumResult></ADL>";
            TestData  = "<root><ADL><rec><val>1</val><val2>10</val2></rec><rec><val>2</val></rec><rec><val>3</val></rec><rec><val>4</val></rec></ADL></root>";
            IDSFDataObject result = ExecuteProcess();

            try
            {
                string error;
                string actual;
                GetScalarValueFromEnvironment(result.Environment, "sumResult", out actual, out error);
            }
            catch (Exception e)
            {
                StringAssert.Contains(e.Message, "No Value assigned for: [[sumResult]]");
            }
        }
        public void RecursiveEvaluateRecordset_WhenDataContainsQuotes_ShouldEvaluateWithoutExtraEscaping()
        {
            var fieldCollection = new ObservableCollection <ActivityDTO>();

            fieldCollection.Add(new ActivityDTO("[[gRec(1).opt]]", "\"testData\"", fieldCollection.Count));
            fieldCollection.Add(new ActivityDTO("[[gRec(2).opt]]", "some value [[gRec(1).opt]] another", fieldCollection.Count));

            TestStartNode = new FlowStep
            {
                Action = new DsfMultiAssignActivity {
                    OutputMapping = null, FieldsCollection = fieldCollection
                }
            };

            SetupArguments(
                ActivityStrings.MultiAssignStarDataListWithScalar
                , ActivityStrings.MultiAssignStarDataListWithScalar
                , fieldCollection);
            var result = ExecuteProcess();
            var actual = RetrieveAllRecordSetFieldValues(result.Environment, "gRec", "opt", out string error);

            // remove test datalist ;)
            Assert.AreEqual("some value \"testData\" another", actual[1]);
        }
Beispiel #3
0
        public void FlowDecisionConditionMustBeSet()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Act.Flowchart prod = flowchart.ProductActivity as Act.Flowchart;

            FlowStep     step;
            FlowDecision decision = new FlowDecision {
                True = step = new FlowStep {
                    Action = new WriteLine {
                        Text = "Dummy"
                    }
                }
            };

            prod.StartNode = decision;
            prod.Nodes.Add(step);

            List <string> errors = new List <string>();

            errors.Add(string.Format(ErrorStrings.FlowDecisionRequiresCondition, prod.DisplayName));

            Validate(flowchart, errors);
        }
        public void DsfSortRecordsActivity_Execute_SingleRecordSetRuleCalled_ExpectNoResultsSortFieldIncorrect()
        {
            TestStartNode = new FlowStep
            {
                Action = new DsfSortRecordsActivity {
                    SortField = "[[recset()]]", SelectedSort = "Forward"
                }
            };

            var act = SetupArgumentsReturnObj(
                ActivityStrings.SortDataList_Shape
                , ActivityStrings.SortDataList
                , "[[recset()]]"
                , "Forward"

                );
            IDSFDataObject result = ExecuteProcess(isDebug: true);

            // remove test datalist ;)
            DataListRemoval(result.DataListID);
            var debugOut = act.GetDebugOutputs(null);

            Assert.AreEqual(0, debugOut.Count);
        }
        public void FieldSpecifiedSortForwards_Numeric_GapsInNonSortedField_Expected_Recordset_Sorted_Top_To_Bottom()
        {
            TestStartNode = new FlowStep
            {
                Action = new DsfSortRecordsActivity {
                    SortField = "[[recset().Id]]", SelectedSort = "Forward"
                }
            };

            SetupArguments(
                ActivityStrings.SortDataList_Shape
                , ActivityStrings.SortDataListGaps
                , "[[recset().Id]]"
                , "Forward"
                );
            IDSFDataObject result   = ExecuteProcess();
            List <string>  expected = new List <string> {
                ""
                , ""
                , "1"
                , "1"
                , "2"
                , "3"
                , "6"
                , "7"
                , "9"
                , "10"
            };
            string        error;
            List <string> actual = RetrieveAllRecordSetFieldValues(result.DataListID, "recset", "Id", out error);

            // remove test datalist ;)
            DataListRemoval(result.DataListID);

            CollectionAssert.AreEqual(expected, actual, new ActivityUnitTests.Utils.StringComparer());
        }
        public void SortActivity_DateTimeSortForward_Expected_RecordSetSortedAscendingDateTime()
        {
            TestStartNode = new FlowStep
            {
                Action = new DsfSortRecordsActivity {
                    SortField = "[[recset().Time]]", SelectedSort = "Forward"
                }
            };

            SetupArguments(
                ActivityStrings.SortDataList_Shape
                , ActivityStrings.SortDataList
                , "[[recset().Time]]"
                , "Forward"
                );
            IDSFDataObject result   = ExecuteProcess();
            List <string>  expected = new List <string> {
                "Monday, November 17, 2008 02:11:59 AM"
                , "Monday, November 17, 2008 04:11:59 AM"
                , "Monday, November 17, 2008 05:11:59 AM"
                , "Monday, November 17, 2008 09:11:59 AM"
                , "Monday, November 17, 2008 10:11:59 AM"
                , "Monday, November 17, 2008 11:11:59 AM"
                , "Monday, November 17, 2008 05:11:59 PM"
                , "Monday, November 17, 2008 11:10:59 PM"
                , "Sunday, November 30, 2008 05:11:59 PM"
                , "Wednesday, June 27, 2012 08:10:00 AM"
            };
            string        error;
            List <string> actual = RetrieveAllRecordSetFieldValues(result.DataListID, "recset", "Time", out error);

            // remove test datalist ;)
            DataListRemoval(result.DataListID);

            CollectionAssert.AreEqual(expected, actual, new ActivityUnitTests.Utils.StringComparer());
        }
        public void String_ForwardSort_String_Expected_RecordSetSortedAscending()
        {
            TestStartNode = new FlowStep
            {
                Action = new DsfSortRecordsActivity {
                    SortField = "[[recset().Name]]", SelectedSort = "Forward"
                }
            };

            SetupArguments(
                ActivityStrings.SortDataList_Shape
                , ActivityStrings.SortDataList
                , "[[recset().Name]]"
                , "Forward"
                );
            IDSFDataObject result   = ExecuteProcess();
            List <string>  expected = new List <string> {
                "A"
                , "A"
                , "A"
                , "B"
                , "C"
                , "F"
                , "F"
                , "L"
                , "Y"
                , "Z"
            };
            string        error;
            List <string> actual = RetrieveAllRecordSetFieldValues(result.DataListID, "recset", "Name", out error);

            // remove test datalist ;)
            DataListRemoval(result.DataListID);

            CollectionAssert.AreEqual(expected, actual, new ActivityUnitTests.Utils.StringComparer());
        }
        public void WebGetRequestExecuteWhereErrorExpectErrorAdded()
        {
            //------------Setup for test--------------------------
            var          mock    = new Mock <IWebRequestInvoker>();
            const string Message = "This is a forced exception";

            mock.Setup(invoker => invoker.ExecuteRequest(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <List <Tuple <string, string> > >(), It.IsAny <int>())).Throws(new InvalidDataException(Message));
            var activity = GetWebGetRequestWithTimeoutActivity(mock);

            activity.Method = "GET";
            activity.Url    = "BodyValue";
            TestStartNode   = new FlowStep
            {
                Action = activity
            };
            TestData = "<root><testVar /></root>";
            //------------Execute Test---------------------------
            ExecuteProcess();
            //------------Assert Results-------------------------
            mock.Verify(sender => sender.ExecuteRequest(activity.Method, activity.Url, It.IsAny <List <Tuple <string, string> > >(), It.IsAny <int>()), Times.Once());
            var errorString = DataObject.Environment.FetchErrors();

            StringAssert.Contains(errorString, Message);
        }
Beispiel #9
0
        protected override void BuildDataList()
        {
            ErrorResultTO errors;
            var           compiler   = DataListFactory.CreateDataListCompiler();
            var           webService = ScenarioContext.Current.Get <Runtime.ServiceModel.Data.WebService>("WebService");

            webService.ResourceID   = Guid.NewGuid();
            webService.ResourceName = "Google Maps Service";
            ResourceCatalog.Instance.SaveResource(Guid.Empty, webService.Source);
            ResourceCatalog.Instance.SaveResource(Guid.Empty, webService);
            var shape = compiler.ShapeDev2DefinitionsToDataList(webService.OutputSpecification, enDev2ArgumentType.Output, false, out errors);

            var dataListId = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), "", shape, out errors);
            var dataObj    = new Mock <IDSFDataObject>();

            dataObj.SetupAllProperties();
            dataObj.Setup(d => d.DataListID).Returns(dataListId);
            dataObj.Setup(d => d.ResourceID).Returns(webService.ResourceID);
            dataObj.Setup(d => d.ServiceName).Returns(webService.ResourceName);
            dataObj.Setup(d => d.ParentThreadID).Returns(9);
            dataObj.Setup(d => d.WorkspaceID).Returns(Guid.Empty);
            dataObj.Setup(d => d.IsDebugMode()).Returns(true);

            var webServiceActivity = new DsfWebserviceActivity {
                OutputMapping = webService.OutputSpecification
            };

            ExecutionId   = dataListId;
            CurrentDl     = shape.ToString();
            TestData      = "";
            TestStartNode = new FlowStep
            {
                Action = webServiceActivity
            };
            ScenarioContext.Current.Add("dataObject", dataObj.Object);
        }
Beispiel #10
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);
            }
            var resultVariable = ResultVariable;

            if (scenarioContext.TryGetValue("resVar", out string resVar))
            {
                resultVariable = resVar;
            }
            variableList.Add(new Tuple <string, string>(resultVariable, ""));
            BuildShapeAndTestData();

            scenarioContext.TryGetValue("header", out string header);
            scenarioContext.TryGetValue("url", out string url);
            scenarioContext.TryGetValue("timeoutSeconds", out string timeout);
            var webGet = new DsfWebGetRequestWithTimeoutActivity
            {
                Result         = resultVariable,
                Url            = url ?? "",
                Headers        = header ?? "",
                TimeoutSeconds = String.IsNullOrEmpty(timeout) ? 100 : int.Parse(timeout),
                TimeOutText    = String.IsNullOrEmpty(timeout) ? "" : timeout
            };

            TestStartNode = new FlowStep
            {
                Action = webGet
            };
            scenarioContext.Add("activity", webGet);
        }
Beispiel #11
0
        protected override void BuildDataList()
        {
            BuildShapeAndTestData();

            string privateKeyFile;

            scenarioContext.TryGetValue(CommonSteps.DestinationPrivateKeyFile, out privateKeyFile);
            var create = new DsfPathCreate
            {
                OutputPath     = scenarioContext.Get <string>(CommonSteps.DestinationHolder),
                Username       = scenarioContext.Get <string>(CommonSteps.DestinationUsernameHolder).ResolveDomain(),
                Password       = scenarioContext.Get <string>(CommonSteps.DestinationPasswordHolder),
                Overwrite      = scenarioContext.Get <bool>(CommonSteps.OverwriteHolder),
                Result         = scenarioContext.Get <string>(CommonSteps.ResultVariableHolder),
                PrivateKeyFile = privateKeyFile
            };

            TestStartNode = new FlowStep
            {
                Action = create
            };

            scenarioContext.Add("activity", create);
        }
Beispiel #12
0
        public void DsfActivity_OnExecute_WhenLocalExecutionInLocalContext_ExpectEnviromentIDRemainsLocalAndOverrideSetToFalse()
        {
            //------------Setup for test--------------------------
            var         resourceID    = Guid.NewGuid();
            var         environmentID = Guid.Empty;
            DsfActivity act           = new DsfActivity
            {
                ResourceID    = new InArgument <Guid>(resourceID),
                EnvironmentID = Guid.Empty
            };
            var mockAutorizationService = new Mock <IAuthorizationService>();

            mockAutorizationService.Setup(service => service.IsAuthorized(It.IsAny <IPrincipal>(), AuthorizationContext.Execute, resourceID.ToString())).Returns(true);
            act.AuthorizationService = mockAutorizationService.Object;

            //------------Execute Test---------------------------
            TestStartNode = new FlowStep
            {
                Action = act
            };

            TestData  = "<DataList></DataList>";
            CurrentDl = "<DataList></DataList>";
            User      = new Mock <IPrincipal>().Object;
            var result = ExecuteProcess(null, true, null, false, true, false, environmentID);

            // ReSharper disable PossibleNullReferenceException
            var resultEnvironmentID = result.EnvironmentID;
            var isRemoteOverridden  = result.IsRemoteInvokeOverridden;

            // ReSharper restore PossibleNullReferenceException

            //------------Assert Results-------------------------
            Assert.AreEqual(environmentID, resultEnvironmentID);
            Assert.IsFalse(isRemoteOverridden);
        }
Beispiel #13
0
        protected override void BuildDataList()
        {
            if (!scenarioContext.ContainsKey("activity"))
            {
                BuildShapeAndTestData();

                scenarioContext.TryGetValue(CommonSteps.SourcePrivatePublicKeyFile, out string privateKeyFile);
                var delete = new DsfPathDelete
                {
                    InputPath      = scenarioContext.Get <string>(CommonSteps.SourceHolder),
                    Username       = scenarioContext.Get <string>(CommonSteps.SourceUsernameHolder).ResolveDomain(),
                    Password       = scenarioContext.Get <string>(CommonSteps.SourcePasswordHolder),
                    Result         = scenarioContext.Get <string>(CommonSteps.ResultVariableHolder),
                    PrivateKeyFile = privateKeyFile
                };

                TestStartNode = new FlowStep
                {
                    Action = delete
                };

                scenarioContext.Add("activity", delete);
            }
        }
Beispiel #14
0
        public void OnExecuteWhereConsoleOutputsExpectOutputForResultCmddirc()
        {
            //------------Setup for test--------------------------
            var          activity     = new DsfExecuteCommandLineActivity();
            const string RandomString = @"cmd.exe /c dir C:\";

            activity.CommandFileName = RandomString;
            activity.CommandResult   = "[[OutVar1]]";
            TestStartNode            = new FlowStep
            {
                Action = activity
            };
            TestData = "<root><OutVar1 /></root>";
            //------------Execute Test---------------------------
            var result = ExecuteProcess();

            //------------Assert Results-------------------------
            Assert.IsTrue(result.Environment.HasErrors());
            var fetchErrors = DataObject.Environment.FetchErrors();

            // remove test datalist ;)

            StringAssert.Contains(fetchErrors, "Cannot execute CMD from tool.");
        }
Beispiel #15
0
        protected override void BuildDataList()
        {
            BuildShapeAndTestData();


            var create = new DsfPathCopy
            {
                InputPath           = ScenarioContext.Current.Get <string>(CommonSteps.SourceHolder),
                Username            = ScenarioContext.Current.Get <string>(CommonSteps.SourceUsernameHolder),
                Password            = ScenarioContext.Current.Get <string>(CommonSteps.SourcePasswordHolder),
                OutputPath          = ScenarioContext.Current.Get <string>(CommonSteps.DestinationHolder),
                DestinationUsername = ScenarioContext.Current.Get <string>(CommonSteps.DestinationUsernameHolder),
                DestinationPassword = ScenarioContext.Current.Get <string>(CommonSteps.DestinationPasswordHolder),
                Overwrite           = ScenarioContext.Current.Get <bool>(CommonSteps.OverwriteHolder),
                Result = ScenarioContext.Current.Get <string>(CommonSteps.ResultVariableHolder)
            };

            TestStartNode = new FlowStep
            {
                Action = create
            };

            ScenarioContext.Current.Add("activity", create);
        }
Beispiel #16
0
        public void OnExecute_WhereConsolePathStartsWithCmd_ShouldError()
        {
            //------------Setup for test--------------------------
            var activity = new DsfExecuteCommandLineActivity {
                CommandFileName = "cmd  C:\\", CommandResult = "[[OutVar1]]"
            };

            TestStartNode = new FlowStep
            {
                Action = activity
            };
            TestData = "<root><OutVar1 /></root>";
            //------------Execute Test---------------------------
            var result = ExecuteProcess();
            //------------Assert Results-------------------------
            var fetchErrors = result.Environment.FetchErrors();

            if (fetchErrors == string.Empty)
            {
                Assert.Fail("no error");
            }

            StringAssert.Contains(fetchErrors, "Cannot execute CMD from tool.");
        }
Beispiel #17
0
        protected override void BuildDataList()
        {
            BuildShapeAndTestData();
            CopyZipFileToSourceLocation();
            var unzip = new DsfUnZip
            {
                InputPath           = ScenarioContext.Current.Get <string>(CommonSteps.SourceHolder),
                Username            = ScenarioContext.Current.Get <string>(CommonSteps.SourceUsernameHolder),
                Password            = ScenarioContext.Current.Get <string>(CommonSteps.SourcePasswordHolder),
                OutputPath          = ScenarioContext.Current.Get <string>(CommonSteps.DestinationHolder),
                DestinationUsername = ScenarioContext.Current.Get <string>(CommonSteps.DestinationUsernameHolder),
                DestinationPassword = ScenarioContext.Current.Get <string>(CommonSteps.DestinationPasswordHolder),
                Overwrite           = ScenarioContext.Current.Get <bool>(CommonSteps.OverwriteHolder),
                Result          = ScenarioContext.Current.Get <string>(CommonSteps.ResultVariableHolder),
                ArchivePassword = ScenarioContext.Current.Get <string>("archivePassword")
            };

            TestStartNode = new FlowStep
            {
                Action = unzip
            };

            ScenarioContext.Current.Add("activity", unzip);
        }
Beispiel #18
0
        public void ConflictModelFactory_GivenAssignConflictNode_ShouldReturnMergeToolModel()
        {
            //------------Setup for test--------------------------
            var adapter = new Mock <IApplicationAdaptor>();

            adapter.Setup(p => p.TryFindResource(It.IsAny <object>())).Returns(new object());
            CustomContainer.Register(adapter.Object);
            var node = new Mock <IConflictTreeNode>();
            var contextualResource = new Mock <IContextualResourceModel>();
            var value      = new DsfMultiAssignActivity();
            var assignStep = new FlowStep
            {
                Action = value
            };

            node.Setup(p => p.Activity).Returns(value);
            var toolConflictItem = new ToolConflictItem(new ViewModels.Merge.Utils.ConflictRowList(new Mock <IConflictModelFactory>().Object, new Mock <IConflictModelFactory>().Object, new List <ConflictTreeNode>(), new List <ConflictTreeNode>()), ViewModels.Merge.Utils.ConflictRowList.Column.Current);
            //------------Execute Test---------------------------
            var completeConflict = new ConflictModelFactory(toolConflictItem, contextualResource.Object, node.Object);

            //------------Assert Results-------------------------
            Assert.IsNotNull(completeConflict);
            adapter.Verify(p => p.TryFindResource(It.IsAny <object>()));
        }
Beispiel #19
0
 private FlowStep GetNextFlowStep(WorkflowActivity workflow, FlowStep step)
 {
     var flowSwitch = step.Next as FlowSwitch<string>;
     return flowSwitch.Cases.Count > 0
         ? flowSwitch.Cases.First().Value as FlowStep
         : flowSwitch.Default as FlowStep;
 }
Beispiel #20
0
        private static Activity CreateFlowchartWithFaults(string promoCode, int numKids)
        {
            Variable <string> promo = new Variable <string> {
                Default = promoCode
            };
            Variable <int> numberOfKids = new Variable <int> {
                Default = numKids
            };
            Variable <double> discount = new Variable <double>();
            DelegateInArgument <DivideByZeroException> ex = new DelegateInArgument <DivideByZeroException>();

            FlowStep discountNotApplied = new FlowStep
            {
                Action = new WriteLine
                {
                    DisplayName = "WriteLine: Discount not applied",
                    Text        = "Discount not applied"
                },
                Next = null
            };

            FlowStep discountApplied = new FlowStep
            {
                Action = new WriteLine
                {
                    DisplayName = "WriteLine: Discount applied",
                    Text        = "Discount applied "
                },
                Next = null
            };
//<Snippet3>
            FlowDecision flowDecision = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => discount.Get(ctx) > 0),
                True      = discountApplied,
                False     = discountNotApplied
            };
//</Snippet3>
//<Snippet4>
            FlowStep singleStep = new FlowStep
            {
                Action = new Assign
                {
                    DisplayName = "discount = 10.0",
                    To          = new OutArgument <double> (discount),
                    Value       = new InArgument <double> (10.0)
                },
                Next = flowDecision
            };
//</Snippet4>

            FlowStep mnkStep = new FlowStep
            {
                Action = new Assign
                {
                    DisplayName = "discount = 15.0",
                    To          = new OutArgument <double> (discount),
                    Value       = new InArgument <double> (15.0)
                },
                Next = flowDecision
            };

//<Snippet1>
            FlowStep mwkStep = new FlowStep
            {
                Action = new TryCatch
                {
                    DisplayName = "Try/Catch for Divide By Zero Exception",
                    Try         = new Assign
                    {
                        DisplayName = "discount = 15 + (1 - 1/numberOfKids)*10",
                        To          = new OutArgument <double>(discount),
                        Value       = new InArgument <double>((ctx) => (15 + (1 - 1 / numberOfKids.Get(ctx)) * 10))
                    },
                    Catches =
                    {
                        new Catch <System.DivideByZeroException>
                        {
                            Action = new ActivityAction <System.DivideByZeroException>
                            {
                                Argument    = ex,
                                DisplayName = "ActivityAction - DivideByZeroException",
                                Handler     =
                                    new Sequence
                                {
                                    DisplayName = "Divide by Zero Exception Workflow",
                                    Activities  =
                                    {
                                        new WriteLine()
                                        {
                                            DisplayName = "WriteLine: DivideByZeroException",
                                            Text        = "DivideByZeroException: Promo code is MWK - but number of kids = 0"
                                        },
                                        new Assign <double>
                                        {
                                            DisplayName = "Exception - discount = 0",
                                            To          = discount,
                                            Value       = new InArgument <double>(0)
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                Next = flowDecision
            };
//</Snippet1>

            FlowStep discountDefault = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Default discount assignment: discount = 0",
                    To          = discount,
                    Value       = new InArgument <double>(0)
                },
                Next = flowDecision
            };
//<Snippet5>
            FlowSwitch <string> promoCodeSwitch = new FlowSwitch <string>
            {
                Expression = promo,
                Cases      =
                {
                    { "Single", singleStep },
                    { "MNK",    mnkStep    },
                    { "MWK",    mwkStep    }
                },
                Default = discountDefault
            };
//</Snippet5>
//<Snippet2>
            Flowchart flowChart = new Flowchart
            {
                DisplayName = "Promotional Discount Calculation",
                Variables   = { discount, promo, numberOfKids },
                StartNode   = promoCodeSwitch,
                Nodes       =
                {
                    promoCodeSwitch,
                    singleStep,
                    mnkStep,
                    mwkStep,
                    discountDefault,
                    flowDecision,
                    discountApplied,
                    discountNotApplied
                }
            };

//</Snippet2>
            return(flowChart);
        }
Beispiel #21
0
 public TestFlowStep()
 {
     _productFlowStep = new FlowStep();
 }
Beispiel #22
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);
        }
        void Verify_Execute_FromAccount_EmailSourceIsCorrect(bool isFromAccountGiven)
        {
            //------------Setup for test--------------------------
            const string TestSourceAccount  = "*****@*****.**";
            const string TestSourcePassword = "******";
            const string TestFromAccount    = "*****@*****.**";
            const string TestFromPassword   = "******";

            var testSource = new EmailSource
            {
                Host         = "TestHost",
                UserName     = TestSourceAccount,
                Password     = TestSourcePassword,
                ResourceName = Guid.NewGuid().ToString(),
                ResourceID   = Guid.NewGuid()
            };

            ResourceCatalog.Instance.SaveResource(Guid.Empty, testSource, "");
            EmailSource sendSource  = null;
            MailMessage sendMessage = null;
            var         emailSender = new Mock <IEmailSender>();

            emailSender.Setup(sender => sender.Send(It.IsAny <EmailSource>(), It.IsAny <MailMessage>()))
            .Callback <EmailSource, MailMessage>((source, message) =>
            {
                sendSource  = source;
                sendMessage = message;
            });

            var activity = GetSendEmailActivity(emailSender);

            activity.SelectedEmailSource = testSource;
            activity.Body    = "Hello world";
            activity.To      = "*****@*****.**";
            activity.Subject = "This is the subject!";
            if (isFromAccountGiven)
            {
                activity.FromAccount = TestFromAccount;
                activity.Password    = TestFromPassword;
            }
            else
            {
                activity.FromAccount = string.Empty;
                activity.Password    = string.Empty;
            }

            TestStartNode = new FlowStep
            {
                Action = activity
            };
            TestData  = "<root></root>";
            CurrentDl = "<ADL></ADL>";
            var esbChannelMock = CreateMockEsbChannel();

            //------------Execute Test---------------------------
            ExecuteProcess(channel: esbChannelMock.Object, isDebug: true);

            // remove test datalist ;)

            //------------Assert Results-------------------------
            emailSender.Verify(sender => sender.Send(It.IsAny <EmailSource>(), It.IsAny <MailMessage>()), Times.Once());
            Assert.IsNotNull(sendSource);
            Assert.IsNotNull(sendMessage);
            Assert.AreNotSame(testSource, sendSource);
            if (isFromAccountGiven)
            {
                Assert.AreEqual(TestFromAccount, sendSource.UserName);
                Assert.AreEqual(TestFromPassword, sendSource.Password);
                Assert.AreEqual(TestFromAccount, sendMessage.From.Address);
            }
            else
            {
                Assert.AreEqual(TestSourceAccount, sendSource.UserName);
                Assert.AreEqual(TestSourcePassword, sendSource.Password);
                Assert.AreEqual(TestSourceAccount, sendMessage.From.Address);
            }
        }
        public void SetupScenerio()
        {
            _containerOps = new Depends(Depends.ContainerType.MSSQL);
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource(_containerOps.Container.IP, int.Parse(_containerOps.Container.Port));

            ResourceCatalog.Instance.SaveResource(Guid.Empty, dbSource, "");
            scenarioContext.Add("dbSource", dbSource);

            var sqlBulkInsert = new DsfSqlBulkInsertActivity();

            sqlBulkInsert.Database  = dbSource;
            sqlBulkInsert.TableName = "SqlBulkInsertSpecFlowTestTable_for_" + scenarioContext.ScenarioInfo.Title.Replace(' ', '_');
            if (scenarioContext.ScenarioInfo.Title.Replace(' ', '_') == "Import_data_into_Table_Batch_size_is_1")
            {
                var tableNameUniqueNameGuid = CommonSteps.GetGuid();
                CreateIsolatedSQLTable(tableNameUniqueNameGuid);
                scenarioContext.Add("tableNameUniqueNameGuid", tableNameUniqueNameGuid);
                sqlBulkInsert.TableName += "_" + tableNameUniqueNameGuid;
            }
            var dataColumnMappings = new List <DataColumnMapping>
            {
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col1]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col1",
                        DataType   = typeof(Int32),
                        MaxLength  = 100
                    },
                },
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col2]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col2",
                        DataType   = typeof(String),
                        MaxLength  = 100
                    }
                },
                new DataColumnMapping
                {
                    InputColumn  = "[[rs(*).Col3]]",
                    OutputColumn = new DbColumn
                    {
                        ColumnName = "Col3",
                        DataType   = typeof(Guid),
                        MaxLength  = 100
                    }
                }
            };

            sqlBulkInsert.InputMappings = dataColumnMappings;
            TestStartNode = new FlowStep
            {
                Action = sqlBulkInsert
            };

            scenarioContext.Add("activity", sqlBulkInsert);
        }
Beispiel #25
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>(ResultVariable, ""));
            BuildShapeAndTestData();

            scenarioContext.TryGetValue("scriptToExecute", out string scriptToExecute);
            scenarioContext.TryGetValue("language", out enScriptType language);
            scenarioContext.TryGetValue("javascript", out DsfJavascriptActivity javascriptActivity);

            if (javascriptActivity != null)
            {
                javascriptActivity.Script = scriptToExecute;
                javascriptActivity.Result = ResultVariable;

                TestStartNode = new FlowStep
                {
                    Action = javascriptActivity
                };
                scenarioContext.Add("activity", javascriptActivity);
                return;
            }

            _featureContext.TryGetValue("pythonActivity", out DsfPythonActivity pythonActivity);

            if (pythonActivity != null)
            {
                pythonActivity.Script = scriptToExecute;
                pythonActivity.Result = ResultVariable;

                TestStartNode = new FlowStep
                {
                    Action = pythonActivity
                };
                scenarioContext.Add("activity", pythonActivity);
                return;
            }

            _featureContext.TryGetValue("rubyActivity", out DsfRubyActivity rubyActivity);

            if (rubyActivity != null)
            {
                rubyActivity.Script = scriptToExecute;
                rubyActivity.Result = ResultVariable;

                TestStartNode = new FlowStep
                {
                    Action = rubyActivity
                };
                scenarioContext.Add("activity", rubyActivity);
                return;
            }

            var dsfScripting = new DsfScriptingActivity
            {
                Script     = scriptToExecute,
                ScriptType = language,
                Result     = ResultVariable
            };

            TestStartNode = new FlowStep
            {
                Action = dsfScripting
            };
            scenarioContext.Add("activity", dsfScripting);
        }
Beispiel #26
0
        //得到自定义流程图
        public static flowcharStruct getFlowcharStruct(string xaml)
        {
            char[] sp = { ',' };
            char[] sl = { ' ' };
            //(1)
            WorkflowStruct.flowcharStruct flowcharStruct = new WorkflowStruct.flowcharStruct();

            //(2)
            DynamicActivity dynamicActivity = tool.activityByXaml(xaml) as DynamicActivity;
            Activity        activity        = tool.getImplementation(dynamicActivity);
            Flowchart       flowchar        = activity as Flowchart;

            if (flowchar == null)
            {
                return(null);
            }

            //(3)=====================================

            //(3.1)----------------------------------------------------------------------------------
            flowcharStruct.beginNode.DisplayName = "开始";
            flowcharStruct.beginNode.id          = "begin";

            //(3.1.1)
            if (WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"] != null)
            {
                string ShapeLocation = WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"].ToString();
                flowcharStruct.beginNode.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]);
                flowcharStruct.beginNode.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]);
            }

            //(3.1.2)
            if (WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"] != null)
            {
                string ShapeSize = WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"].ToString();
                flowcharStruct.beginNode.ShapeSize.width  = double.Parse(ShapeSize.Split(sp)[0]);
                flowcharStruct.beginNode.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]);
            }

            //(3.1.3)
            if (WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"] != null)
            {
                string              ConnectorLocation = WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"].ToString();
                string[]            points            = ConnectorLocation.Split(sl);
                WorkflowStruct.line oneline           = new WorkflowStruct.line();
                oneline.beginNodeID = flowchar.Id;
                oneline.text        = flowchar.DisplayName;
                foreach (string item in points)
                {
                    double x = double.Parse(item.Split(sp)[0]);
                    double y = double.Parse(item.Split(sp)[1]);
                    oneline.connectorPoint.Add(new WorkflowStruct.point()
                    {
                        x = x, y = y
                    });
                }
                flowcharStruct.lineList.Add(oneline);
            }

            //(3.2)--------------------------------------------------------------------------------
            foreach (FlowNode flowNode in flowchar.Nodes)
            {
                FlowStep flowStep = flowNode as FlowStep;
                if (flowStep != null)
                {
                    WorkflowStruct.node node = new WorkflowStruct.node();

                    node.DisplayName = flowStep.Action.DisplayName;
                    node.id          = flowStep.Action.Id;

                    //(3.2.1)
                    if (WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"] != null)
                    {
                        string ShapeLocation = WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"].ToString();
                        node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]);
                        node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]);
                    }

                    //(3.2.2)
                    if (WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"] != null)
                    {
                        string ShapeSize = WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"].ToString();
                        node.ShapeSize.width  = double.Parse(ShapeSize.Split(sp)[0]);
                        node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]);
                    }

                    //(3.2.3)
                    if (WorkflowViewStateService.GetViewState(flowStep).Count(p => p.Key == "ConnectorLocation") == 1)
                    {
                        string              ConnectorLocation = WorkflowViewStateService.GetViewState(flowStep)["ConnectorLocation"].ToString();
                        string[]            points            = ConnectorLocation.Split(sl);
                        WorkflowStruct.line line = new WorkflowStruct.line();
                        line.beginNodeID = flowStep.Action.Id;
                        line.text        = flowStep.Action.DisplayName;
                        foreach (string item in points)
                        {
                            double x = double.Parse(item.Split(sp)[0]);
                            double y = double.Parse(item.Split(sp)[1]);
                            line.connectorPoint.Add(new WorkflowStruct.point()
                            {
                                x = x, y = y
                            });
                        }
                        flowcharStruct.lineList.Add(line);
                    }

                    flowcharStruct.nodeList.Add(node);
                }
            }

            //(3.3)-------------------------------------------------------------
            foreach (FlowNode flowNode in flowchar.Nodes)
            {
                FlowSwitch <string> flowSwitch = flowNode as FlowSwitch <string>;

                if (flowSwitch != null)
                {
                    WorkflowStruct.node node = new WorkflowStruct.node();

                    node.DisplayName = flowSwitch.Expression.DisplayName;
                    node.id          = flowSwitch.Expression.Id;

                    //(3.3.1)
                    if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"] != null)
                    {
                        string ShapeLocation = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"].ToString();
                        node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]);
                        node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]);
                    }

                    //(3.3.2)
                    if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"] != null)
                    {
                        string ShapeSize = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"].ToString();
                        node.ShapeSize.width  = double.Parse(ShapeSize.Split(sp)[0]);
                        node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]);
                    }

                    //(3.3.3)

                    if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == "Default") == 1)
                    {
                        string              ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)["Default"].ToString();
                        string[]            points            = ConnectorLocation.Split(sl);
                        WorkflowStruct.line line = new WorkflowStruct.line();
                        line.beginNodeID = flowSwitch.Expression.Id;
                        line.text        = flowSwitch.Expression.DisplayName;
                        foreach (string item in points)
                        {
                            double x = double.Parse(item.Split(sp)[0]);
                            double y = double.Parse(item.Split(sp)[1]);
                            line.connectorPoint.Add(new WorkflowStruct.point()
                            {
                                x = x, y = y
                            });
                        }
                        flowcharStruct.lineList.Add(line);
                    }

                    //(3.3.4)
                    foreach (var v in flowSwitch.Cases)
                    {
                        System.Activities.Statements.FlowNode next = v.Value;
                        System.Console.WriteLine(v.Key);
                        string caseValue = v.Key + "Connector";
                        if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == caseValue) == 1)
                        {
                            string              ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)[caseValue].ToString();
                            string[]            points            = ConnectorLocation.Split(sl);
                            WorkflowStruct.line line = new WorkflowStruct.line();
                            line.beginNodeID = flowSwitch.Expression.Id;
                            line.text        = flowSwitch.Expression.DisplayName;
                            foreach (string item in points)
                            {
                                double x = double.Parse(item.Split(sp)[0]);
                                double y = double.Parse(item.Split(sp)[1]);
                                line.connectorPoint.Add(new WorkflowStruct.point()
                                {
                                    x = x, y = y
                                });
                            }
                            flowcharStruct.lineList.Add(line);
                        }
                    }
                    flowcharStruct.nodeList.Add(node);
                }
            }

            return(flowcharStruct);
        }//end
Beispiel #27
0
        protected override void BuildDataList()
        {
            List <Tuple <string, string> > variableList;

            ScenarioContext.Current.TryGetValue("variableList", out variableList);

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

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

            string body;

            ScenarioContext.Current.TryGetValue("body", out body);
            string subject;

            ScenarioContext.Current.TryGetValue("subject", out subject);
            string fromAccount;

            ScenarioContext.Current.TryGetValue("fromAccount", out fromAccount);
            string password;

            ScenarioContext.Current.TryGetValue("password", out password);
            string simulationOutput;

            ScenarioContext.Current.TryGetValue("simulationOutput", out simulationOutput);
            string to;

            ScenarioContext.Current.TryGetValue("to", out to);
            bool isHtml;

            ScenarioContext.Current.TryGetValue("isHtml", out isHtml);

            var server = SimpleSmtpServer.Start(25);

            ScenarioContext.Current.Add("server", server);

            var selectedEmailSource = new EmailSource
            {
                Host         = "localhost",
                Port         = 25,
                UserName     = "",
                Password     = "",
                ResourceName = Guid.NewGuid().ToString(),
                ResourceID   = Guid.NewGuid()
            };

            ResourceCatalog.Instance.SaveResource(Guid.Empty, selectedEmailSource);
            var sendEmail = new DsfSendEmailActivity
            {
                Result              = ResultVariable,
                Body                = string.IsNullOrEmpty(body) ? "" : body,
                Subject             = string.IsNullOrEmpty(subject) ? "" : subject,
                FromAccount         = string.IsNullOrEmpty(fromAccount) ? "" : fromAccount,
                To                  = string.IsNullOrEmpty(to) ? "" : to,
                SelectedEmailSource = selectedEmailSource,
                IsHtml              = isHtml
            };

            TestStartNode = new FlowStep
            {
                Action = sendEmail
            };
            ScenarioContext.Current.Add("activity", sendEmail);
        }
Beispiel #28
0
 /// <summary>
 /// Executes the step only if the condition returns true.
 /// </summary>
 public static FlowStep If(Func <Context, bool> condition, FlowStep step) =>
 (Context context) => condition(context) ? step(context) : context;
Beispiel #29
0
 /// <summary>
 /// Executes the step only if the condition is true.
 /// </summary>
 public static FlowStep If(bool condition, FlowStep step) =>
 (Context context) => condition?step(context) : context;
Beispiel #30
0
        /// <summary>
        /// 创建SubProcess子流程节点
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="displayName"></param>
        /// <param name="serverScript">节点执行内容脚本</param>
        /// <param name="finishRule">节点完成规则</param>
        /// <param name="serverScriptResultTo">执行内容的结果输出到指定变量</param>
        /// <param name="serverResultTo">节点执行结果输出到变量</param>
        /// <param name="nexts"></param>
        /// <param name="defaultFlowNode"></param>
        /// <returns></returns>
        public static FlowStep CreateSubProcess(ActivitySetting setting
            , string displayName
            , IDictionary<string, string> finishRule
            , Variable<string> resultTo
            , IDictionary<string, FlowNode> nexts
            , FlowNode defaultFlowNode)
        {
            var server = CreateSubProcess(setting, displayName, finishRule, resultTo);
            var step = new FlowStep();
            step.Action = server;

            if (nexts == null && defaultFlowNode == null) return step;

            //设置finish cases
            var flowSwitch = new FlowSwitch<string>(o => resultTo.Get(o));
            if (defaultFlowNode != null)
                flowSwitch.Default = defaultFlowNode;
            if (nexts != null)
                nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value));
            step.Next = flowSwitch;
            return step;
        }
 private static ContentView FlowStepToView(FlowStep flowStep)
 => flowStep switch
 {
Beispiel #32
0
        public void FindRecordsMulitpleCriteriaActivity_WithTextInMatchField_Expected_NoResults()
        {
            TestStartNode = new FlowStep
            {
                Action = new DsfFindRecordsMultipleCriteriaActivity
                {
                    FieldsToSearch    = "[[Recset().Field1]],[[Recset().Field2]],[[Recset().Field3]]",
                    ResultsCollection = new List <FindRecordsTO> {
                        new FindRecordsTO("jimmy", ">", 1)
                    },
                    StartIndex = "",
                    Result     = "[[Result().res]]"
                }
            };

            CurrentDl = "<DL><Recset><Field1/><Field2/><Field3/></Recset><Result><res/></Result></DL>";
            const string data = @"<ADL>
  <Recset>
	<Field1>Mr A</Field1>
	<Field2>25</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr B</Field1>
	<Field2>651</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr C</Field1>
	<Field2>48</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr D</Field1>
	<Field2>1</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr E</Field1>
	<Field2>22</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr F</Field1>
	<Field2>321</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr G</Field1>
	<Field2>51</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr H</Field1>
	<Field2>2120</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
  <Recset>
	<Field1>Mr I</Field1>
	<Field2>46</Field2>
	<Field3>[email protected]</Field3>
  </Recset>
</ADL>";

            TestData = "<root>" + data + "</root>";
            var result = ExecuteProcess();

            GetRecordSetFieldValueFromDataList(result.Environment, "Result", "res", out IList <string> actual, out string error);

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual("-1", actual[0]);
        }
Beispiel #33
0
        /// <summary>
        /// 创建人工节点
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="displayName"></param>
        /// <param name="actioner"></param>
        /// <param name="humanResultTo"></param>
        /// <param name="nexts"></param>
        /// <param name="defaultFlowNode"></param>
        /// <returns></returns>
        public static FlowStep CreateHuman(ActivitySetting setting
            , string displayName
            , IActionersHelper actioner//Activity<string[]> actioner
            , Variable<string> humanResultTo
            , IDictionary<string, FlowNode> nexts
            , FlowNode defaultFlowNode)
        {
            var human = CreateHuman(setting, displayName, actioner, humanResultTo);
            var step = new FlowStep();
            step.Action = human;

            if (nexts == null && defaultFlowNode == null) return step;

            //设置finish cases
            //HACK:在进入switch之前就已经计算出任务结果
            var flowSwitch = new FlowSwitch<string>(o => humanResultTo.Get(o));
            if (defaultFlowNode != null)
                flowSwitch.Default = defaultFlowNode;
            if (nexts != null)
                nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value));
            step.Next = flowSwitch;
            return step;
        }