Ejemplo n.º 1
0
        public void ParseNoData2()
        {
            // 变量大小写
            var dic = new Dictionary <String, Object>()
            {
                ["userid"] = 1234
            };
            var builder = new WhereBuilder
            {
                Factory    = Log.Meta.Factory,
                Expression = "CreateUserID={#userId}",
            };

            builder.SetData2(dic);

            // 变量大小写
            //var ex = Assert.Throws<ArgumentException>("Data2", () => builder.GetExpression());
            //Assert.NotNull(ex);

            var exp = builder.GetExpression();

            Assert.NotNull(exp);

            var fe = exp as FieldExpression;

            Assert.NotNull(fe);
            Assert.Equal(Log._.CreateUserID, fe.Field);
            Assert.Equal("=", fe.Action);
            Assert.Null(fe.Value);
        }
Ejemplo n.º 2
0
        public void ParseOr()
        {
            var dic = new Dictionary <String, Object>(StringComparer.OrdinalIgnoreCase)
            {
                ["SiteIds"] = new[] { 2, 4, 8, 16 },
                ["userid"]  = 1234
            };
            var builder = new WhereBuilder
            {
                Factory    = Log.Meta.Factory,
                Expression = "linkid in{#SiteIds} or CreateUserID={#userId}",
            };

            builder.SetData2(dic);

            var exp = builder.GetExpression();

            Assert.NotNull(exp);

            var where = exp as WhereExpression;
            Assert.NotNull(where);
            Assert.Equal(Operator.Or, where.Operator);

            var left = where.Left as FormatExpression;

            Assert.NotNull(left);
            Assert.Equal(Log._.LinkID, left.Field);
            Assert.Equal("{0} In({1})", left.Format);
            Assert.Equal(dic["SiteIds"], left.Value);
        }
Ejemplo n.º 3
0
        public void EvalFail(String exp)
        {
            var dic = new Dictionary <String, Object>(StringComparer.OrdinalIgnoreCase)
            {
                ["SiteIds"] = new[] { 2, 4, 8, 16 },
                ["userid"]  = 1234
            };
            var builder = new WhereBuilder
            {
                Factory    = Log.Meta.Factory,
                Expression = exp,
            };

            builder.SetData(dic);
            builder.SetData2(dic);

            var log = new Log {
                LinkID = 17, CreateUserID = 1235
            };

            var rs = builder.Eval(log);

            Assert.False(rs);
        }