示例#1
0
        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])");
        }
示例#2
0
        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]");
        }
示例#3
0
        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))");
        }
示例#4
0
        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])");
        }
示例#5
0
        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)))");
        }
示例#6
0
        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)");
        }
示例#7
0
        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)");
        }
示例#8
0
        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)");
        }
示例#9
0
        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)");
        }
示例#10
0
        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)");
        }
示例#11
0
        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))");
        }
示例#12
0
        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");
        }
示例#13
0
        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)");
        }
示例#14
0
        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])");
        }
示例#15
0
        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]");
        }
示例#16
0
        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])");
        }
示例#17
0
        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]");
        }
示例#18
0
        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));
        }
示例#19
0
        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));
        }
示例#20
0
        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));
        }
示例#21
0
        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));
        }
示例#22
0
        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));
        }