Exemplo n.º 1
0
 public GenerateCdmFromDatabaseCommand(
     ILogger <GenerateCdmFromDatabaseCommand> logger, IRelationalModelReader relationalModelReader,
     SqlRelationalModelAnnotationCombiner annotationCombiner, CdmGenerator cdmGenerator)
 {
     this.logger = logger;
     this.relationalModelReader = relationalModelReader;
     this.annotationCombiner    = annotationCombiner;
     this.cdmGenerator          = cdmGenerator;
 }
Exemplo n.º 2
0
 public GenerateCdmFromFileCommand(
     ILogger <GenerateCdmFromFileCommand> logger, SqlTextCommandAdapter sqlFileAdapter, IRelationalModelReader relationalModelReader,
     SqlRelationalModelAnnotationCombiner annotationCombiner, CdmGenerator cdmGenerator)
 {
     this.logger                = logger;
     this.sqlCommandAdapter     = sqlFileAdapter;
     this.relationalModelReader = relationalModelReader;
     this.annotationCombiner    = annotationCombiner;
     this.cdmGenerator          = cdmGenerator;
 }
Exemplo n.º 3
0
        public void ReadsNonNullRelationalModel()
        {
            var sql = @"CREATE TABLE Customer (
				            CUSTOMER_ID INT
                        );";

            ExecuteSqlCommand(sql);
            IRelationalModelReader reader = CreateRelationalModelReader();

            RelationalModel model = reader.ReadRelationalModel();

            Assert.NotNull(model);
        }
Exemplo n.º 4
0
        public void ReadsColumnIsPrimaryKey(string statement, bool expected)
        {
            var sql = $@"CREATE TABLE Customer (
							CUSTOMER_ID INT {statement}
                        );";

            ExecuteSqlCommand(sql);
            IRelationalModelReader reader = CreateRelationalModelReader();

            Column column = reader.ReadRelationalModel().GetColumn();

            Assert.Equal(expected, column.IsPrimaryKey);
        }
Exemplo n.º 5
0
        public void ReadsColumnType(string type, SqlDbType expected)
        {
            var sql = $@"CREATE TABLE Customer (
							CUSTOMER_ID {type}
                        );";

            ExecuteSqlCommand(sql);
            IRelationalModelReader reader = CreateRelationalModelReader();

            Column column = reader.ReadRelationalModel().GetColumn();

            Assert.Equal(expected, column.Type);
        }
Exemplo n.º 6
0
        public void ReadsColumnName(string name, string expected)
        {
            var sql = $@"CREATE TABLE Customer (
							{name} INT
                        );";

            ExecuteSqlCommand(sql);
            IRelationalModelReader reader = CreateRelationalModelReader();

            Column column = reader.ReadRelationalModel().GetColumn();

            Assert.Equal(expected, column.Name);
        }
Exemplo n.º 7
0
        public void ReadsSingleTable()
        {
            var sql = @"CREATE TABLE Customer (
							CUSTOMER_ID INT
                        );";

            ExecuteSqlCommand(sql);
            IRelationalModelReader reader = CreateRelationalModelReader();

            RelationalModel     model  = reader.ReadRelationalModel();
            IEnumerable <Table> tables = model.Tables;

            Assert.Single(tables);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public void ReadsColumnLength()
        {
            var sql = @"CREATE TABLE Customer (
							CUSTOMER_ID VARCHAR(10)
                        );";

            ExecuteSqlCommand(sql);
            IRelationalModelReader reader = CreateRelationalModelReader();

            RelationalModel model  = reader.ReadRelationalModel();
            Column          column = model.GetColumn();

            Assert.NotNull(column.Length);
            Assert.Equal(10, column.Length.MaxSize);
        }
Exemplo n.º 11
0
        public void ReadsColumnTable()
        {
            var sql = @"CREATE TABLE Customer (
							CUSTOMER_ID INT
                        );";

            ExecuteSqlCommand(sql);
            IRelationalModelReader reader = CreateRelationalModelReader();

            RelationalModel model  = reader.ReadRelationalModel();
            Table           table  = model.GetTable();
            Column          column = model.GetColumn();

            Assert.NotNull(column.Table);
            Assert.Same(table, column.Table);
        }
Exemplo n.º 12
0
        public void ReadsColumnIsForeignKey()
        {
            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();

            Column column = reader.ReadRelationalModel().GetColumn("CustomerAddresses", "CUSTOMER_ID");

            Assert.True(column.IsForeignKey);
        }
Exemplo n.º 13
0
        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);
        }