public void RepeaterHideRuleReferenceRootControl() { ITruthCondition condition = new HideTruthCondition { RuleType = "HIDE" }; TruthConditionList subRuleList = new TruthConditionList(); CompareDefinition compareDefinition = new CompareDefinition { CompareTo = ComparisonType.Value, Field = "Checkbox", FieldScope = FieldScope.Unknown, Operator = Operator.Equals, Value = "checked" }; subRuleList.Add(new CompareTruthCondition { RuleType = "EVAL", Value = compareDefinition }); condition.Value = subRuleList; ControlList controlList = new ControlList { new CheckboxControl { Name = "Checkbox" } }; RepeaterControl repeater = new RepeaterControl { Name = "Parent" }; repeater.AddChild(new ComboControl { Name = "Child", VisibilityRule = condition }); controlList.Add(repeater); ApplicationData applicationData = new ApplicationData { { "Checkbox", "checked" } }; Dictionary<string, object>[] repeaterValue = new Dictionary<string, object>[1]; repeaterValue[0] = new Dictionary<string, object>(); repeaterValue[0]["Child"] = string.Empty; applicationData.Add("Parent", repeaterValue); ITruthConditionEvaluator<ITruthCondition> evaluator = this.EvaluatorRegister.GetEvaluatorFor<HideTruthCondition>(); bool result = evaluator.Evaluate(condition, controlList, applicationData, null, this.EvaluatorRegister, "Parent[0]"); Assert.IsTrue(result); applicationData["Checkbox"] = string.Empty; result = evaluator.Evaluate(condition, controlList, applicationData, null, this.EvaluatorRegister, "Parent[0]"); Assert.IsFalse(result); }
public void TestControlName() { string json = AssemblyResourceReader.ReadAsString("Test_Data.ValidateRule1.json"); ValidateTruthCondition condition = JsonConvert.DeserializeObject<ValidateTruthCondition>(json); ControlList controlList = new ControlList(); RepeaterControl repeater = new RepeaterControl { Id = 3, Name = "Repeater" }; controlList.Add(repeater); repeater.Controls.Add(new TextControl { Id = 1, Name = "Field1", ParentId = 3 }); repeater.Controls.Add(new TextControl { Id = 2, Name = "Field2", ParentId = 3 }); ApplicationData appData = new ApplicationData(); Dictionary<string, object>[] repeaterData = new Dictionary<string, object>[2]; appData.Add("Repeater", repeaterData); repeaterData[0] = new Dictionary<string, object> { { "Field1", "Is Valid" }, { "Field2", "When Combined With This" } }; repeaterData[1] = new Dictionary<string, object> { { "Field1", "Not Valid" }, { "Field2", "When Combined With This" } }; TruthConditionEvaluatorFactory evaluatorFactory = new TruthConditionEvaluatorFactory(); ITruthConditionValidator validator = new ITruthConditionValidator(condition, controlList, evaluatorFactory); ValidationResults results = validator.Validate(appData); Assert.AreEqual("Repeater[1].Field1", results.ToArray()[0].Key); }
public async Task <IActionResult> Create(CustomerViewModel viewModel) { if (ModelState.IsValid) { var json = JsonConvert.SerializeObject(viewModel); var model = JsonConvert.DeserializeObject <CustomerModel>(json); if (string.IsNullOrEmpty(model.FindId)) { model.CreateId(); var data = new CustomerData { Customer = model }; _entity = _context.Add(data); } else { var dataObject = await _context.Customers.SingleOrDefaultAsync(x => x.Customer.FindId == model.FindId); model.IsUpdate(dataObject.Customer.Created); dataObject.Customer = model; _entity = _context.Update(dataObject); } await _context.SaveChangesAsync(); _entity.State = EntityState.Detached; return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public void ControlIsHiddenByLocalisedRepeaterRule() { ControlList controlList = JsonConvert.DeserializeObject<ControlList>(this.GetTestResource("HideRuleInsideRepeater.json"), new JsonKnownTypeConverter()); TextControl control = controlList.FindRecursive<TextControl>(3); ApplicationData postedData = new ApplicationData(); Dictionary<string, object> repeaterItem1 = new Dictionary<string, object> { { "Textbox", "validate me!" }, { "RuleTrigger", "HIDE IT" } }; postedData.Add("Repeater", new[] { repeaterItem1 }); bool visible = control.IsVisible(controlList, postedData, null, this.register, "Repeater[0]"); Assert.IsFalse(visible); }
public void SingleFieldRecipientInRepeater() { MailQueue queue = new MailQueue(); EventActionEmailResponseHandler handler = new EventActionEmailResponseHandler(null, queue, null, new StringFormatter("{%", "%}"), new EmailTokenFormatter("{%", "%}"), new SummaryFormatter("{%", "%}"), null, string.Empty, "*****@*****.**") { Roles = this.roleList, GetUsersFn = this.getUserFn, SystemSettings = this.systemSettings }; ApplicationData data = new ApplicationData(); Dictionary<string, object>[] repeater = new Dictionary<string, object>[1]; repeater[0] = new Dictionary<string, object>(); repeater[0]["Email"] = "*****@*****.**"; data.Add("Repeater1", repeater); this.application.ApplicationData = data; this.recipientList.FormFields.Add("Repeater1[0].Email"); EventResult result = handler.Handle(null, this.action, this.application, new PageList(), this.getApplicationAccessFn); Assert.IsTrue(result.Processed); MailMessageSerializable message = queue.Dequeue().Message as MailMessageSerializable; Assert.AreEqual(1, message.To.Count); Assert.AreEqual("*****@*****.**", message.To[0].Address); Assert.AreEqual("*****@*****.**", message.Sender.Address); Assert.AreEqual(this.action.Content, message.Body); Assert.AreEqual(this.action.Subject, message.Subject); }
public void TestSerializeRepeater() { ApplicationData application = new ApplicationData { { "Textbox1", "Value 1" } }; List<Dictionary<string, object>> repeater = new List<Dictionary<string, object>> { new Dictionary<string, object> { { "Textbox2", "Repeater 1 Value 1" }, { "Textbox3", "Repeater 1 Value 2" } }, new Dictionary<string, object> { { "Textbox2", "Repeater 2 Value 1" }, { "Textbox3", "Repeater 2 Value 2" } } }; application.Add("Repeater", repeater); string json = JsonConvert.SerializeObject(application, Formatting.None); const string expected = "{\"Textbox1\":\"Value 1\",\"Repeater\":[{\"Textbox2\":\"Repeater 1 Value 1\",\"Textbox3\":\"Repeater 1 Value 2\"},{\"Textbox2\":\"Repeater 2 Value 1\",\"Textbox3\":\"Repeater 2 Value 2\"}]}"; Assert.AreEqual(expected, json); }
public void TestNestedRepeaterPassValueBusinessRule() { string json = AssemblyResourceReader.ReadAsString("Test_Data.ValidateRule1.json"); ValidateTruthCondition condition = JsonConvert.DeserializeObject<ValidateTruthCondition>(json); ControlList controlList = new ControlList(); RepeaterControl repeater = new RepeaterControl { Id = 3, Name = "Repeater" }; controlList.Add(repeater); RepeaterControl nestedRepeater = new RepeaterControl { Id = 4, Name = "NestedRepeater", ParentId = 3 }; repeater.Controls.Add(nestedRepeater); nestedRepeater.Controls.Add(new TextControl { Id = 1, Name = "Field1", ParentId = 4 }); nestedRepeater.Controls.Add(new TextControl { Id = 2, Name = "Field2", ParentId = 4 }); ApplicationData appData = new ApplicationData(); var validExample = new Dictionary<string, object> { { "Field1", "Is Valid" }, { "Field2", "When Combined With This" } }; var anotherValidExample = new Dictionary<string, object> { { "Field1", "And So Is This" }, { "Field2", "When Combined With This" } }; Dictionary<string, object>[] repeaterData = new Dictionary<string, object>[2]; appData.Add("Repeater", repeaterData); repeaterData[0] = new Dictionary<string, object>() { { "NestedRepeater", new[] { validExample, anotherValidExample } } }; repeaterData[1] = new Dictionary<string, object>() { { "NestedRepeater", new[] { anotherValidExample, validExample } } }; TruthConditionEvaluatorFactory evaluatorFactory = new TruthConditionEvaluatorFactory(); ITruthConditionValidator validator = new ITruthConditionValidator(condition, controlList, evaluatorFactory); ValidationResults results = validator.Validate(appData); Assert.AreEqual(true, results.IsValid); }
public void TestNestedRepeaterFailRootCompareBusinessRule() { string json = AssemblyResourceReader.ReadAsString("Test_Data.ValidateRule2.json"); ValidateTruthCondition condition = JsonConvert.DeserializeObject<ValidateTruthCondition>(json); ControlList controlList = new ControlList(); RepeaterControl repeater = new RepeaterControl { Id = 3, Name = "Repeater" }; controlList.Add(repeater); RepeaterControl nestedRepeater = new RepeaterControl { Id = 4, Name = "NestedRepeater", ParentId = 3 }; repeater.Controls.Add(nestedRepeater); RepeaterControl nestedNestedRepeater = new RepeaterControl { Id = 5, Name = "NestedNestedRepeater", ParentId = 4 }; nestedRepeater.Controls.Add(nestedNestedRepeater); nestedNestedRepeater.Controls.Add(new TextControl { Id = 1, Name = "Field1", ParentId = 5 }); // Compare to root level controlList.Add(new TextControl { Id = 2, Name = "Field2" }); var validExample = new Dictionary<string, object> { { "Field1", "Is Valid" } }; var invalidExample = new Dictionary<string, object> { { "Field1", "Is Not Valid" } }; ApplicationData appData = new ApplicationData(); Dictionary<string, object>[] repeaterData = new Dictionary<string, object>[2]; appData.Add("Field2", "Is Not Valid"); appData.Add("Repeater", repeaterData); repeaterData[0] = new Dictionary<string, object>() { { "NestedRepeater", new[] { new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { invalidExample, validExample } } }, new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { invalidExample, invalidExample } } }, } } }; repeaterData[1] = new Dictionary<string, object>() { { "NestedRepeater", new[] { new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { invalidExample } } }, new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { validExample } } }, } } }; TruthConditionEvaluatorFactory evaluatorFactory = new TruthConditionEvaluatorFactory(); ITruthConditionValidator validator = new ITruthConditionValidator(condition, controlList, evaluatorFactory); ValidationResults results = validator.Validate(appData); Assert.AreEqual(false, results.IsValid); Assert.AreEqual(4, results.Count); Assert.AreEqual("Repeater[0].NestedRepeater[0].NestedNestedRepeater[0].Field1", results.ToArray()[0].Key); Assert.AreEqual("Repeater[0].NestedRepeater[1].NestedNestedRepeater[0].Field1", results.ToArray()[1].Key); Assert.AreEqual("Repeater[0].NestedRepeater[1].NestedNestedRepeater[1].Field1", results.ToArray()[2].Key); Assert.AreEqual("Repeater[1].NestedRepeater[0].NestedNestedRepeater[0].Field1", results.ToArray()[3].Key); }
/// <summary> /// Returns a test data baseline. /// </summary> /// <returns>A test data baseline.</returns> private Application GetTestDataBaseline() { ApplicationData data = new ApplicationData { { "MandatoryDateField", "05/05/2000" }, { "DateRangeField", "01/01/2000" }, { "OptionalDateField", string.Empty }, { "MandatoryTextField", "John Doe" }, { "OptionalTextField", string.Empty }, { "OptionalTextFieldTwo", string.Empty }, { "MandatoryComboField", "Lorum" }, { "OptionalComboField", "Batman" }, { "MandatoryMultiselectComboField", new[] { "Multiselect", "Field" } }, { "MandatoryCheckbox", "checked" }, { "OptionalCheckbox", string.Empty }, { "Telephone", "(03) 9999 8888" }, { "MandatoryCheckboxGroup", new[] { "Opt2", "Opt4" } } }; List<Dictionary<string, object>> repeaterArr = new List<Dictionary<string, object>> { new Dictionary<string, object>() }; repeaterArr[0].Add("Repeater_child_1", "Item1 Child1"); repeaterArr[0].Add("Repeater_child_2", string.Empty); repeaterArr[0].Add("Repeater_child_3", "Item1 Child3"); repeaterArr[0].Add("Show_radio", "No"); repeaterArr[0].Add("Repeater_child_4", string.Empty); data.Add("Repeater", repeaterArr.ToArray()); data.Add("Repeater2", new Dictionary<string, object>[0]); return new Application(data); }
public void NestedRepeaterControlIsHiddenByRule() { ControlList controlList = JsonConvert.DeserializeObject<ControlList>(this.GetTestResource("HideRuleNestedRepeater.json"), new JsonKnownTypeConverter()); TextControl control = controlList.FindRecursive<TextControl>(4); ApplicationData postedData = new ApplicationData(); Dictionary<string, object> hiddenItem = new Dictionary<string, object> { { "Textbox", "validate me!" }, { "RuleTrigger", "HIDE IT" } }; Dictionary<string, object> visibleItem = new Dictionary<string, object> { { "Textbox", "validate me!" }, { "RuleTrigger", "DON'T HIDE IT" } }; /* * Repeater * - Row 0 (Nested Repeater) * - Row 0 (Textbox, Hidden Trigger) * - Row 1 (Textbox, Visible Trigger) * - Row 2 (Textbox, Visible Trigger) * - Row 1 (Nested Repeater) * - Row 0 (Textbox, Visible Trigger) * - Row 1 (Textbox, Hidden Trigger) * - Row 2 (Textbox, Hidden Trigger) */ Dictionary<string, object>[] repeaterData = new Dictionary<string, object>[2]; postedData.Add("Repeater", repeaterData); repeaterData[0] = new Dictionary<string, object>() { { "NestedRepeater", new[] { hiddenItem, visibleItem, visibleItem } } }; repeaterData[1] = new Dictionary<string, object>() { { "NestedRepeater", new[] { visibleItem, hiddenItem, hiddenItem } } }; // Test different indices and orders Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[0]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[1]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[2]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[0]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[1]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[2]")); }
public void MultiLevelNestedRepeaterControlIsHiddenByRootParentRule() { ControlList controlList = JsonConvert.DeserializeObject<ControlList>(this.GetTestResource("HideRuleMultiNestedRepeaterRootParent.json"), new JsonKnownTypeConverter()); TextControl control = controlList.FindRecursive<TextControl>(5); ApplicationData postedData = new ApplicationData(); Dictionary<string, object> validateBox = new Dictionary<string, object> { { "Textbox", "validate me!" } }; /* * Repeater * - Row 0 (Nested Repeater, Visible Trigger) * - Row 0 (NestedNested Repeater) * - Row 0 (Textbox) * - Row 1 (Textbox) * - Row 2 (Textbox) * - Row 1 (NestedNested Repeater) * - Row 0 (Textbox) * - Row 1 (Textbox) * - Row 2 (Textbox) * - Row 2 (NestedNested Repeater) * - Row 0 (Textbox) * - Row 1 (Textbox) * - Row 2 (Textbox) * - Row 1 (Nested Repeater, Hidden Trigger) * - Row 0 (NestedNested Repeater) * - Row 0 (Textbox) * - Row 1 (Textbox) * - Row 2 (Textbox) * - Row 1 (NestedNested Repeater) * - Row 0 (Textbox) * - Row 1 (Textbox) * - Row 2 (Textbox) * - Row 2 (NestedNested Repeater) * - Row 0 (Textbox) * - Row 1 (Textbox) * - Row 2 (Textbox) */ // Add root visible trigger postedData.Add("RuleTrigger", "DON'T HIDE IT"); // Add root repeater Dictionary<string, object>[] repeaterData = new Dictionary<string, object>[2]; postedData.Add("Repeater", repeaterData); repeaterData[0] = new Dictionary<string, object>() { { "NestedRepeater", new[] { new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { validateBox, validateBox, validateBox } } }, new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { validateBox, validateBox, validateBox } } }, new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { validateBox, validateBox, validateBox } } } } } }; repeaterData[1] = new Dictionary<string, object>() { { "NestedRepeater", new[] { new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { validateBox, validateBox, validateBox } } }, new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { validateBox, validateBox, validateBox } } }, new Dictionary<string, object>() { { "NestedNestedRepeater", new[] { validateBox, validateBox, validateBox } } } } } }; // Test different indices and orders Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[0].NestedNestedRepeater[0]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[0].NestedNestedRepeater[1]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[0].NestedNestedRepeater[2]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[1].NestedNestedRepeater[0]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[1].NestedNestedRepeater[1]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[1].NestedNestedRepeater[2]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[2].NestedNestedRepeater[0]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[2].NestedNestedRepeater[1]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[2].NestedNestedRepeater[2]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[0].NestedNestedRepeater[0]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[0].NestedNestedRepeater[1]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[0].NestedNestedRepeater[2]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[1].NestedNestedRepeater[0]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[1].NestedNestedRepeater[1]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[1].NestedNestedRepeater[2]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[2].NestedNestedRepeater[0]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[2].NestedNestedRepeater[1]")); Assert.IsTrue(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[2].NestedNestedRepeater[2]")); // Change trigger to hide postedData["RuleTrigger"] = "HIDE IT"; // Test different indices and orders Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[0].NestedNestedRepeater[0]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[0].NestedNestedRepeater[1]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[0].NestedNestedRepeater[2]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[1].NestedNestedRepeater[0]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[1].NestedNestedRepeater[1]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[1].NestedNestedRepeater[2]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[2].NestedNestedRepeater[0]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[2].NestedNestedRepeater[1]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[0].NestedRepeater[2].NestedNestedRepeater[2]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[0].NestedNestedRepeater[0]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[0].NestedNestedRepeater[1]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[0].NestedNestedRepeater[2]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[1].NestedNestedRepeater[0]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[1].NestedNestedRepeater[1]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[1].NestedNestedRepeater[2]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[2].NestedNestedRepeater[0]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[2].NestedNestedRepeater[1]")); Assert.IsFalse(control.IsVisible(controlList, postedData, null, this.register, "Repeater[1].NestedRepeater[2].NestedNestedRepeater[2]")); }