public void Deserialize_combined_filter_tree()
        {
            var d          = @"{
  ""LogicalOperator"" : ""Or"",
  ""LHS"" : {
		""LogicalOperator"" : ""And"",
		""LHS"" : {
			""Property"" : ""Salary"",
	        ""Operation"" : ""GreaterThan"",
			""Value"" : ""10000""
		},
		""RHS"" :{
			""Property"" : ""Name"",
			""Operation"" : ""StartsWith"",
			""Value"" : ""Ra""
		}
  },
  ""RHS"" :{
	""Property"" : ""Name"",
	""Operation"" : ""StartsWith"",
	""Value"" : ""Shy""
  } 
}";
            var jsonFilter = new JsonFilterExpression(d);
            var f          = jsonFilter.Filter <TestItem>();

            var filteredItems = f.Apply(_testItems).ToArray();

            Assert.That(filteredItems.Length, Is.EqualTo(2));
        }
        public void Deserialize_filter_with_empty_json()
        {
            var jsonFilter = new JsonFilterExpression(@"{}");
            var f          = jsonFilter.Filter <TestItem>();

            var filteredItems = f.Apply(_testItems).ToArray();

            Assert.That(filteredItems.Length, Is.EqualTo(5));
        }
Esempio n. 3
0
        public void Serialize_and_filter_with_one_filter_expression()
        {
            var expression = new LeafFilterExpression()
            {
                Operation = OperationType.GreaterThan, Property = "Salary", Value = 10000
            };
            var json = new JsonFilterExpression(expression.Json());

            var filteredItems = json.Filter <TestItem>().Apply(_testItems);

            Assert.That(filteredItems.Count(), Is.EqualTo(2));
        }
        public void Deserialize_filter_with_one_less_than_condition()
        {
            var d = @"{
			""Property"" : ""Salary"",
			""Operation"" : ""LessThan"",
			""Value"" : ""10000""
		}"        ;

            var jsonFilter = new JsonFilterExpression(d);
            var f          = jsonFilter.Filter <TestItem>();

            var filteredItems = f.Apply(_testItems).ToArray();

            Assert.That(filteredItems.Length, Is.EqualTo(1));
        }
        public void Throws_exception_for_invalid_logical_operator()
        {
            var d          = @"{
  ""LogicalOperator"" : ""INVALID"",
  ""LHS"" : {
			""Property"" : ""Salary"",
			""Operation"" : ""GreaterThan"",
			""Value"" : ""10000""
	},
  ""RHS"" :{
            ""Property"" : ""Name"",
			""Operation"" : ""StartsWith"",
			""Value"" : ""Ra""
    }
}";
            var jsonFilter = new JsonFilterExpression(d);

            Assert.Throws <ArgumentException>(() => jsonFilter.Filter <TestItem>());
        }
Esempio n. 6
0
        public void Serialize_and_filter_with_combined_or_filter_expression()
        {
            var lhs = new LeafFilterExpression()
            {
                Operation = OperationType.GreaterThan, Property = "Salary", Value = 10000
            };

            var rhs = new LeafFilterExpression()
            {
                Operation = OperationType.Contains, Property = "Name", Value = "am"
            };

            var combined = new CompositeFilterExpression()
            {
                LHS = lhs, RHS = rhs, LogicalOperator = LogicalOperator.Or
            };

            var json = new JsonFilterExpression(combined.Json());

            var filteredItems = json.Filter <TestItem>().Apply(_testItems);

            Assert.That(filteredItems.Count(), Is.EqualTo(3));
        }