public void Null_Test() { Expression <Func <Entity, bool> > expression = x => x.Flag == null; var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("([flag] IS NULL)"); }
public void should_generate_sql_for_ends_with_equals_false() { Expression <Func <Entity, bool> > expression = x => x.Name.EndsWith("ed") == false; var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(1); statement.Parameters.First().Value.ShouldEqual("ed"); statement.Text.ShouldEqual(string.Format("([name] NOT LIKE '%' + @{0})", statement.Parameters.First().Key)); }
public void Or_Test() { Expression <Func <Entity, bool> > expression = x => x.Age == 10 || x.Flag != null; var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(1); statement.Parameters.First().Value.ShouldEqual(10); statement.Text.ShouldEqual($"(([age] = @{statement.Parameters.First().Key}) OR ([flag] IS NOT NULL))"); }
public void should_generate_sql_for_trim() { Expression <Func <Entity, bool> > expression = x => x.Name.Trim() == "ed"; var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(1); statement.Parameters.First().Value.ShouldEqual("ed"); statement.Text.ShouldEqual(string.Format("(LTRIM(RTRIM([name])) = @{0})", statement.Parameters.First().Key)); }
public void Less_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)); }
public void should_generate_sql_for_not_contains() { Expression <Func <Entity, bool> > expression = x => !x.Name.Contains("ed"); var statement = WhereWriter <Entity> .CreateStatement(WhereVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(1); statement.Parameters.First().Value.ShouldEqual("ed"); statement.Text.ShouldEqual(string.Format("([name] NOT LIKE '%' + @{0} + '%')", statement.Parameters.First().Key)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }