public void ReadsSingleColumn() { var sql = @"CREATE TABLE Customer ( CUSTOMER_ID INT );"; ExecuteSqlCommand(sql); IRelationalModelReader reader = CreateRelationalModelReader(); RelationalModel model = reader.ReadRelationalModel(); IEnumerable <Column> columns = model.GetTable().Columns; Assert.Single(columns); }
public void ReadsTableName(string name, string expected) { var sql = $@"CREATE TABLE {name} ( CUSTOMER_ID INT );"; ExecuteSqlCommand(sql); IRelationalModelReader reader = CreateRelationalModelReader(); RelationalModel model = reader.ReadRelationalModel(); Table table = model.GetTable(); Assert.Equal(expected, table.Name); }
public void ReadsNonNullTable() { var sql = @"CREATE TABLE Customer ( CUSTOMER_ID INT );"; ExecuteSqlCommand(sql); IRelationalModelReader reader = CreateRelationalModelReader(); RelationalModel model = reader.ReadRelationalModel(); Table table = model.GetTable(); Assert.NotNull(table); }
public void ReadsColumnForeignKeyTable() { var sql = @"CREATE TABLE Customer ( CUSTOMER_ID INT PRIMARY KEY ); CREATE TABLE CustomerAddresses ( CUSTOMER_ADDRESS_ID INT PRIMARY KEY, CUSTOMER_ID INT, FOREIGN KEY(CUSTOMER_ID) REFERENCES Customer(CUSTOMER_ID) );"; ExecuteSqlCommand(sql); IRelationalModelReader reader = CreateRelationalModelReader(); RelationalModel model = reader.ReadRelationalModel(); Column fromColumn = model.GetColumn("CustomerAddresses", "CUSTOMER_ID"); Table toTable = model.GetTable("Customer"); Assert.Same(toTable, fromColumn.ForeignKey.Table); }
public static Column GetColumn(this RelationalModel model, string tableName, string columnName) { return(model.GetTable(tableName).Columns.First(c => c.Name == columnName)); }
public static Column GetColumn(this RelationalModel model) { return(model.GetTable().Columns.First()); }