Exemplo n.º 1
0
        public void Greater_Than_Or_Equal_Test()
        {
            Expression <Func <Entity, bool> > expression = x => x.Age >= 33;
            var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map);

            statement.Parameters.Count().ShouldEqual(1);
            statement.Parameters.First().Value.ShouldEqual(33);
            statement.Text.ShouldEqual(string.Format("([age] >= @{0})", statement.Parameters.First().Key));
        }
Exemplo n.º 2
0
        public void Unary_True_Test()
        {
            Expression <Func <Entity, bool> > expression = x => x.Active;
            var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map);

            statement.Parameters.Count().ShouldEqual(1);
            statement.Parameters.First().Value.ShouldEqual(true);
            statement.Text.ShouldEqual(string.Format("([active] = @{0})", statement.Parameters.First().Key));
        }
Exemplo n.º 3
0
        public void Equals_Boolean_Expression_Test()
        {
            Expression <Func <Entity, bool> > expression = x => x.Active == (x.Age == 33);
            var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map);

            statement.Parameters.Count().ShouldEqual(1);
            statement.Parameters.First().Value.ShouldEqual(33);
            statement.Text.ShouldEqual(string.Format("([active] = CASE WHEN ([age] = @{0}) THEN 1 ELSE 0 END)", statement.Parameters.First().Key));
        }
Exemplo n.º 4
0
        public void should_not_cast_dynamic_value()
        {
            var optout = (object)true;
            Expression <Func <Entity, bool> > expression = x => x.Values["optout"] == optout;
            var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map);

            statement.Parameters.Count().ShouldEqual(1);
            statement.Parameters.First().Value.ShouldEqual(true);
            statement.Text.ShouldEqual(string.Format("([optout] = @{0})", statement.Parameters.First().Key));
        }
Exemplo n.º 5
0
        public void Modulo_Test()
        {
            Expression <Func <Entity, bool> > expression = x => x.Age % 20 == 55;
            var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map);

            statement.Parameters.Count().ShouldEqual(2);
            statement.Parameters.First().Value.ShouldEqual(20);
            statement.Parameters.Skip(1).First().Value.ShouldEqual(55);
            statement.Text.ShouldEqual(string.Format("(([age] % @{0}) = @{1})", statement.Parameters.First().Key, statement.Parameters.Skip(1).First().Key));
        }
Exemplo n.º 6
0
        public void Not_Bool_Test()
        {
            Expression <Func <Entity, bool> > expression = x => !x.Active && !(bool)x.Values["optout"];
            var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map);

            statement.Parameters.Count().ShouldEqual(2);
            statement.Parameters.First().Value.ShouldEqual(false);
            statement.Parameters.Skip(1).First().Value.ShouldEqual(false);
            statement.Text.ShouldEqual(string.Format("(([active] = @{0}) AND (CAST([optout] AS bit) = @{1}))",
                                                     statement.Parameters.First().Key,
                                                     statement.Parameters.Skip(1).First().Key));
        }
Exemplo n.º 7
0
        public void Not_Expression_Test()
        {
            Expression <Func <Entity, bool> > expression = x => !(x.Age == 33);
            var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map);

            statement.Parameters.Count().ShouldEqual(2);
            statement.Parameters.First().Value.ShouldEqual(33);
            statement.Parameters.Skip(1).First().Value.ShouldEqual(false);
            statement.Text.ShouldEqual(string.Format("(CASE WHEN ([age] = @{0}) THEN 1 ELSE 0 END = @{1})",
                                                     statement.Parameters.First().Key,
                                                     statement.Parameters.Skip(1).First().Key));
        }