public void NestedCalcDependency() { Application app = new Application(); app.ApplicationData[this.rootControl.Name] = "9"; // * 3 List<Dictionary<string, object>> outerValue = new List<Dictionary<string, object>> { new Dictionary<string, object>() }; outerValue[0][this.outerChild.Name] = "7"; // *2 outerValue.Add(new Dictionary<string, object>()); outerValue[1][this.outerChild.Name] = "6"; // *2 List<Dictionary<string, object>> innerValue0 = new List<Dictionary<string, object>> { new Dictionary<string, object>() }; innerValue0[0][this.innerChild.Name] = "10"; // * 5 innerValue0.Add(new Dictionary<string, object>()); innerValue0[1][this.innerChild.Name] = "8"; // * 5 outerValue[0][this.innerRepeat.Name] = innerValue0.ToArray(); List<Dictionary<string, object>> innerValue1 = new List<Dictionary<string, object>> { new Dictionary<string, object>() }; innerValue1[0][this.innerChild.Name] = "4"; // * 5 innerValue1.Add(new Dictionary<string, object>()); innerValue1[1][this.innerChild.Name] = "5"; // * 5 outerValue[1][this.innerRepeat.Name] = innerValue1.ToArray(); app.ApplicationData[this.outerRepeat.Name] = outerValue.ToArray(); MultiExpressionEvaluator evaluator = new MultiExpressionEvaluator(app, this.controlList); ApplicationData result = evaluator.EvaluateAll(); /* RootControl | RootCalc | OuterChild | OuterCalc | InnerChild | InnerCalc | InnerCalcWithDependency * 9 | 27 | 7 | 14 | 10 | 50 | 91 * 9 | 27 | 7 | 14 | 8 | 40 | 81 * 9 | 27 | 6 | 12 | 4 | 20 | 59 * 9 | 27 | 6 | 12 | 5 | 25 | 64 */ var outerResult = (Dictionary<string, object>[])result[this.outerRepeat.Name]; var outer0Inner = (Dictionary<string, object>[])outerResult[0][this.innerRepeat.Name]; var outer1Inner = (Dictionary<string, object>[])outerResult[1][this.innerRepeat.Name]; Assert.AreEqual("91", outer0Inner[0][this.innerCalcWithDependency.Name]); Assert.AreEqual("81", outer0Inner[1][this.innerCalcWithDependency.Name]); Assert.AreEqual("59", outer1Inner[0][this.innerCalcWithDependency.Name]); Assert.AreEqual("64", outer1Inner[1][this.innerCalcWithDependency.Name]); }
public void NestedRepeaterCalc() { Application app = new Application(); List<Dictionary<string, object>> outerValue = new List<Dictionary<string, object>> { new Dictionary<string, object>() }; List<Dictionary<string, object>> innerValue = new List<Dictionary<string, object>> { new Dictionary<string, object>() }; innerValue[0][this.innerChild.Name] = "10"; outerValue[0][this.innerRepeat.Name] = innerValue.ToArray(); app.ApplicationData[this.outerRepeat.Name] = outerValue.ToArray(); MultiExpressionEvaluator evaluator = new MultiExpressionEvaluator(app, this.controlList); ApplicationData result = evaluator.EvaluateAll(); var outerResult = (Dictionary<string, object>[])result[this.outerRepeat.Name]; var innerResult = (Dictionary<string, object>[])outerResult[0][this.innerRepeat.Name]; var calcResult = innerResult[0][this.innerCalc.Name]; Assert.AreEqual("50", calcResult); }
public void RootCalc() { ControlList controls = new ControlList(); int i = 0; controls.Add(new TextControl { Id = i++, Name = "field1" }); controls.Add(new TextControl { Id = i++, Name = "field2" }); controls.Add(new CalculationControl { Id = i + 1, Name = "field3", CalculationExpression = "{%field1%}+{%field2%}" }); Application app = new Application(); app.ApplicationData["field1"] = "1"; app.ApplicationData["field2"] = "1"; app.ApplicationData["field3"] = null; MultiExpressionEvaluator evaluator = new MultiExpressionEvaluator(app, controls); ApplicationData result = evaluator.EvaluateAll(); Assert.AreEqual("2", result["field3"]); }
public void RepeaterInsideGroupCalc() { ControlList controls = new ControlList(); int i = 0; GroupControl group = new GroupControl { Id = i++, Name = "group1" }; controls.Add(group); RepeaterControl control = new RepeaterControl { Id = i++, Name = "repeater1" }; group.Controls.Add(control); control.AddChild(new TextControl { Id = i++, Name = "field1" }); control.AddChild(new TextControl { Id = i++, Name = "field2" }); control.AddChild(new CalculationControl { Id = i + 1, Name = "field3", CalculationExpression = "{%field1%}+{%field2%}" }); Application app = new Application(); List<Dictionary<string, object>> repeaterValue = new List<Dictionary<string, object>> { new Dictionary<string, object>() }; repeaterValue[0]["field1"] = "1"; repeaterValue[0]["field2"] = "1"; repeaterValue[0]["field3"] = null; repeaterValue.Add(new Dictionary<string, object>()); repeaterValue[1]["field1"] = "2"; repeaterValue[1]["field2"] = "2"; repeaterValue[1]["field3"] = null; app.ApplicationData["repeater1"] = repeaterValue.ToArray(); MultiExpressionEvaluator evaluator = new MultiExpressionEvaluator(app, controls); ApplicationData result = evaluator.EvaluateAll(); var repeater = (Dictionary<string, object>[])result["repeater1"]; Assert.AreEqual(repeater[0]["field3"], "2"); Assert.AreEqual(repeater[1]["field3"], "4"); }