/// <summary>
        /// The base application table collection difference unit test_ remove column.
        /// </summary>
        /// <param name="originalDatabaseModel">
        /// The original database model.
        /// </param>
        /// <param name="changedDatabaseModel">
        /// The changed database model.
        /// </param>
        private void RemoveColumn(
            DatabaseModel originalDatabaseModel,
            DatabaseModel changedDatabaseModel)
        {
            Table  bankTransfers         = changedDatabaseModel.Tables.FirstOrDefault(t => t.TableName == "BankTransfers");
            Column bankTransfersIdColumn = bankTransfers.Columns.FirstOrDefault(c => c.ColumnName == "BankTransferId");

            bankTransfers.Columns.Remove(bankTransfersIdColumn);

            ApplicationTableCollectionDifference differences = this.Differences.CompareTables(
                originalDatabaseModel.Tables,
                changedDatabaseModel.Tables);

            Assert.AreEqual(0, differences.FirstExtraTables.Count, "There should be 0 Extra tables");
            Assert.AreEqual(0, differences.FirstMissingTables.Count, "There should be 0 missing tables");
            Assert.AreEqual(1, differences.ProblemTables.Count, "There should be 1 problem tables");
            Assert.AreEqual(1, differences.RefreshTable.Count, "There should be 1 table to refresh");

            Assert.AreEqual(1, differences.ProblemTables[0].FirstExtraColumns.Count);
            Assert.AreEqual("BankTransferId", differences.ProblemTables[0].FirstExtraColumns[0].ColumnName);

            Assert.AreEqual("BankTransfers", differences.RefreshTable[0].TableName);

            bankTransfers.Columns.Insert(0, bankTransfersIdColumn);
        }
        /// <summary>
        /// The test nodifference.
        /// </summary>
        /// <param name="originalDatabaseModel">
        /// The original database model.
        /// </param>
        /// <param name="changedDatabaseModel">
        /// The changed database model.
        /// </param>
        private void TestNodifference(
            DatabaseModel originalDatabaseModel,
            DatabaseModel changedDatabaseModel)
        {
            ApplicationTableCollectionDifference differences = this.Differences.CompareTables(
                originalDatabaseModel.Tables,
                changedDatabaseModel.Tables);

            Assert.AreEqual(0, differences.FirstExtraTables.Count, "There should be 0 Extra tables");
            Assert.AreEqual(0, differences.FirstMissingTables.Count, "There should be 0 missing tables");
            Assert.AreEqual(0, differences.ProblemTables.Count, "There should be 0 problem tables");
            Assert.AreEqual(0, differences.RefreshTable.Count, "There should be 0 refresh tables");
        }
