예제 #1
0
        /// <summary>
        ///     Execute the command.
        /// </summary>
        public override void Execute()
        {
            var editor = Services.Resolve <IEditor>("txt-editor");

            //var editor = Services.Resolve<IEditor>();
            editor.FileName = null;
            HostWindow.DisplayDockedForm(editor as DockContent);

            if (HostWindow.DatabaseInspector.DbSchema == null)
            {
                HostWindow.DatabaseInspector.LoadDatabaseDetails();
            }

            var dependencyWalker = new DbModelDependencyWalker(HostWindow.DatabaseInspector.DbSchema);
            var tables           = dependencyWalker.SortTablesByForeignKeyReferences();

            var sb = new StringBuilder();

            foreach (DbModelTable table in tables)
            {
                sb.AppendLine(table.FullName);
            }

            editor.AllText = sb.ToString();
        }
        public void Build_dependency_tree_from_model()
        {
            DbModelDependencyWalker dependencyWalker = new DbModelDependencyWalker(_model);
            var tables = dependencyWalker.SortTablesByForeignKeyReferences();

            DisplayTableDetails(tables);

            /*
             *  Categories (fks:0)
             *  Customers (fks:0)
             *  Employees (fks:0)
             *  Order Details_New (fks:0)
             *  Shippers (fks:0)
             *  Suppliers (fks:0)
             *  Orders (fks:3)
             *    (FK --> Customers.Customer ID)
             *    (FK --> Employees.Employee ID)
             *    (FK --> Shippers.Shipper ID)
             *  Products (fks:2)
             *    (FK --> Suppliers.Supplier ID)
             *    (FK --> Categories.Category ID)
             *  Order Details (fks:2)
             *    (FK --> Orders.Order ID)
             *    (FK --> Products.Product ID)
             */

            Assert.That(tables[0].Name, Is.EqualTo("Categories"));
            Assert.That(tables[1].Name, Is.EqualTo("Customers"));
            Assert.That(tables[2].Name, Is.EqualTo("Employees"));
            Assert.That(tables[4].Name, Is.EqualTo("Shippers"));
            Assert.That(tables[5].Name, Is.EqualTo("Suppliers"));
            Assert.That(tables[6].Name, Is.EqualTo("Orders"), "Order is dependent on Customers, Employees, Shippers");
            Assert.That(tables[7].Name, Is.EqualTo("Products"), "Products is dependent on Suppliers, Categories");
            Assert.That(tables[8].Name, Is.EqualTo("Order Details"), "Order Details is dependent on Orders, Products");
        }
        public void Build_dependency_tree_from_model()
        {
            DbModelDependencyWalker dependencyWalker = new DbModelDependencyWalker(_model);
            var tables = dependencyWalker.SortTablesByForeignKeyReferences();

            DisplayTableDetails(tables);

            Assert.That(tables[0].Name, Is.EqualTo("Categories"));
            Assert.That(tables[1].Name, Is.EqualTo("Customers"));
            Assert.That(tables[2].Name, Is.EqualTo("Employees"));
            Assert.That(tables[3].Name, Is.EqualTo("Shippers"));
            Assert.That(tables[4].Name, Is.EqualTo("Suppliers"));
            Assert.That(tables[5].Name, Is.EqualTo("Orders"), "Order is dependent on Customers, Employees, Shippers");
            Assert.That(tables[6].Name, Is.EqualTo("Products"), "Products is dependent on Suppliers, Categories");
            Assert.That(tables[7].Name, Is.EqualTo("Order Details"), "Order Details is dependent on Orders, Products");
        }