static ModelItem CreateModelItem(IEnumerable <DecisionTO> items, string displayName = "Find") { var dec = new DsfDecision(); var modelItem = ModelItemUtils.CreateModelItem(dec); FeatureContext.Current["decision"] = dec; modelItem.SetProperty("DisplayName", displayName); return(modelItem); }
public void DsfDecision_SerializeDeserialize_WhenAndSetFalse_ShouldHaveAndAsFalseWhenDeserialized() { //------------Setup for test-------------------------- var dsfDecision = new DsfDecision { And = false }; var serializer = new Dev2JsonSerializer(); var serDecision = serializer.Serialize(dsfDecision); //------------Execute Test--------------------------- var deSerDecision = serializer.Deserialize <DsfDecision>(serDecision); //------------Assert Results------------------------- Assert.IsNotNull(deSerDecision); Assert.IsFalse(deSerDecision.And); }
public void ConflictModelFactory_GivenDsfDecisionConflictNode_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 dev2DecisionStack = new Dev2DecisionStack { TheStack = new List <Dev2Decision>(), TrueArmText = "a", FalseArmText = "a", DisplayText = "a", Mode = Dev2DecisionMode.AND }; var serializer = new Dev2JsonSerializer(); var serialize = serializer.Serialize(dev2DecisionStack); var condition = new DsfFlowDecisionActivity { ExpressionText = serialize }; var value = new DsfDecision(condition) { Conditions = dev2DecisionStack }; 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>())); var mergeToolModel = completeConflict.CreateModelItem(toolConflictItem, node.Object); Assert.AreEqual("a", mergeToolModel.MergeDescription); Assert.AreEqual(typeof(DecisionDesignerViewModel).FullName, ((ToolConflictItem)mergeToolModel).ActivityDesignerViewModel.GetType().FullName); }
public void DsfDecision_GetState_ReturnsStateVariable() { //---------------Set up test pack------------------- var conditions = new Dev2DecisionStack(); conditions.TheStack = new List <Dev2Decision>(); conditions.AddModelItem(new Dev2Decision { Col1 = "[[a]]", EvaluationFn = Data.Decisions.Operations.enDecisionType.IsEqual, Col2 = "bob" }); var serializer = new Dev2JsonSerializer(); //------------Setup for test-------------------------- var act = new DsfDecision { Conditions = conditions, And = true }; //------------Execute Test--------------------------- var stateItems = act.GetState(); Assert.AreEqual(5, stateItems.Count()); var expectedResults = new[] { new StateVariable { Name = "Conditions", Type = StateVariable.StateType.Input, Value = serializer.Serialize(conditions) }, new StateVariable { Name = "And", Type = StateVariable.StateType.Input, Value = "True" }, new StateVariable { Name = "Result", Type = StateVariable.StateType.Output, Value = null }, new StateVariable { Name = "TrueArm", Type = StateVariable.StateType.Output, Value = ActivityHelper.GetSerializedStateValueFromCollection(act.TrueArm?.ToList()) }, new StateVariable { Name = "FalseArm", Type = StateVariable.StateType.Output, Value = ActivityHelper.GetSerializedStateValueFromCollection(act.FalseArm?.ToList()) } }; var iter = act.GetState().Select( (item, index) => new { value = item, expectValue = expectedResults[index] } ); //------------Assert Results------------------------- foreach (var entry in iter) { Assert.AreEqual(entry.expectValue.Name, entry.value.Name); Assert.AreEqual(entry.expectValue.Type, entry.value.Type); Assert.AreEqual(entry.expectValue.Value, entry.value.Value); } }
public void ActivityHelper_InjectExpression_Dev2DecisionStack() { //---------------Set up test pack------------------- var dev2DecisionStack = new Dev2DecisionStack() { DisplayText = "", FalseArmText = "", TrueArmText = "", Version = "2", Mode = Dev2DecisionMode.AND }; dev2DecisionStack.TheStack = new List <Dev2Decision>(); var testAct = new DsfFlowSwitchActivity { ExpressionText = "" }; var prop = new Mock <ModelProperty>(); prop.Setup(p => p.ComputedValue).Returns(testAct); ActivityHelper.InjectExpression(dev2DecisionStack, prop.Object); //------------Assert Results------------------------- var act = new DsfDecision { Conditions = dev2DecisionStack, And = true }; var stateItems = act.GetState(); Assert.AreEqual(5, stateItems.Count()); var serializer = new Dev2JsonSerializer(); var expectedResults = new[] { new StateVariable { Name = "Conditions", Type = StateVariable.StateType.Input, Value = serializer.Serialize(dev2DecisionStack) }, new StateVariable { Name = "And", Type = StateVariable.StateType.Input, Value = "True" }, new StateVariable { Name = "Result", Type = StateVariable.StateType.Output, Value = null }, new StateVariable { Name = "TrueArm", Type = StateVariable.StateType.Output, Value = ActivityHelper.GetSerializedStateValueFromCollection(act.TrueArm?.ToList()) }, new StateVariable { Name = "FalseArm", Type = StateVariable.StateType.Output, Value = ActivityHelper.GetSerializedStateValueFromCollection(act.FalseArm?.ToList()) } }; var iter = act.GetState().Select((item, index) => new { value = item, expectValue = expectedResults[index] }); Assert.AreEqual(expectedResults.Length, iter.Count()); foreach (var entry in iter) { Assert.AreEqual(entry.expectValue.Name, entry.value.Name); Assert.AreEqual(entry.expectValue.Type, entry.value.Type); Assert.AreEqual(entry.expectValue.Value, entry.value.Value); } }
public void ActivityHelper_Dev2Decision_SetArmTextDefaults_SetArmText_SetDisplayName() { //---------------Set up test pack------------------- var serializer = new Dev2JsonSerializer(); var viewModel = new DecisionDesignerViewModel(CreateModelItem()); var dev2DecisionStack = new Dev2DecisionStack() { DisplayText = "", FalseArmText = "", TrueArmText = "", Version = "2", Mode = Dev2DecisionMode.AND }; dev2DecisionStack.TheStack = new List <Dev2Decision>(); var decisionExpressionMessage = new ConfigureDecisionExpressionMessage(); viewModel.Handle(decisionExpressionMessage); //------------Setup for test-------------------------- ActivityHelper.SetArmTextDefaults(dev2DecisionStack); ActivityHelper.SetArmText(viewModel.ModelItem, dev2DecisionStack); ActivityHelper.SetDisplayName(viewModel.ModelItem, dev2DecisionStack); //------------Assert Results------------------------- var act = new DsfDecision { Conditions = dev2DecisionStack, And = true }; var stateItems = act.GetState(); Assert.AreEqual(5, stateItems.Count()); var expectedResults = new[] { new StateVariable { Name = "Conditions", Type = StateVariable.StateType.Input, Value = serializer.Serialize(dev2DecisionStack) }, new StateVariable { Name = "And", Type = StateVariable.StateType.Input, Value = "True" }, new StateVariable { Name = "Result", Type = StateVariable.StateType.Output, Value = null }, new StateVariable { Name = "TrueArm", Type = StateVariable.StateType.Output, Value = ActivityHelper.GetSerializedStateValueFromCollection(act.TrueArm?.ToList()) }, new StateVariable { Name = "FalseArm", Type = StateVariable.StateType.Output, Value = ActivityHelper.GetSerializedStateValueFromCollection(act.FalseArm?.ToList()) } }; var iter = act.GetState().Select((item, index) => new { value = item, expectValue = expectedResults[index] }); Assert.AreEqual(expectedResults.Length, iter.Count()); foreach (var entry in iter) { Assert.AreEqual(entry.expectValue.Name, entry.value.Name); Assert.AreEqual(entry.expectValue.Type, entry.value.Type); Assert.AreEqual(entry.expectValue.Value, entry.value.Value); } }
IEnumerable<IDev2Activity> ParseDecision(FlowDecision decision, List<IDev2Activity> seenActivities) { var activity = decision.Condition as DsfFlowDecisionActivity; if(activity != null) { if( seenActivities.Contains(activity)) { return new List<IDev2Activity> { activity}; } var rawText = activity.ExpressionText; // ReSharper disable MaximumChainedReferences var activityTextjson = rawText.Substring(rawText.IndexOf("{", StringComparison.Ordinal)).Replace(@""",AmbientDataList)","").Replace("\"","!"); // ReSharper restore MaximumChainedReferences var activityText = Dev2DecisionStack.FromVBPersitableModelToJSON(activityTextjson); var decisionStack = JsonConvert.DeserializeObject<Dev2DecisionStack>(activityText); var dec = new DsfDecision(activity); if (!seenActivities.Contains(activity)) { seenActivities.Add( dec); } dec.TrueArm = ParseTools(decision.True, seenActivities); dec.FalseArm = ParseTools(decision.False, seenActivities); dec.Conditions = decisionStack; dec.And = decisionStack.Mode == Dev2DecisionMode.AND; return new List<IDev2Activity> { dec}; } throw new Exception("Invalid activity"); }
public void ActivityParser_ParseToLinkedFlatList() { var topLevelActivity = new DsfDotNetMultiAssignActivity { DisplayName = "Assign (1)", UniqueID = "d006a409-333a-49d3-8e1c-7c908f6ba461", }; var suspendExecutionActivityOne = new SuspendExecutionActivity { DisplayName = "Suspend Execution", UniqueID = "66b7c885-9ea4-4d75-b822-13ff5ef28128", }; topLevelActivity.NextNodes = new List <IDev2Activity> { suspendExecutionActivityOne }; var dev2DecisionStackOne = new Dev2DecisionStack { DisplayText = "If [[a]] Is = 2" }; var flowDecisionActivityOne = new DsfDecision { DisplayName = "If [[a]] Is = 2", UniqueID = "1764efe9-4e0e-423a-8510-b35dc9b053f4", NextNodes = null, Conditions = dev2DecisionStackOne }; var fileWriteActivityOne = new FileWriteActivity { DisplayName = "Write File", UniqueID = "8e35adbf-d0c4-443b-ab04-2a83ca1aaa62", }; flowDecisionActivityOne.TrueArm = new [] { fileWriteActivityOne }; var flowDecisionActivityOneFalseArmAssign = new DsfDotNetMultiAssignActivity { DisplayName = "Assign (1)", UniqueID = "23b599b7-49f4-40a8-8304-f034d227d3dd", }; var flowDecisionActivityOneFalseArmFileWrite = new FileWriteActivity { DisplayName = "Write File", UniqueID = "baad2ce3-371b-4fec-81f4-0da4112078c8", }; flowDecisionActivityOneFalseArmAssign.NextNodes = new List <IDev2Activity> { flowDecisionActivityOneFalseArmFileWrite }; flowDecisionActivityOneFalseArmFileWrite.NextNodes = new List <IDev2Activity> { suspendExecutionActivityOne }; flowDecisionActivityOne.FalseArm = new [] { flowDecisionActivityOneFalseArmAssign }; suspendExecutionActivityOne.NextNodes = new List <IDev2Activity> { flowDecisionActivityOne }; var suspendExecutionActivityTwo = new SuspendExecutionActivity { DisplayName = "Suspend Execution", UniqueID = "f72ab5fe-efc9-46c5-8944-f2032f0613eb", }; fileWriteActivityOne.NextNodes = new List <IDev2Activity> { suspendExecutionActivityTwo }; var dev2DecisionStackTwo = new Dev2DecisionStack { DisplayText = "If [[a]] Is = 4" }; var flowDecisionActivityTwo = new DsfDecision { DisplayName = "If [[a]] Is = 4", UniqueID = "9ad7861e-6fe8-449f-8640-92147259f919", NextNodes = null, Conditions = dev2DecisionStackTwo }; var fileWriteActivityTwo = new FileWriteActivity { DisplayName = "Write File", UniqueID = "88deb70e-ad45-4735-8a87-a77f7eb54d83", }; var flowDecisionActivityTwoFalseArmAssign = new DsfDotNetMultiAssignActivity { DisplayName = "Assign (1)", UniqueID = "c511b3e4-819f-4c38-81f6-6579ae3f52df", }; var flowDecisionActivityTwoFalseArmFileWrite = new FileWriteActivity { DisplayName = "Write File", UniqueID = "3c477009-7b12-432f-908c-b0ad613e8c57", }; flowDecisionActivityTwoFalseArmAssign.NextNodes = new List <IDev2Activity> { flowDecisionActivityTwoFalseArmFileWrite }; flowDecisionActivityTwoFalseArmFileWrite.NextNodes = new List <IDev2Activity> { suspendExecutionActivityTwo }; flowDecisionActivityTwo.NextNodes = null; flowDecisionActivityTwo.TrueArm = new [] { fileWriteActivityTwo }; flowDecisionActivityTwo.FalseArm = new [] { flowDecisionActivityTwoFalseArmAssign }; suspendExecutionActivityTwo.NextNodes = new List <IDev2Activity> { flowDecisionActivityTwo }; var activityParser = new ActivityParser(); var activities = activityParser.ParseToLinkedFlatList(topLevelActivity); Assert.IsNotNull(activities); var dev2Activities = activities.ToList(); Assert.AreEqual(13, dev2Activities.Count); }