Exemple #3
0
        /// <summary>
        /// The do table collection diff.
        /// </summary>
        /// <param name="originalTableList">
        /// The original table list.
        /// </param>
        /// <param name="addedTables">
        /// The added tables.
        /// </param>
        /// <param name="removedTables">
        /// The removed tables.
        /// </param>
        /// <param name="refreshedTables">
        /// The refreshed Tables.
        /// </param>
        /// <param name="comparison">
        /// The comparison.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List <Table> DoTableCollectionDiff(
            List <Table> originalTableList,
            List <Table> addedTables,
            List <Table> removedTables,
            List <Table> refreshedTables,
            ApplicationTableCollectionDifference comparison)
        {
            List <Table> newList = new List <Table>();

            foreach (Table table in originalTableList)
            {
                if (!refreshedTables.Exists(
                        t => t.TableName.ToUpper() == table.TableName.ToUpper() &&
                        t.SchemaName.ToUpper() == table.SchemaName.ToUpper()))
                {
                    newList.Add(table.Clone() as Table);
                }
                else
                {
                    // add updated table
                    // Copy Changeable Data
                    Table refreshedTable = refreshedTables.First(
                        t => t.TableName.ToUpper() == table.TableName.ToUpper() &&
                        t.SchemaName.ToUpper() == table.SchemaName.ToUpper());
                    PreserveCustomMetadata(refreshedTable, table);
                    newList.Add(refreshedTable);
                }
            }

            foreach (Table table in addedTables)
            {
                newList.Add(table.Clone() as Table);
            }

            Table tableToRemove;

            foreach (Table table in removedTables)
            {
                tableToRemove = newList.FirstOrDefault(
                    t => t.SchemaName.ToUpper() == table.SchemaName.ToUpper() &&
                    t.TableName.ToUpper() == table.TableName.ToUpper());

                if (tableToRemove != null)
                {
                    newList.Remove(tableToRemove);
                }
            }

            return(newList);
        }
        /// <summary>
        /// The shared column changed.
        /// </summary>
        /// <param name="differences">
        /// The differences.
        /// </param>
        private void SharedColumnChanged(ApplicationTableCollectionDifference differences)
        {
            Assert.AreEqual(0, differences.FirstExtraTables.Count, "There should be 0 Extra tables");
            Assert.AreEqual(0, differences.FirstMissingTables.Count, "There should be 0 missing tables");
            Assert.AreEqual(1, differences.ProblemTables.Count, "There should be 1 problem tables");
            Assert.AreEqual(1, differences.RefreshTable.Count, "There should be 1 table to refresh");

            Assert.AreEqual(1, differences.ProblemTables[0].ColumnDataTypeDiffs.Count);

            Assert.AreEqual(
                "BankTransferId",
                differences.ProblemTables[0].ColumnDataTypeDiffs[0].FirstColumn.ColumnName);
            Assert.AreEqual("BankTransfers", differences.RefreshTable[0].TableName);
        }
        /// <summary>
        /// The remove table from changed model.
        /// </summary>
        /// <param name="originalDatabaseModel">
        /// The original database model.
        /// </param>
        /// <param name="changedDatabaseModel">
        /// The changed database model.
        /// </param>
        private void RemoveTableFromChangedModel(
            DatabaseModel originalDatabaseModel,
            DatabaseModel changedDatabaseModel)
        {
            Table bankTransfers = changedDatabaseModel.Tables.FirstOrDefault(t => t.TableName == "BankTransfers");

            changedDatabaseModel.Tables.Remove(bankTransfers);

            ApplicationTableCollectionDifference differences = this.Differences.CompareTables(
                originalDatabaseModel.Tables,
                changedDatabaseModel.Tables);

            Assert.AreEqual(0, differences.FirstExtraTables.Count, "There should be 0 Extra tables");
            Assert.AreEqual(1, differences.FirstMissingTables.Count, "There should be 1 missing table");
            Assert.AreEqual(0, differences.ProblemTables.Count, "There should be 0 problem tables");
            Assert.AreEqual(0, differences.RefreshTable.Count, "There should be 0 refresh tables");

            changedDatabaseModel.Tables.Insert(0, bankTransfers);
        }
