public void MoreComplicated()
        {
            var rule =
                new Rule
            {
                Operator = "OrElse",
                Rules    = new List <Rule>
                {
                    new Rule
                    {
                        MemberName  = "FirstName",
                        Operator    = "Equal",
                        TargetValue = "Sally"
                    },
                    new Rule
                    {
                        MemberName  = "FirstName",
                        Operator    = "Equal",
                        TargetValue = "Jane"
                    }
                }
            };

            var expression = MRE.ToExpression <Student>(rule, false);

            using (var context = new TestDbContext(options))
            {
                var count = context.Students.Where(expression)
                            .Count();

                Assert.AreEqual(4,
                                count);
            }
        }
        public void SimpleRule_IncludeTryCatch()
        {
            var rule = new Rule
            {
                MemberName  = "FirstName",
                Operator    = "Equal",
                TargetValue = "Sally"
            };

            var expression = MRE.ToExpression <Student>(rule, true);

            using (var context = new TestDbContext(options))
            {
                var count = context.Students.Where(expression)
                            .Count();

                Assert.AreEqual(2,
                                count);
            }
        }
예제 #3
0
        public void BasicEqualityExpression()
        {
            using (var context = new BloggingContext(GetDBOptions()))
            {
                context.Blogs.Add(new Blog {
                    Url = "http://test.com"
                });
                context.SaveChanges();

                var testBlog = context.Blogs.FirstOrDefault(b => b.Url == "http://test.com");

                var  fields = MRE.Member.GetFields(typeof(Blog));
                Rule rule   = new Rule
                {
                    MemberName  = "Url",
                    Operator    = mreOperator.Equal.ToString("g"),
                    TargetValue = "http://test.com"
                };

                var blog2 = context.Blogs.Where(MRE.ToExpression <Blog>(rule, false)).FirstOrDefault();

                Assert.IsTrue(testBlog.BlogId == blog2.BlogId);
            }
        }