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 SerializeCompareValueArray() { IfTruthCondition rootCondition = new IfTruthCondition(); TruthConditionList conditionList = new TruthConditionList(); CompareTruthCondition compareCondition = new CompareTruthCondition(); conditionList.Add(compareCondition); rootCondition.Value = conditionList; CompareDefinition compareDefinition = new CompareDefinition(); compareCondition.Value = compareDefinition; compareDefinition.Value = new[] { "test1", "test2" }; string serialized = JsonConvert.SerializeObject(rootCondition); Assert.IsTrue(serialized.Contains("\"Value\":[\"test1\",\"test2\"]")); }
public void SerializeCompareValueString() { IfTruthCondition rootCondition = new IfTruthCondition(); TruthConditionList conditionList = new TruthConditionList(); CompareTruthCondition compareCondition = new CompareTruthCondition(); conditionList.Add(compareCondition); rootCondition.Value = conditionList; CompareDefinition compareDefinition = new CompareDefinition(); compareCondition.Value = compareDefinition; compareDefinition.Value = "test"; string serialized = JsonConvert.SerializeObject(rootCondition); Assert.IsTrue(serialized.Contains("\"Value\":\"test\"")); }
/// <summary> /// Get Friendly formatted operator. /// </summary> /// <param name="ruleString"> /// The rule string. /// </param> /// <param name="ruleOperation"> /// The rule operation. /// </param> /// <returns> /// Returns formatted ruleString. /// </returns> private static string ResolveRuleOperation(string ruleString, CompareDefinition ruleOperation) { var builder = new StringBuilder(ruleString); builder.Append("["); builder.Append(ruleOperation.Field); builder.Append("] "); switch (ruleOperation.Operator) { case Operator.Equals: builder.Append("equals "); break; case Operator.NotEquals: builder.Append("does not equal "); break; case Operator.GreaterThan: builder.Append("is greater than "); break; case Operator.GreaterThanOrEqualTo: builder.Append("is greater than or equal to "); break; case Operator.LessThan: builder.Append("is less than "); break; case Operator.LessThanOrEqualTo: builder.Append("is less than or equal to "); break; case Operator.In: builder.Append("is in "); break; case Operator.NotIn: builder.Append("is not in "); break; } if (ruleOperation.CompareTo == ComparisonType.Value) { object value = ruleOperation.Value; var values = ruleOperation.Value as IEnumerable<string>; if (values != null) { value = string.Join(",", values); } builder.Append("'"); builder.Append(value); builder.Append("' "); } else { builder.Append("field ["); builder.Append(ruleOperation.Value); builder.Append("] "); } return builder.ToString(); }
/// <summary> /// Determine the organization. /// </summary> /// <param name="orgMapDefinition">Defines how to determine the organization.</param> /// <param name="application">The application.</param> /// <returns>The organization the application should be entitled to, or <see langword="null"/>.</returns> private Organisation DetermineOrganisation(CompareDefinition orgMapDefinition, Application application) { OrganisationList organisationList = this.organisationManager.GetOrganisationList(); Organisation defaultOrg = string.IsNullOrEmpty(application.OrganisationId) ? null : organisationList.FirstOrDefault(o => o.Id == application.OrganisationId); if (orgMapDefinition == null) { return defaultOrg; } string formValue = application.ApplicationData.GetValue(orgMapDefinition.Field, string.Empty); if (orgMapDefinition.CompareTo == ComparisonType.Value) { PropertyInfo info = typeof(Organisation).GetProperty(orgMapDefinition.Value.ToString()); if (info == null) { return defaultOrg; } foreach (var org in organisationList) { object propValue = info.GetValue(org); if (propValue != null && propValue.ToString() == formValue) { return org; } } } if (orgMapDefinition.CompareTo == ComparisonType.Field) { string metaValue = orgMapDefinition.Value.ToString(); foreach (var org in organisationList) { if (org.ExtendedProperties.ContainsKey(metaValue) && org.ExtendedProperties[metaValue] == formValue) { return org; } } } return defaultOrg; }