Example #1
0
        public async Task RunAsync(FileOptions options)
        {
            logger.LogInformation("Executing {sqlFile} ...", Path.GetFullPath(options.InputSqlFile));
            sqlCommandAdapter.ExecuteSqlCommand();

            logger.LogDebug("Reading SQL schema ...");
            RelationalModel model = relationalModelReader.ReadRelationalModel();

            if (!model.Tables.Any())
            {
                logger.LogWarning("No tables were found ...");
                return;
            }

            logger.LogDebug("Running Annotation Combiner ...");
            annotationCombiner.ReadAnnotationsAndCombineWithModel(model);

            logger.LogDebug("Generating CDM folder ...");
            CdmManifestDefinition manifest = await cdmGenerator.GenerateCdmAsync(model);

            logger.LogInformation("Saving CDM folder at {cdmOutput}...", Path.GetFullPath(options.OutputCdmFolder));
            await manifest.SaveAsync();

            logger.LogInformation("Success!");
        }
Example #2
0
        public void ReadsNonNullRelationalModel()
        {
            var sql = @"CREATE TABLE Customer (
				            CUSTOMER_ID INT
                        );";

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

            RelationalModel model = reader.ReadRelationalModel();

            Assert.NotNull(model);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
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);
        }