public void verify_context_with_diff_check() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children[0].Age", Operator = Operator.DiffWithinPct, Right = "Children[1].Age", RightSideIsExpression = true, OperatorArgs = new [] { "100" } }, new LeafExpression() { Left = "Children.Count()", Operator = Operator.Equals, Right = "2" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void verify_context_with_date_field_filter_returns_true() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "FirstName", Operator = Operator.Equals, Right = "Donald" }, new LeafExpression() { Left = "BirthDate", Operator = Operator.LessThan, Right = "2020-04-07T15:47:54.760654-07:00" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void verify_context_with_expression_on_each_side_returns_true() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children[0].LastName", Operator = Operator.Equals, Right = "Children[1].LastName", RightSideIsExpression = true }, new LeafExpression() { Left = "Children.Count()", Operator = Operator.Equals, Right = "2" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void verify_context_with_enum_field_in_filter_returns_true() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "FirstName", Operator = Operator.Equals, Right = "Donald" }, new LeafExpression() { Left = "Race", Operator = Operator.In, Right = "Black,White" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void verify_context_with_nested_properties_returns_true() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "FirstName", Operator = Operator.Equals, Right = "Donald" }, new LeafExpression() { Left = "LastName", Operator = Operator.Equals, Right = "Trump" }, new LeafExpression() { Left = "Spouse.FirstName", Operator = Operator.Equals, Right = "Melania" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void verify_context_with_array_contains_filter_returns_true() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "FirstName", Operator = Operator.Equals, Right = "Donald" }, new LeafExpression() { Left = "Hobbies", Operator = Operator.Contains, Right = "Golf" }, new LeafExpression() { Left = "Spouse.FirstName", Operator = Operator.NotEquals, Right = "Ivanka" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void verify_context_with_all_in_range_check() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.Select(Age)", Operator = Operator.AllInRangePct, Right = "15,25", OperatorArgs = new [] { "10" } }, new LeafExpression() { Left = "Children.Count()", Operator = Operator.Equals, Right = "2" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void verify_context_with_composite_filters_returns_true() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new NotExpression() { Not = new LeafExpression() { Left = "Country", Operator = Operator.Equals, Right = "Canada" } }, new LeafExpression() { Left = "City", Operator = Operator.Equals, Right = "Redmond" }, new LeafExpression() { Left = "State", Operator = Operator.Equals, Right = "WA" } } }; Runner.RunScenario( given => An_evaluation_context <Location>("redmond"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
private void ShouldBeEquivalent(AllOfExpression actual, AllOfExpression expected) { actual.AllOf.Length.Should().Be(expected.AllOf.Length); for (var i = 0; i < actual.AllOf.Length; i++) { var actualChild = actual.AllOf[i]; var expectedChild = expected.AllOf[i]; ShouldBeEquivalent(actualChild, expectedChild); } }
public void verify_context_with_indexed_array_filter_returns_true() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "FirstName", Operator = Operator.Equals, Right = "Donald" }, new LeafExpression() { Left = "Hobbies", Operator = Operator.Contains, Right = "Golf" }, new LeafExpression() { Left = "Spouse.FirstName", Operator = Operator.StartsWith, Right = "Mel" }, new LeafExpression() { Left = "Children[0].FirstName", Operator = Operator.Equals, Right = "Tiffany" }, new LeafExpression() { Left = "Titles[1]", Operator = Operator.NotEquals, Right = "Scientist" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void Accept_multiple_filters() { var json = $@" {{ ""allOf"": [ {{ ""left"": ""DeviceType"", ""operator"": ""Equals"", ""right"": ""Breaker"" }}, {{ ""left"": ""Hierarchy"", ""operator"": ""In"", ""right"": ""ATS"" }} ] }}"; var expected = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "DeviceType", Operator = Operator.Equals, Right = "Breaker", RightSideIsExpression = false }, new LeafExpression() { Left = "Hierarchy", Operator = Operator.In, Right = "ATS", RightSideIsExpression = false } } }; Runner.RunScenario( given => A_leaf_expression(json), when => I_parse_json_expression(), then => Parsed_expression_should_be(expected)); }
public void should_be_able_to_call_min_with_arg() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.Min(Age)", Operator = Operator.Equals, Right = "14" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_get_dinstinct_count_on_string_list() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Titles.DistinctCount()", Operator = Operator.Equals, Right = "2" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_call_self_macro_with_args() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Self.IsAdult(18)", Operator = Operator.Equals, Right = "true" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_stop_traverse_at_loop() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Traverse(Parent, Id)", Operator = Operator.ContainsAll, Right = "A,B,C,!!" } } }; Runner.RunScenario( given => An_evaluation_context <TreeNode>("tree_with_loop"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_stop_traverse_before_max_steps_reached() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Traverse(Parent, Id, 1).Count()", Operator = Operator.Equals, Right = "2" } } }; Runner.RunScenario( given => An_evaluation_context <TreeNode>("correct_tree"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_call_orderbydesc() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.OrderByDesc(FirstName).First().FirstName", Operator = Operator.Equals, Right = "Tiffany" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_call_last_with_no_arg() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Hobbies.Last()", Operator = Operator.In, Right = "Golf,Tweeter" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_call_function_last() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.Last(FirstName, Equals, Tiffany).Age", Operator = Operator.GreaterThan, Right = "14" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_call_where_with_contains() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.Where(LastName, contains, 'ump').Select(FirstName)", Operator = Operator.AllIn, Right = "Tiffany,Barron" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_select_with_nested_function_inside() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.Select(Hobbies.OrderByDesc().First())", Operator = Operator.AllIn, Right = "Music,Soccer" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_call_selectmany() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.SelectMany(Hobbies)", Operator = Operator.AllIn, Right = "Arts, Music, Dancing, Soccer" } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_call_where_with_contains() { IConditionExpression filterExpr = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "LastReadings.Where(DataPoint, contains, 'Pwr.kW tot')", Operator = Operator.NotIsEmpty, Right = "" } } }; Runner.RunScenario( given => A_device("device_with_zenon_events"), when => A_filter_condition(filterExpr), then => Context_should_pass_filter(true)); }
public void should_be_able_to_call_function_ago() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "BirthDate", Operator = Operator.GreaterThan, Right = "Ago(50000d)", RightSideIsExpression = true } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }
public void should_be_able_to_compare_two_expressions() { IConditionExpression filter = new AllOfExpression() { AllOf = new IConditionExpression[] { new LeafExpression() { Left = "Children.Select(Age).Sum()", Operator = Operator.LessThan, Right = "Age", RightSideIsExpression = true } } }; Runner.RunScenario( given => An_evaluation_context <Person>("donald_trump"), when => I_evaluate_context_with_filter(filter), then => Evaluation_results_should_be(true)); }