Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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");
        }
Beispiel #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");
        }
Beispiel #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))");
        }
Beispiel #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])");
        }
Beispiel #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)))");
        }
Beispiel #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])");
        }
Beispiel #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)");
        }
Beispiel #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)");
        }
Beispiel #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)");
        }
Beispiel #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))");
        }
Beispiel #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");
        }
Beispiel #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]");
        }
Beispiel #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]");
        }
Beispiel #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)");
        }
Beispiel #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)");
        }
Beispiel #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)");
        }
Beispiel #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])");
        }
Beispiel #20
0
            public ProjectionBuilder(IVertexBase source, TValue value, ProjectionVisitor <TValue> visitor, ProjectionGraph graph)
            {
                Source = source;
                Value  = value;

                _visitor = visitor;
                _graph   = graph;
            }
Beispiel #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]");
        }
Beispiel #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])");
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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");
        }
Beispiel #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());
            }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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);
        }