public void GetFieldDefinitionsFromGenericTypeMatchedWithInvariantCaseMatch()
        {
            var parts = new QueryPartsContainer();
            var item = new QueryPart(OperationType.None);
            item.Add(new FieldQueryPart("iD", null, null, "Warrior") { FieldType = typeof(int) });
            item.Add(new FieldQueryPart("nAme", null, null, "Warrior") { FieldType = typeof(string) });
            item.Add(new FieldQueryPart("weaponId", null, null, "Warrior") { FieldType = typeof(int) });
            item.Add(new FieldQueryPart("raCe", null, null, "Warrior") { FieldType = typeof(string) });
            item.Add(new FieldQueryPart("specialSkill", null, null, "Warrior") { FieldType = typeof(string) });

            parts.Add(item);

            // Act
            var fields = TypeDefinitionFactory.GetFieldDefinitions<Warrior>(parts);

            Assert.IsTrue(fields.Count() == 5);

            //Assert.IsTrue(fields.Any(f => f.FieldName == "iD"));
            //Assert.IsTrue(fields.Any(f => f.FieldName == "nAme"));
            //Assert.IsTrue(fields.Any(f => f.FieldName == "weaponId"));
            //Assert.IsTrue(fields.Any(f => f.FieldName == "raCe"));
            //Assert.IsTrue(fields.Any(f => f.FieldName == "specialSkill"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "ID"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "Name"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "WeaponID"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "Race"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "SpecialSkill"));
        }
        public void QueryCompilerCompileFieldTest()
        {
            var part = new QueryPart(OperationType.None);
            part.Add(new FieldQueryPart("Name", null));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, " Name");
        }
        public void QueryCompilerCompileCountTest()
        {
            var part = new QueryPart(OperationType.None);
            part.Add(new FieldQueryPart("Name", "Alias", operation: OperationType.Count));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, " COUNT(Name) AS Alias");
        }
        public void QueryCompilerCompileFieldWithAliasAndTableAndTableAliasDefinitionTest()
        {
            var part = new QueryPart(OperationType.None);
            part.Add(new FieldQueryPart("Name", "Alias", entity: "Entity", entityalias: "EntityAlias"));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, " EntityAlias.Name AS Alias");
        }
        public void QueryCompilerCompileValuesWithInsertValuesTest()
        {
            var part = new QueryPart(OperationType.Values);
            part.Add(new DelegateQueryPart(OperationType.InsertValue, () => "Field1"));
            part.Add(new DelegateQueryPart(OperationType.InsertValue, () => "Field2"));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, " VALUES (Field1, Field2)");
        }
        public void QueryCompilerCompileValuesTest()
        {
            var part = new QueryPart(OperationType.Values, null);
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, " VALUES ()");
        }
        public void QueryCompilerCompileSelectWithIncludeTest()
        {
            var select = new QueryPart(OperationType.Select);
            select.Add(new FieldQueryPart("Name", "Alias") { OperationType = OperationType.Include });
            var parts = new QueryPartsContainer();
            parts.Add(select);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, "SELECT Name AS Alias");
        }
        public void QueryCompilerCompileIgnoreTest()
        {
            var select = new QueryPart(OperationType.IgnoreColumn);
            var parts = new QueryPartsContainer();
            parts.Add(select);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, string.Empty);
        }
        public void SqlServer_QueryCompiler_Compile_ColumnMultipleTest()
        {
            var part = new QueryPart(OperationType.None);

            var part1 = new ValueCollectionQueryPart(OperationType.Column);
            part1.AddValue(KeyValuePart.MemberName, "ColumnName1");
            part1.AddValue(KeyValuePart.MemberType, "int");
            part1.AddValue(KeyValuePart.Nullable, false.ToString());

            part.Add(part1);

            var part2 = new ValueCollectionQueryPart(OperationType.Column);
            part2.AddValue(KeyValuePart.MemberName, "ColumnName2");
            part2.AddValue(KeyValuePart.MemberType, "VARCHAR(20)");
            part2.AddValue(KeyValuePart.Nullable, true.ToString());

            part.Add(part2);

            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, "ColumnName1 int NOT NULL, ColumnName2 VARCHAR(20)");
        }
Exemplo n.º 10
0
        public void SqlServer_QueryCompiler_Compile_SelectWithOutputParameterSelectTest()
        {
            var part = new QueryPart(OperationType.Select);
            part.Add(new DelegateQueryPart(OperationType.OutParameterSelect, () => "Param1"));
            part.Add(new DelegateQueryPart(OperationType.OutParameterSelect, () => "Param2"));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, "SELECT @Param1 AS Param1, @Param2 AS Param2");
        }
Exemplo n.º 11
0
        public void SqlServer_QueryCompiler_Compile_PrimaryKeyWithMultipleColumnsTest()
        {
            var part = new QueryPart(OperationType.PrimaryKey);
            part.Add(new DelegateQueryPart(OperationType.Column, () => "Column1"));
            part.Add(new DelegateQueryPart(OperationType.Column, () => "Column2"));

            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, "PRIMARY KEY (Column1, Column2)");
        }
Exemplo n.º 12
0
        public void SqlServer_QueryCompiler_Compile_ParameterTest()
        {
            var part = new QueryPart(OperationType.None, null);
            part.Add(new DelegateQueryPart(OperationType.Parameter, () => "Param=value"));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, "Param=value");
        }
Exemplo n.º 13
0
        public void SqlServer_QueryCompiler_Compile_OutputParameterDefinitionTest()
        {
            var part = new QueryPart(OperationType.None);
            part.Add(new DelegateQueryPart(OperationType.OutParameterDeclare, () => "Param int"));
            part.Add(new DelegateQueryPart(OperationType.OutParameterSet, () => "Param=1"));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, "DECLARE @Param int\r\nSET @Param=1\r\n");
        }
Exemplo n.º 14
0
        public void SqlServer_QueryCompiler_Compile_MultipleParameterOutputTest()
        {
            var part = new QueryPart(OperationType.None);
            part.Add(new DelegateQueryPart(OperationType.OutputParameter, () => "Param1=value1"));
            part.Add(new DelegateQueryPart(OperationType.OutputParameter, () => "Param2=value2"));
            var parts = new QueryPartsContainer();
            parts.Add(part);

            var compiler = new QueryCompiler();
            var query = compiler.Compile(parts, new InterceptorCollection());

            Assert.AreEqual(query.QueryString, "Param1=value1 OUTPUT, Param2=value2 OUTPUT");
        }
        public void GetFieldDefinitionsFromGenericTypeWithQueryPartsMatch()
        {
            var parts = new QueryPartsContainer();
            var item = new QueryPart(OperationType.None);
            item.Add(new FieldQueryPart("ID", null, null, "Warrior")
            {
                FieldType = typeof(DateTime)
            });

            parts.Add(item);

            // Act
            var fields = TypeDefinitionFactory.GetFieldDefinitions<Warrior>(parts);

            Assert.IsTrue(fields.Count() == 5);

            Assert.IsTrue(fields.Any(f => f.FieldName == "ID"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "Name"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "WeaponID"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "Race"));
            Assert.IsTrue(fields.Any(f => f.FieldName == "SpecialSkill"));

            Assert.IsTrue(fields.First(f => f.FieldName == "ID").FieldType == typeof(DateTime));
            Assert.IsTrue(fields.First(f => f.FieldName == "ID").MemberType == typeof(int));
        }