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 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 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 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 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 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 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 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 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 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 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 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 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 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)); }