Beispiel #1
0
        public void ToString_WithJoinTable()
        {
            var schema    = "fromSchema";
            var name      = "fromTable";
            var tableName = new EntityName(schema, name);

            var fromColumn1 = "fromCol1";
            var fromColumn2 = "fromCol2";
            var fromAlias2  = "fromAlias2";
            var columns     = new IItemName[]  {
                new ItemName(fromColumn1),
                new ColumnName(fromColumn2, fromAlias2)
            };
            var fromTable = new FromTable(tableName, columns);

            IEntityName joinTableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[2] {
                new ItemName("joinTblCol1"), new ItemName("joinTblCol2")
            };
            var joinTable = new JoinTable(joinTableName, selectColumns);

            fromTable.Join(joinTable);

            var selectClause = fromTable.GetSelectClause();
            var testString   = $"[{schema}].[{name}].[{fromColumn1}], [{schema}].[{name}].[{fromColumn2}] as [{fromAlias2}], {joinTableName}.{selectColumns[0]}, {joinTableName}.{selectColumns[1]}";

            Assert.AreEqual(testString, selectClause);
        }
Beispiel #2
0
        public void ToString_WithJoinTable_NoJTSelectColumns()
        {
            var schema    = "fromSchema";
            var name      = "fromTable";
            var tableName = new EntityName(schema, name);

            var fromColumn1 = "fromCol1";
            var fromColumn2 = "fromCol2";
            var fromAlias2  = "fromAlias2";
            var columns     = new IColumnName[]  {
                new ColumnName(fromColumn1),
                new ColumnName(fromColumn2, fromAlias2)
            };
            IFromTable fromTable = new FromTable(tableName, columns);

            IEntityName joinTableName = new EntityName("joinTable");
            var         joinTable     = new JoinTable(joinTableName);

            fromTable.Join(joinTable);

            var selectClause = fromTable.ToString();
            var testString   = $"select [{schema}].[{name}].[{fromColumn1}], [{schema}].[{name}].[{fromColumn2}] as [{fromAlias2}]\r\nfrom [{schema}].[{name}]\r\n";

            Assert.AreEqual(testString.TrimEnd(), selectClause.TrimEnd());
        }
Beispiel #3
0
        public void Constructor_Name()
        {
            var name      = "name";
            var tableName = new EntityName(name);

            Assert.AreEqual(name, tableName.Name);
        }
Beispiel #4
0
        private JoinColumn GetJoinColumn(string table, string column)
        {
            EntityName tableName  = table;
            ItemName   columnName = column;

            return(new JoinColumn(tableName, columnName));
        }
Beispiel #5
0
        public void InterfaceToString_NameProvided()
        {
            var         name      = "name";
            IEntityName tableName = new EntityName(name);

            Assert.AreEqual($"[{name}]", tableName.ToString());
        }
Beispiel #6
0
        public void ToStringTest()
        {
            EntityName tableName  = "tableName";
            ItemName   columnName = "columnName";
            JoinColumn joinColumn = new JoinColumn(tableName, columnName);

            Assert.AreEqual($"{tableName}.{columnName}", joinColumn.ToString());
        }
Beispiel #7
0
        public void Constructor_EmptyColumnsArgument()
        {
            IEntityName tableName = new EntityName("tableName");

            IItemName[] selectColumns = new IItemName[0];

            var table = new FromTable(tableName, selectColumns);
        }
Beispiel #8
0
        public void InterfaceToString_SchemaAndNameProvided()
        {
            var        schema    = "schema";
            var        name      = "name";
            EntityName tableName = new EntityName(schema, name);

            Assert.AreEqual($"[{schema}].[{name}]", tableName.ToString());
        }
Beispiel #9
0
        public void ImplicitStringOperator_NameProvided()
        {
            var        name            = "name";
            EntityName tableName       = new EntityName(name);
            string     tableNameString = tableName;

            Assert.AreEqual($"[{name}]", tableNameString);
        }
        public void Constructor_NullColumnsArgument()
        {
            IEntityName tableName = new EntityName("joinTable");
            var         table     = new JoinTable(tableName, null);

            Assert.AreEqual(tableName, table.TableName);
            Assert.IsNull(table.Columns);
        }
        public void Constructor_OneNullColumnArgument()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[2] {
                new ItemName("joinColumn"), null
            };
            var table = new JoinTable(tableName, selectColumns);
        }
        public void Constructor_EmptyColumnsArgument()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[0];
            var         table         = new JoinTable(tableName, selectColumns);

            Assert.AreEqual(0, table.Columns.Length);
        }
Beispiel #13
0
        public void ImplicitStringOperator_SchemaAndNameProvided()
        {
            var        schema          = "schema";
            var        name            = "name";
            EntityName tableName       = new EntityName(schema, name);
            string     tableNameString = tableName;

            Assert.AreEqual($"[{schema}].[{name}]", tableNameString);
        }
Beispiel #14
0
        public void Constructor_SchemaName()
        {
            var schema    = "schema";
            var name      = "name";
            var tableName = new EntityName(schema, name);

            Assert.AreEqual(name, tableName.Name);
            Assert.AreEqual(schema, tableName.Schema);
        }
