public void Sub_String_Fixed_Test() { Expression <Func <Entity, string> > where = x => x.Name.Substring(0, 5); var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Function); projection.Function.ShouldNotBeNull(); projection.Function.Type.ShouldEqual(Function.FunctionType.SubstringFixed); projection.Function.SubstringFixed.Text.ShouldNotBeNull(); projection.Function.SubstringFixed.Text.Type.ShouldEqual(Projection.ProjectionType.Field); projection.Function.SubstringFixed.Text.Field.ShouldNotBeNull(); projection.Function.SubstringFixed.Text.Field.Name.ShouldEqual("Name"); projection.Function.SubstringFixed.Start.ShouldNotBeNull(); projection.Function.SubstringFixed.Start.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.SubstringFixed.Start.Constant.ShouldNotBeNull(); projection.Function.SubstringFixed.Start.Constant.Value.ShouldEqual(0); projection.Function.SubstringFixed.Length.ShouldNotBeNull(); projection.Function.SubstringFixed.Length.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.SubstringFixed.Length.Constant.ShouldNotBeNull(); projection.Function.SubstringFixed.Length.Constant.Value.ShouldEqual(5); }
public void Replace_Test() { Expression <Func <Entity, string> > where = x => x.Name.Replace("oh", "hai"); var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Function); projection.Function.ShouldNotBeNull(); projection.Function.Type.ShouldEqual(Function.FunctionType.Replace); projection.Function.Replace.Text.ShouldNotBeNull(); projection.Function.Replace.Text.Type.ShouldEqual(Projection.ProjectionType.Field); projection.Function.Replace.Text.Field.ShouldNotBeNull(); projection.Function.Replace.Text.Field.Name.ShouldEqual("Name"); projection.Function.Replace.SearchValue.ShouldNotBeNull(); projection.Function.Replace.SearchValue.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.Replace.SearchValue.Constant.ShouldNotBeNull(); projection.Function.Replace.SearchValue.Constant.Value.ShouldEqual("oh"); projection.Function.Replace.ReplaceValue.ShouldNotBeNull(); projection.Function.Replace.ReplaceValue.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.Replace.ReplaceValue.Constant.ShouldNotBeNull(); projection.Function.Replace.ReplaceValue.Constant.Value.ShouldEqual("hai"); }
public void Ondex_Of_At_Test() { Expression <Func <Entity, int> > where = x => x.Name.IndexOf("hai", 10); var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Function); projection.Function.ShouldNotBeNull(); projection.Function.Type.ShouldEqual(Function.FunctionType.IndexOfAt); projection.Function.IndexOfAt.Text.ShouldNotBeNull(); projection.Function.IndexOfAt.Text.Type.ShouldEqual(Projection.ProjectionType.Field); projection.Function.IndexOfAt.Text.Field.ShouldNotBeNull(); projection.Function.IndexOfAt.Text.Field.Name.ShouldEqual("Name"); projection.Function.IndexOfAt.Value.ShouldNotBeNull(); projection.Function.IndexOfAt.Value.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.IndexOfAt.Value.Constant.ShouldNotBeNull(); projection.Function.IndexOfAt.Value.Constant.Value.ShouldEqual("hai"); projection.Function.IndexOfAt.Start.ShouldNotBeNull(); projection.Function.IndexOfAt.Start.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.IndexOfAt.Start.Constant.ShouldNotBeNull(); projection.Function.IndexOfAt.Start.Constant.Value.ShouldEqual(10); }
public void Insert_Test() { Expression <Func <Entity, string> > where = x => x.Name.Insert(5, "hai"); var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Function); projection.Function.ShouldNotBeNull(); projection.Function.Type.ShouldEqual(Function.FunctionType.Insert); projection.Function.Insert.Text.ShouldNotBeNull(); projection.Function.Insert.Text.Type.ShouldEqual(Projection.ProjectionType.Field); projection.Function.Insert.Text.Field.ShouldNotBeNull(); projection.Function.Insert.Text.Field.Name.ShouldEqual("Name"); projection.Function.Insert.Start.ShouldNotBeNull(); projection.Function.Insert.Start.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.Insert.Start.Constant.ShouldNotBeNull(); projection.Function.Insert.Start.Constant.Value.ShouldEqual(5); projection.Function.Insert.Value.ShouldNotBeNull(); projection.Function.Insert.Value.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Function.Insert.Value.Constant.ShouldNotBeNull(); projection.Function.Insert.Value.Constant.Value.ShouldEqual("hai"); }
public void Entity_Dictionary_Property_Test() { Expression <Func <Entity, object> > expression = x => x.Values["Company"]; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("[company]"); }
public void To_Hex_Test() { Expression <Func <Entity, string> > expression = x => x.Name.Hash(EntityExtensions.HashAlgorithim.Md5).ToHex(); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CONVERT(nvarchar (MAX), HASHBYTES('Md5', [name]), 1)"); }
public void Hash_Sha1_Test() { Expression <Func <Entity, byte[]> > expression = x => x.Name.Hash(EntityExtensions.HashAlgorithim.Sha1); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("HASHBYTES('Sha1', [name])"); }
public void Guid_ToString_Test() { Expression <Func <Entity, string> > expression = x => x.Id.ToString(); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CAST([id] AS nvarchar (MAX))"); }
public void Fields_Length_Test() { Expression <Func <Entity, int> > expression = x => ((string)x.Values["CompanyName"]).Length; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("LEN(CAST([companyname] AS nvarchar (MAX)))"); }
public void Guid_Cast_Test() { Expression <Func <Entity, Guid> > expression = x => (Guid)x.Values["Count"]; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CAST([count] AS uniqueidentifier)"); }
public void Float_Cast_Test() { Expression <Func <Entity, float> > expression = x => (float)x.Values["Count"]; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CAST([count] AS real)"); }
public void Bool_Cast_Test() { Expression <Func <Entity, bool> > expression = x => (bool)x.Values["OptOut"]; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CAST([optout] AS bit)"); }
public void DateTime_Cast_Test() { Expression <Func <Entity, DateTime> > expression = x => (DateTime)x.Values["CreateDate"]; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CAST([createdate] AS datetime)"); }
public void Int_Cast_Test() { Expression <Func <Entity, int> > expression = x => (int)x.Values["PubCode"]; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CAST([pubcode] AS int)"); }
public void String_Cast_Test() { Expression <Func <Entity, string> > expression = x => (string)x.Values["Company"]; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("CAST([company] AS nvarchar (MAX))"); }
public void Null_Test() { Expression <Func <Entity, object> > expression = x => null; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("NULL"); }
public void Property_Length_Test() { Expression <Func <Entity, int> > expression = x => x.Name.Length; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("LEN([name])"); }
public void Trim_Right_Test() { Expression <Func <Entity, string> > expression = x => x.Name.TrimEnd(); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("RTRIM([name])"); }
public void Entity_Property_Table_Alias_Test() { Expression <Func <Entity, int> > expression = x => x.Age; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body, "T"), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("[T].[age]"); }
public void Coalesce_Test() { Expression <Func <Entity, string> > expression = x => x.Name ?? x.NickName; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("COALESCE([name], [nickname])"); }
public void Entity_Nullable_Property_Test() { Expression <Func <Entity, DateTime?> > expression = x => x.Created; var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(0); statement.Text.ShouldEqual("[created]"); }
public void Index_Of_Test() { Expression <Func <Entity, int> > expression = x => x.Name.IndexOf("hi"); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(1); statement.Parameters.First().Value.ShouldEqual("hi"); statement.Text.ShouldEqual(string.Format("CHARINDEX(@{0}, [name])", statement.Parameters.First().Key)); }
public void Substring_Test() { Expression <Func <Entity, string> > expression = x => x.Name.Substring(10); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(1); statement.Parameters.First().Value.ShouldEqual(10); statement.Text.ShouldEqual(string.Format("RIGHT([name], LEN([name]) - @{0})", statement.Parameters.First().Key)); }
public void Substring_Fixed_Length_Test() { Expression <Func <Entity, string> > expression = x => x.Name.Substring(10, 5); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(2); statement.Parameters.First().Value.ShouldEqual(10); statement.Parameters.Skip(1).First().Value.ShouldEqual(5); statement.Text.ShouldEqual(string.Format("SUBSTRING([name], @{0}, @{1})", statement.Parameters.First().Key, statement.Parameters.Skip(1).First().Key)); }
public void Constant_Test() { Expression <Func <Entity, string> > where = x => "Jeff"; var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Constant.ShouldNotBeNull(); projection.Constant.Value.ShouldEqual("Jeff"); }
public void Replace_Test() { Expression <Func <Entity, string> > expression = x => x.Name.Replace("this", "that"); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(2); statement.Parameters.First().Value.ShouldEqual("this"); statement.Parameters.Skip(1).First().Value.ShouldEqual("that"); statement.Text.ShouldEqual(string.Format("REPLACE([name], @{0}, @{1})", statement.Parameters.First().Key, statement.Parameters.Skip(1).First().Key)); }
public void Insert_Test() { Expression <Func <Entity, string> > expression = x => x.Name.Insert(10, "that"); var statement = ProjectionWriter <Entity> .CreateStatement(ProjectionVisitor <Entity> .CreateModel(expression.Body), Map); statement.Parameters.Count().ShouldEqual(2); statement.Parameters.First().Value.ShouldEqual(10); statement.Parameters.Skip(1).First().Value.ShouldEqual("that"); statement.Text.ShouldEqual(string.Format("STUFF([name], @{0}, LEN([name]) - @{0}, @{1})", statement.Parameters.First().Key, statement.Parameters.Skip(1).First().Key)); }
public void Property_Test() { Expression <Func <Entity, DateTime> > where = x => x.Birthdate; var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Field); projection.Field.ShouldNotBeNull(); projection.Field.Name.ShouldEqual("Birthdate"); projection.Field.HasKey.ShouldEqual(false); }
public void Dictionary_Property_Test() { Expression <Func <Entity, object> > where = x => x.Values["OptOut"]; var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Field); projection.Field.ShouldNotBeNull(); projection.Field.Name.ShouldEqual("Values"); projection.Field.HasKey.ShouldEqual(true); projection.Field.Key.ShouldEqual("OptOut"); }
public void Non_Entity_Property_Access_Test() { var widget = new Widget(); Expression <Func <Entity, string> > where = x => widget.Yada; var projection = ProjectionVisitor <Entity> .CreateModel(where.Body); projection.ShouldNotBeNull(); projection.Type.ShouldEqual(Projection.ProjectionType.Constant); projection.Constant.ShouldNotBeNull(); projection.Constant.Value.ShouldEqual(widget.Yada); }