Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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");
        }
Exemple #4
0
        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");
        }
Exemple #5
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))");
        }
Exemple #6
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])");
        }
Exemple #7
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)))");
        }
Exemple #8
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])");
        }
Exemple #9
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)");
        }
Exemple #10
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)");
        }
Exemple #11
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)");
        }
Exemple #12
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))");
        }
Exemple #13
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");
        }
Exemple #14
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]");
        }
Exemple #15
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]");
        }
Exemple #16
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)");
        }
Exemple #17
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)");
        }
Exemple #18
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)");
        }
Exemple #19
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])");
        }
Exemple #20
0
            public ProjectionBuilder(IVertexBase source, TValue value, ProjectionVisitor <TValue> visitor, ProjectionGraph graph)
            {
                Source = source;
                Value  = value;

                _visitor = visitor;
                _graph   = graph;
            }
Exemple #21
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]");
        }
Exemple #22
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])");
        }
Exemple #23
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));
        }
Exemple #24
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));
        }
Exemple #25
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));
        }
Exemple #26
0
        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");
        }
Exemple #27
0
            public IEnumerator <Projection <TValue> > GetEnumerator()
            {
                if (Source == null || Target == null)
                {
                    return(Enumerable.Empty <Projection <TValue> >().GetEnumerator());
                }

                var arguments = new ProjectionVisitor <TValue> .Arguments(Value, Target, Raycasting, RaycastClient, Directions, DepthMax, ViewDepthMax);

                return(Source.Accept(_visitor, arguments).GetEnumerator());
            }
Exemple #28
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));
        }
Exemple #29
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));
        }
Exemple #30
0
        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);
        }