Beispiel #15
0
        public void Constructor()
        {
            EntityName tableName  = "tableName";
            ItemName   columnName = "columnName";
            JoinColumn joinColumn = new JoinColumn(tableName, columnName);

            Assert.AreEqual(tableName, joinColumn.TableName);
            Assert.AreEqual(columnName, joinColumn.ColumnName);
        }
Beispiel #16
0
        public void Constructor_OneNullColumnArgument()
        {
            IEntityName tableName = new EntityName("tableName");

            IItemName[] selectColumns = new IItemName[2] {
                new ColumnName("name", "alias"), null
            };

            var table = new FromTable(tableName, selectColumns);
        }
Beispiel #17
0
        public void Equatable()
        {
            EntityName tableName   = "tableName";
            ItemName   columnName  = "columnName";
            JoinColumn joinColumn1 = new JoinColumn(tableName, columnName);
            JoinColumn joinColumn2 = new JoinColumn(tableName, columnName);

            Assert.AreEqual(joinColumn1, joinColumn2);
            Assert.IsTrue(joinColumn1 == joinColumn2);
        }
        public void ToString_NoJoinColumns()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("selectColumn")
            };
            var table = new JoinTable(tableName, selectColumns);

            Assert.AreEqual(string.Empty, table.ToString());
        }
        public void Constructor_WithColumns()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("joinColumn")
            };
            var table = new JoinTable(tableName, selectColumns);

            Assert.AreEqual(tableName, table.TableName);
            Assert.AreEqual(selectColumns, table.Columns);
        }
Beispiel #20
0
        public void ToString_WithSchemaAndOneColumn()
        {
            var schema    = "fromSchema";
            var name      = "fromTable";
            var tableName = new EntityName(schema, name);

            var fromColumn1 = "fromCol1";
            var columns     = new IItemName[] { new ItemName(fromColumn1) };
            var ft          = new FromTable(tableName, columns);

            Assert.AreEqual($"select [{schema}].[{name}].[{fromColumn1}]\r\nfrom [{schema}].[{name}]\r\n", ft.ToString());
        }
Beispiel #21
0
        public void Constructor()
        {
            IEntityName tableName = new EntityName("tableName");

            IItemName[] selectColumns = new IItemName[1] {
                new ColumnName("name", "alias")
            };
            var table = new FromTable(tableName, selectColumns);

            Assert.AreEqual(tableName, table.TableName);
            Assert.AreEqual(selectColumns, table.Columns);
            Assert.IsNull(table.JoinTables);
        }
        public void AddJoinColumn()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("joinColumn")
            };
            var        table         = new JoinTable(tableName, selectColumns);
            EntityName fromTableName = "fromTable";
            ItemName   leftColumn    = "leftJoinColumn";
            ItemName   rightColumn   = "rightJoinColumn";

            table.AddJoinColumn(fromTableName, leftColumn, rightColumn);
        }
Beispiel #23
0
        public void ToString_WithoutSchema()
        {
            var name      = "fromTable";
            var tableName = new EntityName(name);

            var fromColumn1 = "fromCol1";
            var fromColumn2 = "fromCol2";
            var fromAlias2  = "fromAlias2";
            var columns     = new IItemName[]  {
                new ItemName(fromColumn1),
                new ColumnName(fromColumn2, fromAlias2)
            };
            var ft = new FromTable(tableName, columns);

            Assert.AreEqual($"select [{name}].[{fromColumn1}], [{name}].[{fromColumn2}] as [{fromAlias2}]\r\nfrom [{name}]\r\n", ft.ToString());
        }
        public void ToString_OneJoinColumn()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("selectColumn")
            };
            var        table         = new JoinTable(tableName, selectColumns);
            EntityName fromTableName = "fromTable";
            ItemName   leftColumn1   = "leftJoinColumn";
            ItemName   rightColumn1  = "rightJoinColumn";

            table.AddJoinColumn(fromTableName, leftColumn1, rightColumn1);

            var testString = $"join {tableName} on {fromTableName}.{leftColumn1}{RelationalOperators.Equal.ToSqlString()}{table.TableName}.{rightColumn1}";

            Assert.AreEqual(testString, table.ToString());
        }
Beispiel #25
0
 public void Constructor_SchemaProvided_NameStringEmptyArgument()
 {
     string schema    = "schema";
     string name      = string.Empty;
     var    tableName = new EntityName(schema, name);
 }
Beispiel #26
0
 public void Constructor_SchemaProvided_NameNullArgument()
 {
     string schema    = "schema";
     string name      = null;
     var    tableName = new EntityName(schema, name);
 }
Beispiel #27
0
 public void Constructor_SchemaStringEmptyArgument()
 {
     string schema    = string.Empty;
     var    name      = "name";
     var    tableName = new EntityName(schema, name);
 }
Beispiel #28
0
 public void Constructor_SchemaNullArgument()
 {
     string schema    = null;
     var    name      = "name";
     var    tableName = new EntityName(schema, name);
 }
Beispiel #29
0
 public void Constructor_NameStringEmptyArgument()
 {
     string name      = string.Empty;
     var    tableName = new EntityName(name);
 }
Beispiel #30
0
 public void Constructor_NameNullArgument()
 {
     string name      = null;
     var    tableName = new EntityName(name);
 }