public void ParsePredicate_Enum_Succeed()
        {
            var query = $"Option='{TestOptions.Option1}' and Option != 1 and Option = 0  and Option in ['{TestOptions.Option1}','{TestOptions.Option2}','{TestOptions.Option3}']";
            var and1  = Interpreter.ParsePredicate <TestEntity>(query);
            var and2  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&&"));
            var and3  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&"));
            var or1   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "or"));
            var or2   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "||"));
            var or3   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "|"));

            Assert.True(and1.Succeeded);
            Assert.True(and2.Succeeded);
            Assert.True(and3.Succeeded);
            Assert.True(or1.Succeeded);
            Assert.True(or2.Succeeded);
            Assert.True(or3.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(and1.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and2.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and3.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(or1.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or2.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or3.Result);
                Assert.True(value > 0);
            }
        }
Exemple #2
0
        public void TryBuildPredicate_FilterGroups_Succeed()
        {
            var query = new FilterGroup[]
            {
                new FilterGroup
                {
                    Filters = new List <Filter>
                    {
                        new Filter {
                            Property = "Integer", Operator = "=", Value = DF.Integer1.ToString()
                        },
                        new Filter {
                            Property = "String", Operator = "=", Value = DF.String1
                        }
                    }
                },
                new FilterGroup
                {
                    Filters = new List <Filter>
                    {
                        new Filter {
                            Property = "Integer", Operator = "=", Value = DF.Integer3.ToString()
                        }
                    }
                }
            }.TryBuildPredicate <TestEntity>(validProperties: new string[] { "Integer", "String" });

            Assert.True(query.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(query.Result);
                Assert.Equal(2, value);
            }
        }
        public void TryOrderBy_Success()
        {
            using (var context = DF.GetContext())
            {
                var result = context.Entities.Where(p => p.OrderBy1 < 50).TryOrderBy("OrderBy1 desc, OrderBy2 desc");
                Assert.True(result.Succeeded);
                var value = result.Result.FirstOrDefault();
                Assert.Equal("EBC", value.OrderBy2);

                result = context.Entities.Where(p => p.OrderBy1 < 50).TryOrderBy(new[] { new OrderByInfo {
                                                                                             Property = "OrderBy1", Descending = true
                                                                                         }, new OrderByInfo {
                                                                                             Property = "OrderBy2", Descending = true
                                                                                         } });
                Assert.True(result.Succeeded);
                value = result.Result.FirstOrDefault();
                Assert.Equal("EBC", value.OrderBy2);

                result = context.Entities.TryOrderBy("OrderBy1 desc, OrderBy2 desc", new[] { "OrderBy1" });
                Assert.False(result.Succeeded);
                Assert.True(result.InvalidProperties.Count() == 1 && result.InvalidProperties.First() == "OrderBy2");

                result = context.Entities.TryOrderBy(new[] { new OrderByInfo {
                                                                 Property = "OrderBy1", Descending = true
                                                             }, new OrderByInfo {
                                                                 Property = "OrderBy2", Descending = true
                                                             } }, new[] { "OrderBy1" });
                Assert.False(result.Succeeded);
                Assert.True(result.InvalidProperties.Count() == 1 && result.InvalidProperties.First() == "OrderBy2");
            }
        }
        public void ParsePredicate_Guid_Succeed()
        {
            var query = $"Guid='{DF.Guid1}' and Guid in ['{DF.Guid1}','{DF.Guid2}','{DF.Guid3}']";
            var and1  = Interpreter.ParsePredicate <TestEntity>(query);
            var and2  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&&"));
            var and3  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&"));
            var or1   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "or"));
            var or2   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "||"));
            var or3   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "|"));

            Assert.True(and1.Succeeded);
            Assert.True(and2.Succeeded);
            Assert.True(and3.Succeeded);
            Assert.True(or1.Succeeded);
            Assert.True(or2.Succeeded);
            Assert.True(or3.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(and1.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and2.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and3.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(or1.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or2.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or3.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_String_Succeed()
        {
            var query = $"String='{DF.String1}' and String != null and String @* 'N' and String *@ '1' and String @ 'm' and String in ['{DF.String1}','{DF.String2}','{DF.String3}','{DF.DoubleN}']";
            var and1  = Interpreter.ParsePredicate <TestEntity>(query);
            var and2  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&&"));
            var and3  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&"));
            var or1   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "or"));
            var or2   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "||"));
            var or3   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "|"));

            Assert.True(and1.Succeeded);
            Assert.True(and2.Succeeded);
            Assert.True(and3.Succeeded);
            Assert.True(or1.Succeeded);
            Assert.True(or2.Succeeded);
            Assert.True(or3.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(and1.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and2.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and3.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(or1.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or2.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or3.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_Double_Succeed()
        {
            var query = $"Double={DF.Double3} and Double != 0.0 and Double<{DF.DoubleN} and Double<={DF.Double3} and Double>={DF.Double1} and Double>0.0 and Double in [{DF.Double1},{DF.Double2},{DF.Double3},{DF.DoubleN}]";
            var and1  = Interpreter.ParsePredicate <TestEntity>(query);
            var and2  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&&"));
            var and3  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&"));
            var or1   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "or"));
            var or2   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "||"));
            var or3   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "|"));

            Assert.True(and1.Succeeded);
            Assert.True(and2.Succeeded);
            Assert.True(and3.Succeeded);
            Assert.True(or1.Succeeded);
            Assert.True(or2.Succeeded);
            Assert.True(or3.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(and1.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and2.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and3.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(or1.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or2.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or3.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_Integer_Succeed()
        {
            var query = $"Integer={DF.Integer1} and Integer != 0 and Integer<{DF.Integer2} and Integer<={DF.Integer1} and Integer>={DF.Integer1} and Integer>0 and Integer in [{DF.Integer1},{DF.Integer2},{DF.Integer3}]";
            var and1  = Interpreter.ParsePredicate <TestEntity>(query);
            var and2  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&&"));
            var and3  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&"));
            var or1   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "or"));
            var or2   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "||"));
            var or3   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "|"));

            Assert.True(and1.Succeeded);
            Assert.True(and2.Succeeded);
            Assert.True(and3.Succeeded);
            Assert.True(or1.Succeeded);
            Assert.True(or2.Succeeded);
            Assert.True(or3.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(and1.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and2.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and3.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(or1.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or2.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or3.Result);
                Assert.True(value > 0);
            }
        }
        public void OrderBy_Expression_PropertyMapping_Success()
        {
            var propertyMapping = new Dictionary <string, string> {
                ["Name"] = "OrderBy1"
            };

            using (var context = DF.GetContext())
            {
                var value = context.Entities.OrderBy("Name", propertyMapping: propertyMapping).FirstOrDefault();
                Assert.Equal(10, value.OrderBy1);
                value = context.Entities.OrderBy("Name asc", propertyMapping: propertyMapping).FirstOrDefault();
                Assert.Equal(10, value.OrderBy1);
                value = context.Entities.OrderBy("Name desc", propertyMapping: propertyMapping).FirstOrDefault();
                Assert.Equal(50, value.OrderBy1);
                value = context.Entities.Where(p => p.OrderBy1 < 50).OrderBy("Name desc, OrderBy2 desc", propertyMapping: propertyMapping).FirstOrDefault();
                Assert.Equal("EBC", value.OrderBy2);
                value = context.Entities.OrderBy(new[] { new OrderByInfo {
                                                             Property = "Name"
                                                         } }, propertyMapping: propertyMapping).FirstOrDefault();
                Assert.Equal(10, value.OrderBy1);
                value = context.Entities.OrderBy(new[] { new OrderByInfo {
                                                             Property = "Name", Descending = true
                                                         } }, propertyMapping: propertyMapping).FirstOrDefault();
                Assert.Equal(50, value.OrderBy1);
                value = context.Entities.Where(p => p.OrderBy1 < 50).OrderBy(new[] { new OrderByInfo {
                                                                                         Property = "Name", Descending = true
                                                                                     }, new OrderByInfo {
                                                                                         Property = "OrderBy2", Descending = true
                                                                                     } }, propertyMapping: propertyMapping).FirstOrDefault();
                Assert.Equal("EBC", value.OrderBy2);

                var result = context.Entities.Where(p => p.OrderBy1 < 50).TryOrderBy("Name desc, OrderBy2 desc", propertyMapping: propertyMapping);
                Assert.True(result.Succeeded);
                value = result.Result.FirstOrDefault();
                Assert.Equal("EBC", value.OrderBy2);

                result = context.Entities.Where(p => p.OrderBy1 < 50).TryOrderBy(new[] { new OrderByInfo {
                                                                                             Property = "Name", Descending = true
                                                                                         }, new OrderByInfo {
                                                                                             Property = "OrderBy2", Descending = true
                                                                                         } }, propertyMapping: propertyMapping);
                Assert.True(result.Succeeded);
                value = result.Result.FirstOrDefault();
                Assert.Equal("EBC", value.OrderBy2);

                result = context.Entities.TryOrderBy("Name desc, OrderBy2 desc", new[] { "Name" }, propertyMapping: propertyMapping);
                Assert.False(result.Succeeded);
                Assert.True(result.InvalidProperties.Count() == 1 && result.InvalidProperties.First() == "OrderBy2");

                result = context.Entities.TryOrderBy(new[] { new OrderByInfo {
                                                                 Property = "Name", Descending = true
                                                             }, new OrderByInfo {
                                                                 Property = "OrderBy2", Descending = true
                                                             } }, new[] { "Name" }, propertyMapping: propertyMapping);
                Assert.False(result.Succeeded);
                Assert.True(result.InvalidProperties.Count() == 1 && result.InvalidProperties.First() == "OrderBy2");
            }
        }
        public void ParsePredicate_String_ComparisonFunction_Succeed()
        {
            var query = $"String='{DF.String1}' and String != null and String.startsWith(String) and String.endsWith('1') and String.contains('m') and String in ['{DF.String1}','{DF.String2}','{DF.String3}','{DF.StringN}']";
            var and1  = Interpreter.ParsePredicate <TestEntity>(query);
            var and2  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&&"));
            var and3  = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "&"));
            var or1   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "or"));
            var or2   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "||"));
            var or3   = Interpreter.ParsePredicate <TestEntity>(query.Replace("and", "|"));
            var t1    = Interpreter.ParsePredicate <TestEntity>($"'{DF.String1}'.contains('Name')");
            var t2    = Interpreter.ParsePredicate <TestEntity>($"'{DF.String1}'.startsWith('Name')");
            var t3    = Interpreter.ParsePredicate <TestEntity>($"'{DF.String1}'.endsWith('1')");
            var t4    = Interpreter.ParsePredicate <TestEntity>($"'{DF.String1}' @ 'Name'");
            var t5    = Interpreter.ParsePredicate <TestEntity>($"'{DF.String1}' @* 'Name'");
            var t6    = Interpreter.ParsePredicate <TestEntity>($"'{DF.String1}' *@ '1'");

            Assert.True(and1.Succeeded);
            Assert.True(and2.Succeeded);
            Assert.True(and3.Succeeded);
            Assert.True(or1.Succeeded);
            Assert.True(or2.Succeeded);
            Assert.True(or3.Succeeded);
            Assert.True(t1.Succeeded);
            Assert.True(t2.Succeeded);
            Assert.True(t3.Succeeded);
            Assert.True(t4.Succeeded);
            Assert.True(t5.Succeeded);
            Assert.True(t6.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(and1.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and2.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(and3.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(or1.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or2.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(or3.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(t1.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(t2.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(t3.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(t4.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(t5.Result);
                Assert.True(value > 0);
                value = context.Entities.Count(t6.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_CustomVariableResolver_Success()
        {
            var result = Interpreter.ParsePredicate <TestEntity>("Integer=user.Id", new CustomVariableResolver());

            Assert.True(result.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(1, value);
            }
        }
        public void ParsePredicate_ComplicatedGroup_Success()
        {
            var result = Interpreter.ParsePredicate <TestEntity>($"(Integer={DF.Integer1} or Double={DF.Double3}) and (Guid=='{DF.Guid1}' or DateTime='{DF.DateTime3}')");

            Assert.True(result.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(2, value);
            }
        }
        public void ParsePredicate_NestedProperty_Succeed()
        {
            var result = Interpreter.ParsePredicate <TestEntity>($"Parent.Id = 1 and Parent.Id >= 1");

            Assert.True(result.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(1, value);
            }
        }
 public void OrderBy_Expression_Success()
 {
     using (var context = DF.GetContext())
     {
         var value = context.Entities.OrderBy("OrderBy1").FirstOrDefault();
         Assert.Equal(10, value.OrderBy1);
         value = context.Entities.OrderBy("OrderBy1 asc").FirstOrDefault();
         Assert.Equal(10, value.OrderBy1);
         value = context.Entities.OrderBy("OrderBy1 desc").FirstOrDefault();
         Assert.Equal(50, value.OrderBy1);
         value = context.Entities.Where(p => p.OrderBy1 < 50).OrderBy("OrderBy1 desc, OrderBy2 desc").FirstOrDefault();
         Assert.Equal("EBC", value.OrderBy2);
     }
 }
        public void ParsePredicate_DateTimeOffsetNullable_Succeed()
        {
            var result  = Interpreter.ParsePredicate <TestEntity>($"DateTimeOffsetNullable='{DF.DateTimeOffsetString1}' and DateTimeOffsetNullable!=null");
            var result2 = Interpreter.ParsePredicate <TestEntity>($"DateTimeOffsetNullable>'{DF.DateTimeOffsetString1}'");

            Assert.True(result.Succeeded);
            Assert.True(result2.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(result2.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_BooleanAndBooleanNullable_Succeed()
        {
            var result  = Interpreter.ParsePredicate <TestEntity>($"Boolean and BooleanNullable=null");
            var result2 = Interpreter.ParsePredicate <TestEntity>($"BooleanNullable=true and Not(Boolean) and !Boolean and Boolean=false");

            Assert.True(result.Succeeded);
            Assert.True(result2.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(result2.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_DoubleNullable_Succeed()
        {
            var result  = Interpreter.ParsePredicate <TestEntity>($"Double={DF.Double2} and DoubleNullable=null");
            var result2 = Interpreter.ParsePredicate <TestEntity>($"DoubleNullable>0");

            Assert.True(result.Succeeded);
            Assert.True(result2.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(result2.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_EnumNullable_Succeed()
        {
            var result  = Interpreter.ParsePredicate <TestEntity>($"Option='{TestOptions.Option2}' and OptionNullable=null");
            var result2 = Interpreter.ParsePredicate <TestEntity>($"OptionNullable='{TestOptions.Option1}'");

            Assert.True(result.Succeeded);
            Assert.True(result2.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(result2.Result);
                Assert.True(value > 0);
            }
        }
Exemple #18
0
        public void ParsePredicate_CustomVariableResolver_Success()
        {
            var query = new Filter[]
            {
                new Filter {
                    Property = "Integer", Operator = "=", Value = "user.Id"
                }
            }.TryBuildPredicate <TestEntity>(new CustomVariableResolver(), validProperties: new string[] { "Integer" });

            Assert.True(query.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(query.Result);
                Assert.Equal(1, value);
            }
        }
Exemple #19
0
        public void BuildPredicate_Filters_Succeed()
        {
            var query = new Filter[]
            {
                new Filter {
                    Property = "Integer", Operator = "=", Value = DF.Integer1.ToString()
                },
                new Filter {
                    Property = "String", Operator = "=", Value = DF.String1
                }
            }.BuildPredicate <TestEntity>();

            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(query);
                Assert.Equal(1, value);
            }
        }
        public void ParsePredicate_PropertyMapping_Succeed()
        {
            var propertyMapping = new Dictionary <string, string> {
                ["Number"] = "Integer", ["NumberNullable"] = "IntegerNullable"
            };
            var validProperties = new[] { "Number", "NumberNullable" };
            var result          = Interpreter.ParsePredicate <TestEntity>($"Number={DF.Integer2} and NumberNullable=null", validProperties: validProperties, propertyMapping: propertyMapping);
            var result2         = Interpreter.ParsePredicate <TestEntity>($"NumberNullable>0", validProperties: validProperties, propertyMapping: propertyMapping);

            Assert.True(result.Succeeded);
            Assert.True(result2.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(1, value);
                value = context.Entities.Count(result2.Result);
                Assert.True(value > 0);
            }
        }
        public void ParsePredicate_DateTimeAndVariableResolver_Succeed()
        {
            //var query = $"DateTime='{DF.DateTime1}' and DateTime<'{DF.DateTime2}' and DateTime<='{DF.DateTime1}' and DateTime>='{DF.DateTime1}' and DateTime in ['{DF.DateTime1}','{DF.DateTime2}','{DF.DateTime3}']";
            //var query2 = $"DateTime='{DF.DateTimeString1}' and DateTime<'{DF.DateTimeString2}' and DateTime<='{DF.DateTimeString1}' and DateTime>='{DF.DateTimeString1}' and DateTime in ['{DF.DateTimeString1}','{DF.DateTimeString2}','{DF.DateTimeString3}']";
            var query3 = $"DateTime.Year=now.year and DateTime.Year==utcnow.year";
            //var and1 = Interpreter.ParsePredicate<TestEntity>(query);
            //var and1_1 = Interpreter.ParsePredicate<TestEntity>(query2);
            var and1_2 = Interpreter.ParsePredicate <TestEntity>(query3);

            //var and2 = Interpreter.ParsePredicate<TestEntity>(query.Replace("and", "&&"));
            //var and3 = Interpreter.ParsePredicate<TestEntity>(query.Replace("and", "&"));
            //var or1 = Interpreter.ParsePredicate<TestEntity>(query.Replace("and", "or"));
            //var or2 = Interpreter.ParsePredicate<TestEntity>(query.Replace("and", "||"));
            //var or3 = Interpreter.ParsePredicate<TestEntity>(query.Replace("and", "|"));
            //Assert.True(and1_1.Succeeded);
            Assert.True(and1_2.Succeeded);
            //Assert.True(and1.Succeeded);
            //Assert.True(and2.Succeeded);
            //Assert.True(and3.Succeeded);
            //Assert.True(or1.Succeeded);
            //Assert.True(or2.Succeeded);
            //Assert.True(or3.Succeeded);
            using (var context = DF.GetContext())
            {
                //var value = context.Entities.Count(and1.Result);
                //Assert.Equal(1, value);
                //value = context.Entities.Count(and1_1.Result);
                //Assert.Equal(1, value);
                var value = context.Entities.Count(and1_2.Result);
                Assert.Equal(1, value);
                //value = context.Entities.Count(and2.Result);
                //Assert.Equal(1, value);
                //value = context.Entities.Count(and3.Result);
                //Assert.Equal(1, value);
                //value = context.Entities.Count(or1.Result);
                //Assert.True(value > 0);
                //value = context.Entities.Count(or2.Result);
                //Assert.True(value > 0);
                //value = context.Entities.Count(or3.Result);
                //Assert.True(value > 0);
            }
        }
 public void OrderBy_OrderByInfo_Success()
 {
     using (var context = DF.GetContext())
     {
         var value = context.Entities.OrderBy(new[] { new OrderByInfo {
                                                          Property = "OrderBy1"
                                                      } }).FirstOrDefault();
         Assert.Equal(10, value.OrderBy1);
         value = context.Entities.OrderBy(new[] { new OrderByInfo {
                                                      Property = "OrderBy1", Descending = true
                                                  } }).FirstOrDefault();
         Assert.Equal(50, value.OrderBy1);
         value = context.Entities.Where(p => p.OrderBy1 < 50).OrderBy(new[] { new OrderByInfo {
                                                                                  Property = "OrderBy1", Descending = true
                                                                              }, new OrderByInfo {
                                                                                  Property = "OrderBy2", Descending = true
                                                                              } }).FirstOrDefault();
         Assert.Equal("EBC", value.OrderBy2);
     }
 }
Exemple #23
0
        public void TakeAndTakePage_Success()
        {
            var c = new ConditionOptions().BuildCondition <TestEntity>();
            var p = new Pagination {
                Offset = 1, Limit = 2
            };

            using (var context = DF.GetContext())
            {
                var e = context.Entities.Take(c, p);
                Assert.Equal(2, e.Count());
                var r = e.First();
                Assert.Equal(DF.Integer2, r.Integer);

                var page = context.Entities.TakePage(c, p);
                Assert.Equal(2, page.Records.Count());
                Assert.Equal(5, page.TotalRecords);
                r = page.Records.First();
                Assert.Equal(DF.Integer2, r.Integer);
            }
        }
Exemple #24
0
        public void BuildCondition_Success()
        {
            using (var context = DF.GetContext())
            {
                ConditionOptions       p;
                Condition <TestEntity> c;
                int value;
                p = new ConditionOptions
                {
                    Filters = new Filter[]
                    {
                        new Filter {
                            Property = "Integer", Operator = "=", Value = DF.Integer1.ToString()
                        },
                        new Filter {
                            Property = "String", Operator = "=", Value = DF.String1
                        }
                    }
                };
                c = p.BuildCondition <TestEntity>();
                Assert.True(c.IsValid);
                value = context.Entities.Where(c).Count();
                Assert.Equal(1, value);

                p = new ConditionOptions
                {
                    FilterGroups = new FilterGroup[]
                    {
                        new FilterGroup
                        {
                            Filters = new List <Filter>
                            {
                                new Filter {
                                    Property = "Integer", Operator = "=", Value = DF.Integer1.ToString()
                                },
                                new Filter {
                                    Property = "String", Operator = "=", Value = DF.String1
                                }
                            }
                        },
                        new FilterGroup
                        {
                            Filters = new List <Filter>
                            {
                                new Filter {
                                    Property = "Integer", Operator = "=", Value = DF.Integer3.ToString()
                                }
                            }
                        }
                    }
                };
                c = p.BuildCondition <TestEntity>();
                Assert.True(c.IsValid);
                value = context.Entities.Where(c).Count();
                Assert.Equal(2, value);

                p = new ConditionOptions {
                    Where = $"Integer={DF.Integer1} and String='{DF.String1}'"
                };
                c = p.BuildCondition <TestEntity>();
                Assert.True(c.IsValid);
                value = context.Entities.Where(c).Count();
                Assert.Equal(1, value);

                p = new ConditionOptions {
                    OrderBy = "OrderBy1 desc, OrderBy2 desc", Where = "OrderBy1 < 50"
                };
                c = p.BuildCondition <TestEntity>();
                Assert.True(c.IsValid);
                var e = context.Entities.Where(c).First();
                Assert.Equal("EBC", e.OrderBy2);

                p = new ConditionOptions {
                    OrderBys = new List <OrderByInfo> {
                        new OrderByInfo {
                            Property = "OrderBy1", Descending = true
                        }, new OrderByInfo {
                            Property = "OrderBy2", Descending = true
                        }
                    }, Where = "OrderBy1 < 50"
                };
                c = p.BuildCondition <TestEntity>();
                Assert.True(c.IsValid);
                e = context.Entities.Where(c).First();
                Assert.Equal("EBC", e.OrderBy2);
            }
        }
        public void ParsePredicate_NotOperatorAndNotFunction_Success()
        {
            var result   = Interpreter.ParsePredicate <TestEntity>($"!Boolean");
            var result2  = Interpreter.ParsePredicate <TestEntity>($"!(Boolean=true)");
            var result3  = Interpreter.ParsePredicate <TestEntity>($"not(Boolean)");
            var result4  = Interpreter.ParsePredicate <TestEntity>($"not(Boolean=true)");
            var result5  = Interpreter.ParsePredicate <TestEntity>($"!(Integer={DF.Integer1})");
            var result6  = Interpreter.ParsePredicate <TestEntity>($"!(Integer in [{DF.Integer1}])");
            var result7  = Interpreter.ParsePredicate <TestEntity>($"not(Integer={DF.Integer1})");
            var result8  = Interpreter.ParsePredicate <TestEntity>($"not(Integer in [{DF.Integer1}])");
            var result9  = Interpreter.ParsePredicate <TestEntity>($"!Boolean = true");
            var result10 = Interpreter.ParsePredicate <TestEntity>($"!(Boolean=true) == true");
            var result11 = Interpreter.ParsePredicate <TestEntity>($"not(Boolean) == true");
            var result12 = Interpreter.ParsePredicate <TestEntity>($"not(Boolean=true)==true");
            var result13 = Interpreter.ParsePredicate <TestEntity>($"!Boolean and !(Integer={DF.Integer1})");
            var result14 = Interpreter.ParsePredicate <TestEntity>($"not(Boolean) and not(Integer={DF.Integer1})");

            Assert.True(result.Succeeded);
            Assert.True(result2.Succeeded);
            Assert.True(result3.Succeeded);
            Assert.True(result4.Succeeded);
            Assert.True(result5.Succeeded);
            Assert.True(result6.Succeeded);
            Assert.True(result7.Succeeded);
            Assert.True(result8.Succeeded);
            Assert.True(result9.Succeeded);
            Assert.True(result10.Succeeded);
            Assert.True(result11.Succeeded);
            Assert.True(result12.Succeeded);
            using (var context = DF.GetContext())
            {
                var value = context.Entities.Count(result.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result2.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result3.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result4.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result5.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result6.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result7.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result8.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result9.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result10.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result11.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result12.Result);
                Assert.Equal(4, value);
                value = context.Entities.Count(result13.Result);
                Assert.Equal(3, value);
                value = context.Entities.Count(result14.Result);
                Assert.Equal(3, value);
            }
        }