public void Dev2Decision_PopulatedColumnCount_Default() { var dev2Decision = new Dev2Decision(); Assert.AreEqual(0, dev2Decision.PopulatedColumnCount); Assert.IsNull(dev2Decision.Col1); }
static Dev2DecisionStack SetupTos(IEnumerable <IDev2TOFn> valuecoll) { var val = new Dev2DecisionStack { TheStack = new List <Dev2Decision>() }; var value = valuecoll.Select(a => a as DecisionTO); foreach (var decisionTo in value.Where(a => { return(a != null && !a.IsEmpty()); })) { var dev2Decision = new Dev2Decision { Col1 = decisionTo.MatchValue }; if (!string.IsNullOrEmpty(decisionTo.SearchCriteria)) { dev2Decision.Col2 = decisionTo.SearchCriteria; } dev2Decision.EvaluationFn = DecisionDisplayHelper.GetValue(decisionTo.SearchType); if (decisionTo.IsBetweenCriteriaVisible) { dev2Decision.Col2 = decisionTo.From; dev2Decision.Col3 = decisionTo.To; } if (string.IsNullOrEmpty(dev2Decision.Col3)) { dev2Decision.Col3 = ""; } val.TheStack.Add(dev2Decision); } return(val); }
public void DecisionDesignerViewModel_Validate_CustomizedDisplayText() { //------------Setup for test-------------------------- var viewModel = new DecisionDesignerViewModel(CreateModelItem("Decision")) { DisplayText = "", TrueArmText = "", FalseArmText = "", ExpressionText = "" }; viewModel.DisplayText = "Testing"; var dev2Decision = new Dev2Decision { Col1 = "[[val]]", EvaluationFn = enDecisionType.IsEqual, Col2 = "5" }; var item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); //------------Execute Test--------------------------- //------------Assert Results------------------------- Assert.AreEqual("Testing", viewModel.DisplayText); }
public void DecisionDesignerViewModel_RemoveRow_ShouldRemove() { //------------Setup for test-------------------------- var viewModel = new DecisionDesignerViewModel(CreateModelItem()) { DisplayText = "", TrueArmText = "", FalseArmText = "" }; var dev2Decision = new Dev2Decision { Col1 = "[[val]]", EvaluationFn = enDecisionType.IsEqual, Col2 = "5" }; var item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); //------------Assert Preconsidtions------------------ Assert.AreEqual(3, viewModel.Collection.Count); //------------Execute Test--------------------------- viewModel.DeleteCommand.Execute(item); //------------Assert Results------------------------- Assert.AreEqual(2, viewModel.Collection.Count); }
protected override void BuildDataList() { BuildShapeAndTestData(); var decisionActivity = new DsfFlowDecisionActivity(); scenarioContext.TryGetValue("mode", out Dev2DecisionMode mode); var decisionModels = scenarioContext.Get <List <Tuple <string, enDecisionType, string, string> > >("decisionModels"); var dds = new Dev2DecisionStack { TheStack = new List <Dev2Decision>(), Mode = mode, TrueArmText = "YES", FalseArmText = "NO" }; foreach (var dm in decisionModels) { var dev2Decision = new Dev2Decision { Col1 = dm.Item1 ?? string.Empty, EvaluationFn = dm.Item2, Col2 = dm.Item3 ?? string.Empty, Col3 = dm.Item4 ?? string.Empty }; dds.AddModelItem(dev2Decision); } var modelData = dds.ToVBPersistableModel(); scenarioContext.Add("modelData", modelData); decisionActivity.ExpressionText = string.Join("", GlobalConstants.InjectedDecisionHandler, "(\"", modelData, "\",", GlobalConstants.InjectedDecisionDataListVariable, ")"); scenarioContext.TryGetValue("variableList", out List <Tuple <string, string> > variableList); if (variableList == null) { variableList = new List <Tuple <string, string> >(); scenarioContext.Add("variableList", variableList); } var multiAssign = new DsfMultiAssignActivity(); var row = 1; foreach (var variable in variableList) { multiAssign.FieldsCollection.Add(new ActivityDTO(variable.Item1, variable.Item2, row, true)); row++; } var x = new FlowDecision(); x.Condition = decisionActivity; TestStartNode = new FlowStep { Action = multiAssign, Next = x }; scenarioContext.Add("activity", decisionActivity); }
Dev2Decision ParseDecision(IExecutionEnvironment env, Dev2Decision decision, bool errorIfNull) { var col1 = env.EvalAsList(decision.Col1, 0, errorIfNull); var col2 = env.EvalAsList(decision.Col2 ?? "", 0, errorIfNull); var col3 = env.EvalAsList(decision.Col3 ?? "", 0, errorIfNull); return(new Dev2Decision { Cols1 = col1, Cols2 = col2, Cols3 = col3, EvaluationFn = decision.EvaluationFn }); }
public void Dev2Decision_PopulatedColumnCount_Col3() { var dev2Decision = new Dev2Decision { Col3 = "bob" }; Assert.AreEqual(1, dev2Decision.PopulatedColumnCount); Assert.AreEqual("bob", dev2Decision.Col3); }
public void Dev2Decision_PopulatedColumnCount_Col2() { var dev2Decision = new Dev2Decision { Col2 = "=" }; Assert.AreEqual(1, dev2Decision.PopulatedColumnCount); Assert.AreEqual("=", dev2Decision.Col2); }
public void Dev2Decision_PopulatedColumnCount_Col1() { var dev2Decision = new Dev2Decision { Col1 = "[[a]]" }; Assert.AreEqual(1, dev2Decision.PopulatedColumnCount); Assert.AreEqual("[[a]]", dev2Decision.Col1); }
private Dev2Decision ParseDecision(IExecutionEnvironment env, Dev2Decision decision) { var col1 = env.EvalAsList(decision.Col1, 0); var col2 = env.EvalAsList(decision.Col2, 0); var col3 = env.EvalAsList(decision.Col3, 0); return(new Dev2Decision { Cols1 = col1, Cols2 = col2, Cols3 = col3, EvaluationFn = decision.EvaluationFn }); }
private Dev2Decision ParseDecision(IExecutionEnvironment env, Dev2Decision decision) { bool errorifnull = !decision.EvaluationFn.ToString().ToLower().Contains("null"); var col1 = env.EvalAsList(decision.Col1, 0, errorifnull); var col2 = env.EvalAsList(decision.Col2, 0, errorifnull); var col3 = env.EvalAsList(decision.Col3, 0, errorifnull); return(new Dev2Decision { Cols1 = col1, Cols2 = col2, Cols3 = col3, EvaluationFn = decision.EvaluationFn }); }
public void CommonEqualityOps_CollectionEquals_ReturnTrue() { var TheStack = new List <Dev2Decision>(); var dev2Decision = new Dev2Decision { Col1 = "Col1" }; TheStack.Add(dev2Decision); var collectionEquals = CommonEqualityOps.CollectionEquals(TheStack, TheStack, new Dev2DecisionComparer()); Assert.IsTrue(collectionEquals); }
public void Dev2Decision_GenerateUserFriendlyModel_PopulatedColumnCount_Zero() { var dev2Decision = new Dev2Decision { EvaluationFn = enDecisionType.IsEqual }; var mockExecutionEnvironment = new Mock <IExecutionEnvironment>(); var result = dev2Decision.GenerateToolLabel(mockExecutionEnvironment.Object, Dev2DecisionMode.AND, out var error); Assert.AreEqual("If = ", result); Assert.AreEqual(0, error.FetchErrors().Count); }
public void Dev2Decision_PopulatedColumnCount_AllColumns() { var dev2Decision = new Dev2Decision { Col1 = "[[a]]", Col2 = "=", Col3 = "bob" }; Assert.AreEqual(3, dev2Decision.PopulatedColumnCount); Assert.AreEqual("[[a]]", dev2Decision.Col1); Assert.AreEqual("=", dev2Decision.Col2); Assert.AreEqual("bob", dev2Decision.Col3); }
public void Dev2Decision_GenerateUserFriendlyModel_PopulatedColumnCount_One_Recordset_ExpectedError() { var dev2Decision = new Dev2Decision { Col1 = "[[recset(*).field]]", EvaluationFn = enDecisionType.IsBetween }; var result = dev2Decision.GenerateToolLabel(null, Dev2DecisionMode.AND, out var error); Assert.AreEqual("If ", result); Assert.AreEqual(1, error.FetchErrors().Count); Assert.AreEqual("Object reference not set to an instance of an object.", error.FetchErrors()[0]); }
public void Dev2Decision_GenerateUserFriendlyModel_PopulatedColumnCount_One_Scalar() { var dev2Decision = new Dev2Decision { Col1 = "[[field]]", EvaluationFn = enDecisionType.IsBetween }; var mockExecutionEnvironment = new Mock <IExecutionEnvironment>(); var result = dev2Decision.GenerateToolLabel(mockExecutionEnvironment.Object, Dev2DecisionMode.AND, out var error); Assert.AreEqual("If [[field]] Is Between ", result); Assert.AreEqual(0, error.FetchErrors().Count); }
public void Dev2DecisionComparer_Right_Null_Equals_Expect_False() { var dev2DecisionA = new Dev2Decision { Col1 = "[[a]]", Col2 = "=", Col3 = "bob", EvaluationFn = Decisions.Operations.enDecisionType.IsEqual }; var dev2DecisionComparer = new Dev2DecisionComparer(); var isEqual = dev2DecisionComparer.Equals(dev2DecisionA, null); Assert.IsFalse(isEqual); }
public void Dev2DecisionComparer_GetHashCode_Expected_Not_Zero() { var dev2DecisionA = new Dev2Decision { Col1 = "[[a]]", Col2 = "=", Col3 = "bob", EvaluationFn = Decisions.Operations.enDecisionType.IsEqual }; var dev2DecisionComparer = new Dev2DecisionComparer(); var hashCode = dev2DecisionComparer.GetHashCode(dev2DecisionA); Assert.AreNotEqual(0, hashCode); }
public void FetchDecisionModel_Expected_EmptyJsonString() { var testWebModel = new WebModel(); IDev2DataModel testModel = new Dev2Decision(); var stack = new Dev2DecisionStack { TheStack = new List <Dev2Decision> { new Dev2Decision() } }; string expected = "{}"; string actual = testWebModel.FetchDecisionModel("", Guid.Empty, Guid.Empty); Assert.AreEqual(expected, actual); }
public void Dev2Decision_GenerateUserFriendlyModel_PopulatedColumnCount_One_Recordset_Multiple_Values() { var dev2Decision = new Dev2Decision { Col1 = "[[recset(*).field]]", EvaluationFn = enDecisionType.IsBetween }; var mockExecutionEnvironment = new Mock <IExecutionEnvironment>(); mockExecutionEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "[[a]]", "[[b]]" }); var result = dev2Decision.GenerateToolLabel(mockExecutionEnvironment.Object, Dev2DecisionMode.AND, out var error); Assert.AreEqual("If [[a]] Is Between AND [[b]] Is Between", result); Assert.AreEqual(0, error.FetchErrors().Count); }
public void CommonEqualityOps_CollectionEquals__OneObjectsIsNull_ReturnFalse() { var TheStack = new List <Dev2Decision>(); var dev2Decision = new Dev2Decision { Col1 = "Col1" }; TheStack.Add(dev2Decision); var TheOtherStack = new List <Dev2Decision>(); TheOtherStack = null; var collectionEquals = CommonEqualityOps.CollectionEquals(TheStack, TheOtherStack, new Dev2DecisionComparer()); Assert.IsFalse(collectionEquals); collectionEquals = CommonEqualityOps.CollectionEquals(TheOtherStack, TheStack, new Dev2DecisionComparer()); Assert.IsFalse(collectionEquals); }
public DecisionTO(Dev2Decision a, int ind, Action <DecisionTO> updateDisplayAction, Action <DecisionTO> deleteAction) { UpdateDisplayAction = updateDisplayAction ?? (x => { }); _isInitializing = true; Inserted = false; MatchValue = a.Col1; SearchCriteria = a.Col2; SearchType = DecisionDisplayHelper.GetDisplayValue(a.EvaluationFn); IndexNumber = ind; IsSearchCriteriaEnabled = true; IsSearchCriteriaVisible = true; From = a.Col2; To = a.Col3; IsSearchTypeFocused = false; DeleteAction = deleteAction; IsLast = false; DeleteCommand = new RelayCommand(x => { DeleteAction?.Invoke(this); }, CanDelete); _isInitializing = false; }
public void DecisionDesignerViewModel_GetExpressionText_ShouldSetExpressionText() { //------------Setup for test-------------------------- var viewModel = new DecisionDesignerViewModel(CreateModelItem()) { DisplayText = "", TrueArmText = "", FalseArmText = "" }; var dev2Decision = new Dev2Decision { Col1 = "[[val]]", EvaluationFn = enDecisionType.IsEqual, Col2 = "5" }; viewModel.Collection.Add(new DecisionTO(dev2Decision, 1)); //------------Execute Test--------------------------- viewModel.GetExpressionText(); //------------Assert Results------------------------- Assert.IsNotNull(viewModel.ExpressionText); StringAssert.Contains(viewModel.ExpressionText, "{\"TheStack\":[{\"Col1\":\"[[val]]\",\"Col2\":\"5\",\"Col3\":\"\",\"Cols1\":null,\"Cols2\":null,\"Cols3\":null,\"PopulatedColumnCount\":2,\"EvaluationFn\":\"IsEqual\"}],\"TotalDecisions\":1,\"ModelName\":\"Dev2DecisionStack\",\"Mode\":\"AND\",\"TrueArmText\":\"\",\"FalseArmText\":\"\",\"DisplayText\":\"\",\"Version\":null}"); }
Dev2DecisionStack ResolveAllRecords(IExecutionEnvironment env, Dev2DecisionStack stack, Dev2Decision decision, bool[] effectedCols, out ErrorResultTO errors, int update) { if (effectedCols == null) { throw new ArgumentNullException("effectedCols"); } var stackIndex = stack.TheStack.IndexOf(decision); stack.TheStack.Remove(decision); errors = new ErrorResultTO(); if (effectedCols[0]) { var data = env.EvalAsListOfStrings(decision.Col1, update); var reStackIndex = stackIndex; foreach (var item in data) { var newDecision = new Dev2Decision { Col1 = item, Col2 = decision.Col2, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn }; stack.TheStack.Insert(reStackIndex++, newDecision); } } if (effectedCols[1]) { var data = env.EvalAsListOfStrings(decision.Col2, update); var reStackIndex = stackIndex; foreach (var item in data) { var newDecision = new Dev2Decision { Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = item, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn }; if (effectedCols[0]) { // ensure we have the correct indexing ;) if (reStackIndex < stack.TheStack.Count) { stack.TheStack[reStackIndex++] = newDecision; } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } } if (effectedCols[2]) { var data = env.EvalAsListOfStrings(decision.Col3, update); var reStackIndex = stackIndex; foreach (var item in data) { var newDecision = new Dev2Decision { Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = FetchStackValue(stack, reStackIndex, 2), Col3 = item, EvaluationFn = decision.EvaluationFn }; if (effectedCols[0] || effectedCols[1]) { // ensure we have the correct indexing ;) if (reStackIndex < stack.TheStack.Count) { stack.TheStack[reStackIndex++] = newDecision; } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } } return(stack); }
// Guid dlID /// <summary> /// Executes the decision stack. /// </summary> /// <param name="decisionDataPayload">The decision data payload.</param> /// <param name="oldAmbientData">The old ambient data.</param> /// <returns></returns> /// <exception cref="System.Data.InvalidExpressionException">Could not evaluate decision data - No decision function found for [ + typeOf + ]</exception> public bool ExecuteDecisionStack(string decisionDataPayload, IList <string> oldAmbientData) { Guid dlId = FetchDataListID(oldAmbientData); // if(dlId == GlobalConstants.NullDataListID) throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); string newDecisionData = Dev2DecisionStack.FromVBPersitableModelToJSON(decisionDataPayload); var dds = EvaluateRegion(newDecisionData, dlId); var env = _environments[dlId]; if (dds != null) { if (dlId != GlobalConstants.NullDataListID) { try { if (dds.TheStack != null) { for (int i = 0; i < dds.TotalDecisions; i++) { Dev2Decision dd = dds.GetModelItem(i); enDecisionType typeOf = dd.EvaluationFn; // Treat Errors special if (typeOf == enDecisionType.IsError || typeOf == enDecisionType.IsNotError) { dd.Col1 = String.Join("", env.Errors); } IDecisionOperation op = Dev2DecisionFactory.Instance().FetchDecisionFunction(typeOf); if (op != null) { try { bool result = op.Invoke(dds.GetModelItem(i).FetchColsAsArray()); if (!result && dds.Mode == Dev2DecisionMode.AND) { // Naughty stuff, we have a false in AND mode... break return(false); } if (result && dds.Mode == Dev2DecisionMode.OR) { return(true); } } catch (Exception e) { // An error, push into the DL env.AddError(e.Message); return(false); } } else { throw new InvalidExpressionException("Could not evaluate decision data - No decision function found for [ " + typeOf + " ]"); } } // else we are in AND mode and all have passed ;) if (dds.Mode == Dev2DecisionMode.AND) { return(true); } //finally, it must be OR mode with no matches ;( return(false); } throw new InvalidExpressionException("Could not evaluate decision data - Invalid model data sent!"); } catch { // all hell has broken loose... ;) throw new InvalidExpressionException("Could not evaluate decision data - No model data sent!"); } } throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); } throw new InvalidExpressionException("Could not populate decision model - DataList Errors!"); }
/// <summary> /// Evaluates the region. /// </summary> /// <param name="payload">The payload.</param> /// <param name="dlId">The dl ID.</param> /// <returns></returns> private Dev2DecisionStack EvaluateRegion(string payload, Guid dlId) { var env = _environments[dlId]; if (payload.StartsWith("{\"TheStack\":[{") || payload.StartsWith("{'TheStack':[{")) { //2013.05.06: Ashley Lewis for PBI 9460 - handle record-sets with stars in their index by resolving them var dds = Compiler.ConvertFromJsonToModel <Dev2DecisionStack>(new StringBuilder(payload)); if (dds.TheStack != null) { var effectedCols = new[] { false, false, false }; //Find decisions that mention record sets with starred indexes var invalidDecisions = new List <Dev2Decision>(); for (int i = 0; i < dds.TotalDecisions; i++) { Dev2Decision dd = dds.GetModelItem(i); if (dd.Col1 != null && DataListUtil.GetRecordsetIndexType(dd.Col1) == enRecordsetIndexType.Star) { invalidDecisions.Add(dd); effectedCols[0] = true; } else { var warewolfEvalResult = GetWarewolfEvalResult(env, dd.Col1); dd.Col1 = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult); } if (dd.Col2 != null && DataListUtil.GetRecordsetIndexType(dd.Col2) == enRecordsetIndexType.Star) { if (!effectedCols[0]) { invalidDecisions.Add(dd); } effectedCols[1] = true; } else { var warewolfEvalResult = GetWarewolfEvalResult(env, dd.Col2); dd.Col2 = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult); } if (dd.Col3 != null && DataListUtil.GetRecordsetIndexType(dd.Col3) == enRecordsetIndexType.Star) { if (!effectedCols[0] && !effectedCols[1]) { invalidDecisions.Add(dd); } effectedCols[2] = true; } else { var warewolfEvalResult = GetWarewolfEvalResult(env, dd.Col3); dd.Col3 = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult); } } //Remove those record sets and replace them with a new decision for each resolved value foreach (Dev2Decision decision in invalidDecisions) { ErrorResultTO errors; dds = ResolveAllRecords(env, dds, decision, effectedCols, out errors); } } return(dds); } return(null); }
public DecisionTO(Dev2Decision a, int ind) : this(a, ind, null, null) { }
// Guid dlID /// <summary> /// Executes the decision stack. /// </summary> /// <param name="decisionDataPayload">The decision data payload.</param> /// <param name="oldAmbientData">The old ambient data.</param> /// <returns></returns> /// <exception cref="System.Data.InvalidExpressionException">Could not evaluate decision data - No decision function found for [ + typeOf + ]</exception> public bool ExecuteDecisionStack(string decisionDataPayload, IList <string> oldAmbientData) { // Evaluate decisionDataPayload through the EvaluateFunction ;) Guid dlId = FetchDataListID(oldAmbientData); if (dlId == GlobalConstants.NullDataListID) { throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); } // Swap out ! with a new internal token to avoid nasty issues with string newDecisionData = Dev2DecisionStack.FromVBPersitableModelToJSON(decisionDataPayload); var dds = EvaluateRegion(newDecisionData, dlId); ErrorResultTO errors = new ErrorResultTO(); if (dds != null) { if (dlId != GlobalConstants.NullDataListID) { try { if (dds.TheStack != null) { for (int i = 0; i < dds.TotalDecisions; i++) { Dev2Decision dd = dds.GetModelItem(i); enDecisionType typeOf = dd.EvaluationFn; // Treat Errors special if (typeOf == enDecisionType.IsError || typeOf == enDecisionType.IsNotError) { dd.Col1 = Compiler.EvaluateSystemEntry(dlId, enSystemTag.Dev2Error, out errors); } IDecisionOperation op = Dev2DecisionFactory.Instance().FetchDecisionFunction(typeOf); if (op != null) { try { bool result = op.Invoke(dds.GetModelItem(i).FetchColsAsArray()); if (!result && dds.Mode == Dev2DecisionMode.AND) { // Naughty stuff, we have a false in AND mode... break return(false); } if (result && dds.Mode == Dev2DecisionMode.OR) { return(true); } } catch (Exception e) { // An error, push into the DL ErrorResultTO errorErrors; errors.AddError(e.Message); Compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, errors.MakeDataListReady(), out errorErrors); return(false); } } else { throw new InvalidExpressionException("Could not evaluate decision data - No decision function found for [ " + typeOf + " ]"); } } // else we are in AND mode and all have passed ;) if (dds.Mode == Dev2DecisionMode.AND) { return(true); } //finally, it must be OR mode with no matches ;( return(false); } throw new InvalidExpressionException("Could not evaluate decision data - Invalid model data sent!"); } catch { // all hell has broken loose... ;) throw new InvalidExpressionException("Could not evaluate decision data - No model data sent!"); } } throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); } throw new InvalidExpressionException("Could not populate decision model - DataList Errors!"); }
Dev2DecisionStack ResolveAllRecords(Guid id, Dev2DecisionStack stack, Dev2Decision decision, bool[] effectedCols, out ErrorResultTO errors) { if (effectedCols == null) { throw new ArgumentNullException("effectedCols"); } int stackIndex = stack.TheStack.IndexOf(decision); stack.TheStack.Remove(decision); errors = new ErrorResultTO(); if (effectedCols[0]) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry col1Entry = Compiler.Evaluate(id, enActionType.User, decision.Col1, false, out errors); IDev2DataListEvaluateIterator col1Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col1Entry); colItr.AddIterator(col1Iterator); int reStackIndex = stackIndex; while (colItr.HasMoreData()) { var newDecision = new Dev2Decision { Col1 = colItr.FetchNextRow(col1Iterator).TheValue, Col2 = decision.Col2, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn }; stack.TheStack.Insert(reStackIndex++, newDecision); } } if (effectedCols[1]) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry col2Entry = Compiler.Evaluate(id, enActionType.User, decision.Col2, false, out errors); IDev2DataListEvaluateIterator col2Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col2Entry); colItr.AddIterator(col2Iterator); int reStackIndex = stackIndex; while (colItr.HasMoreData()) { var newDecision = new Dev2Decision { Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = colItr.FetchNextRow(col2Iterator).TheValue, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn }; if (effectedCols[0]) { // ensure we have the correct indexing ;) if (reStackIndex < stack.TheStack.Count) { stack.TheStack[reStackIndex++] = newDecision; } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } } if (effectedCols[2]) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry col3Entry = Compiler.Evaluate(id, enActionType.User, decision.Col3, false, out errors); IDev2DataListEvaluateIterator col3Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col3Entry); colItr.AddIterator(col3Iterator); int reStackIndex = stackIndex; while (colItr.HasMoreData()) { var newDecision = new Dev2Decision { Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = FetchStackValue(stack, reStackIndex, 2), Col3 = colItr.FetchNextRow(col3Iterator).TheValue, EvaluationFn = decision.EvaluationFn }; if (effectedCols[0] || effectedCols[1]) { // ensure we have the correct indexing ;) if (reStackIndex < stack.TheStack.Count) { stack.TheStack[reStackIndex++] = newDecision; } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } } return(stack); }
public void Decision_StaredRecordsetIsBetweenTwoStaredRecordsets_ValidateAndGenerateUserFriendlyModel() { //------------Setup for test-------------------------- using (var viewModel = new DecisionDesignerViewModel(CreateModelItem(nameof(Decision))) { TrueArmText = "", FalseArmText = "", ExpressionText = "", DisplayText = "Testing" }) { var dev2Decision = new Dev2Decision { Col1 = "[[recset(*).field]]", EvaluationFn = enDecisionType.IsBetween, Col2 = "[[recset(*).field]]", Col3 = "[[recset(*).field]]" }; var mockedEnvironment = new Mock <IExecutionEnvironment>(); mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); var userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out ErrorResultTO errors); Assert.AreEqual("If Some Value Is Between Some Value AND Some Value", userFriendlyModel, "User friendly model was not generated correctly for decision on multiple starred recordsets."); var item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); dev2Decision = new Dev2Decision { Col1 = "[[recset(*).field]]", EvaluationFn = enDecisionType.IsBetween, Col2 = "[[recset(*).field]]", Col3 = "[[val]]" }; mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out errors); Assert.AreEqual("If Some Value Is Between Some Value AND [[val]]", userFriendlyModel, "User friendly model was not generated correctly."); item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); dev2Decision = new Dev2Decision { Col1 = "[[recset(*).field]]", EvaluationFn = enDecisionType.IsBetween, Col2 = "[[val]]", Col3 = "[[recset(*).field]]" }; mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out errors); Assert.AreEqual("If Some Value Is Between [[val]] AND Some Value", userFriendlyModel, "User friendly model was not generated correctly."); item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); var dev2Decision4 = new Dev2Decision { Col1 = "[[val]]", EvaluationFn = enDecisionType.IsBetween, Col2 = "[[recset(*).field]]", Col3 = "[[recset(*).field]]" }; mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out errors); item = new DecisionTO(dev2Decision4, 1); viewModel.Collection.Insert(0, item); dev2Decision = new Dev2Decision { Col1 = "[[val]]", EvaluationFn = enDecisionType.IsBetween, Col2 = "[[val]]", Col3 = "[[recset(*).field]]" }; mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out errors); Assert.AreEqual("If [[val]] Is Between [[val]] AND Some Value", userFriendlyModel, "User friendly model was not generated correctly."); item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); dev2Decision = new Dev2Decision { Col1 = "[[val]]", EvaluationFn = enDecisionType.IsBetween, Col2 = "[[recset(*).field]]", Col3 = "[[val]]" }; mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out errors); Assert.AreEqual("If [[val]] Is Between Some Value AND [[val]]", userFriendlyModel, "User friendly model was not generated correctly."); item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); dev2Decision = new Dev2Decision { Col1 = "[[recset(*).field]]", EvaluationFn = enDecisionType.IsBetween, Col2 = "[[val]]", Col3 = "[[val]]" }; mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out errors); Assert.AreEqual("If Some Value Is Between [[val]] AND [[val]]", userFriendlyModel, "User friendly model was not generated correctly."); item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); dev2Decision = new Dev2Decision { Col1 = "[[recset(*).field]]", EvaluationFn = enDecisionType.IsEqual, Col2 = "[[recset(*).field]]" }; mockedEnvironment.Setup(env => env.EvalAsListOfStrings(It.IsAny <string>(), It.IsAny <int>())).Returns(new List <string> { "Some Value" }); userFriendlyModel = dev2Decision.GenerateToolLabel(mockedEnvironment.Object, Dev2DecisionMode.AND, out errors); Assert.AreEqual("If Some Value = Some Value", userFriendlyModel, "User friendly model was not generated correctly."); item = new DecisionTO(dev2Decision, 1); viewModel.Collection.Insert(0, item); //------------Execute Test--------------------------- //------------Assert Results------------------------- Assert.AreEqual("Testing", viewModel.DisplayText); } }