Exemple #6
0
        /// <summary>
        ///     The update data source.
        /// </summary>
        private void UpdateDataSource()
        {
            Logger.Trace("Started UpdateDataSource()");

            if (this.DataSource != null)
            {
                this.sourceType = ScaffoldConfig.ReturnSourceType(this.DataSource.SourceTypeId);

                var sourceOptions = this.sourceType.Load(this.SavePath);

                if (this.sourceType.Test(sourceOptions))
                {
                    this.StartSplashScreen();
                    Thread.Sleep(100);
                    SplashScreen.UdpateStatusText("Loading schema information");

                    this.sourceDomain = this.sourceType.Import(sourceOptions);

                    IApplicationTableCollectionDifference differenceService =
                        new ApplicationTableCollectionDifference(new ApplicationTableDifference());
                    this.differences = differenceService.CompareTables(this.DataSource.Tables, this.sourceDomain.Tables);

                    ITableHierarchyService applicationService = new TempateHierarchyService();
                    List <Hierarchy>       hierarchy          = applicationService.ReturnHierarchyFromList(
                        this.differences.FirstExtraTables,
                        false,
                        false,
                        false);
                    this.AddNodes("Models", this.TreeViewAdd, hierarchy, applicationService);

                    hierarchy = applicationService.ReturnHierarchyFromList(this.differences.RefreshTable, false, false, false);

                    this.AddNodes("Models", this.TreeViewRefresh, hierarchy, applicationService);

                    hierarchy = applicationService.ReturnHierarchyFromList(
                        this.differences.FirstMissingTables,
                        false,
                        false,
                        false);

                    this.AddNodes("Models", this.TreeViewDelete, hierarchy, applicationService);
                    this.Valid = true;

                    Thread.Sleep(100);
                    this.CloseSplashScreen(false);
                }
                else
                {
                    MessageBox.Show(
                        "Invalid configuration. Please update source configuration.",
                        "Configuration Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    this.Valid = false;
                }
            }
            else
            {
                this.Valid = false;
                Logger.Trace("Data Source not updated as domain is null ");
            }

            Logger.Trace("Completed UpdateDataSource()");
        }
        /// <summary>
        /// The update column.
        /// </summary>
        /// <param name="originalDatabaseModel">
        /// The original database model.
        /// </param>
        /// <param name="changedDatabaseModel">
        /// The changed database model.
        /// </param>
        private void UpdateColumn(
            DatabaseModel originalDatabaseModel,
            DatabaseModel changedDatabaseModel)
        {
            Table  bankTransfers         = changedDatabaseModel.Tables.FirstOrDefault(t => t.TableName == "BankTransfers");
            Column bankTransfersIdColumn = bankTransfers.Columns.FirstOrDefault(c => c.ColumnName == "BankTransferId");

            // Test DomainType
            bankTransfersIdColumn.DomainDataType = DomainDataType.Boolean;

            ApplicationTableCollectionDifference differences = this.Differences.CompareTables(
                originalDatabaseModel.Tables,
                changedDatabaseModel.Tables);

            this.SharedColumnChanged(differences);
            Assert.AreEqual(
                DomainDataType.Int32,
                differences.ProblemTables[0].ColumnDataTypeDiffs[0].FirstColumnDataType);
            Assert.AreEqual(
                DomainDataType.Boolean,
                differences.ProblemTables[0].ColumnDataTypeDiffs[0].SecondColumnDataType);

            bankTransfersIdColumn.DomainDataType = DomainDataType.Int32;

            // Test ColumnOrder
            bankTransfersIdColumn.ColumnOrder = 3;

            differences = this.Differences.CompareTables(originalDatabaseModel.Tables, changedDatabaseModel.Tables);

            this.SharedColumnChanged(differences);

            Assert.AreEqual(true, differences.ProblemTables[0].ColumnDataTypeDiffs[0].ColumnOrderIsDifferent);
            bankTransfersIdColumn.ColumnOrder = 1;

            // Test IsPrimaryKey
            bankTransfersIdColumn.IsPrimaryKey = false;

            differences = this.Differences.CompareTables(originalDatabaseModel.Tables, changedDatabaseModel.Tables);

            this.SharedColumnChanged(differences);

            Assert.AreEqual(true, differences.ProblemTables[0].ColumnDataTypeDiffs[0].PrimaryKeyIsDifferent);
            bankTransfersIdColumn.IsPrimaryKey = true;

            // Test IsRequired
            bankTransfersIdColumn.IsRequired = false;

            differences = this.Differences.CompareTables(originalDatabaseModel.Tables, changedDatabaseModel.Tables);

            this.SharedColumnChanged(differences);

            Assert.AreEqual(true, differences.ProblemTables[0].ColumnDataTypeDiffs[0].IsRequiredDifferent);
            bankTransfersIdColumn.IsRequired = true;

            // Test Length
            bankTransfersIdColumn.Length = 1;

            differences = this.Differences.CompareTables(originalDatabaseModel.Tables, changedDatabaseModel.Tables);

            this.SharedColumnChanged(differences);

            Assert.AreEqual(true, differences.ProblemTables[0].ColumnDataTypeDiffs[0].LengthIsDifferent);
            bankTransfersIdColumn.Length = 0;

            // Test Precision
            bankTransfersIdColumn.Precision = 1;

            differences = this.Differences.CompareTables(originalDatabaseModel.Tables, changedDatabaseModel.Tables);

            this.SharedColumnChanged(differences);

            Assert.AreEqual(true, differences.ProblemTables[0].ColumnDataTypeDiffs[0].PrecisionIsDifferent);
            bankTransfersIdColumn.Precision = 0;

            // Test Scale
            bankTransfersIdColumn.Scale = 1;

            differences = this.Differences.CompareTables(originalDatabaseModel.Tables, changedDatabaseModel.Tables);

            this.SharedColumnChanged(differences);

            Assert.AreEqual(true, differences.ProblemTables[0].ColumnDataTypeDiffs[0].ScaleIsDifferent);
            bankTransfersIdColumn.Scale = 0;
        }