コード例 #1
0
        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"));
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        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)");
        }
コード例 #6
0
        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 ()");
        }
コード例 #7
0
        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");
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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)");
        }
コード例 #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");
        }
コード例 #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)");
        }
コード例 #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");
        }
コード例 #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");
        }
コード例 #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");
        }
コード例 #15
0
        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));
        }