Exemplo n.º 1
0
        public void All_Of_The_Operations_Are_Put_Into_The_Result()
        {
            var columnOp = MockRepository.GenerateMock<MergeOperation<IColumn>>();
            var tableOp = MockRepository.GenerateMock<MergeOperation<ITable>>();
            var keyOp = MockRepository.GenerateMock<MergeOperation<IKey>>();
            var indexOp = MockRepository.GenerateMock<MergeOperation<IIndex>>();

            DatabaseMergeResult result1 = new DatabaseMergeResult();
            result1.AddColumnOperation(columnOp);
            result1.AddTableOperation(tableOp);
            result1.AddKeyOperation(keyOp);
            result1.AddIndexOperation(indexOp);

            DatabaseMergeResult result2 = new DatabaseMergeResult();
            result2.CopyFrom(result1);

            Assert.That(result1.ColumnOperations, Has.Count(1));
            Assert.That(result1.TableOperations, Has.Count(1));
            Assert.That(result1.KeyOperations, Has.Count(1));
            Assert.That(result1.IndexOperations, Has.Count(1));

            Assert.That(result1.ColumnOperations.ElementAt(0), Is.SameAs(columnOp));
            Assert.That(result1.TableOperations.ElementAt(0), Is.SameAs(tableOp));
            Assert.That(result1.KeyOperations.ElementAt(0), Is.SameAs(keyOp));
            Assert.That(result1.IndexOperations.ElementAt(0), Is.SameAs(indexOp));
        }
Exemplo n.º 2
0
        public void It_Should_Call_Back_To_The_Main_Panel()
        {
            var form    = MockRepository.GenerateMock <ISimpleDBMergeResultForm>();
            var results = new DatabaseMergeResult();
            var panel   = MockRepository.GenerateMock <IMainPanel>();

            var tableOp  = MockRepository.GenerateMock <IMergeOperation <ITable> >();
            var columnOp = MockRepository.GenerateMock <IMergeOperation <IColumn> >();
            var keyOp    = MockRepository.GenerateMock <IMergeOperation <IKey> >();
            var indexOp  = MockRepository.GenerateMock <IMergeOperation <IIndex> >();

            results.AddTableOperation(tableOp);
            results.AddColumnOperation(columnOp);
            results.AddKeyOperation(keyOp);
            results.AddIndexOperation(indexOp);

            new SimpleDBMergeResultPresenter(form, panel, results);
            form.GetEventRaiser(f => f.ChangesCancelled += null).Raise(form, null);

            panel.AssertWasCalled(f => f.CloseDatabaseRefreshResultsForm(Changes.WereRejected));
            tableOp.AssertWasNotCalled(o => o.RunOperation());
            columnOp.AssertWasNotCalled(o => o.RunOperation());
            keyOp.AssertWasNotCalled(o => o.RunOperation());
            indexOp.AssertWasNotCalled(o => o.RunOperation());
        }
        public void All_Of_The_Operations_Are_Put_Into_The_Result()
        {
            var columnOp = MockRepository.GenerateMock <MergeOperation <IColumn> >();
            var tableOp  = MockRepository.GenerateMock <MergeOperation <ITable> >();
            var keyOp    = MockRepository.GenerateMock <MergeOperation <IKey> >();
            var indexOp  = MockRepository.GenerateMock <MergeOperation <IIndex> >();

            DatabaseMergeResult result1 = new DatabaseMergeResult();

            result1.AddColumnOperation(columnOp);
            result1.AddTableOperation(tableOp);
            result1.AddKeyOperation(keyOp);
            result1.AddIndexOperation(indexOp);

            DatabaseMergeResult result2 = new DatabaseMergeResult();

            result2.CopyFrom(result1);

            Assert.That(result1.ColumnOperations, Has.Count(1));
            Assert.That(result1.TableOperations, Has.Count(1));
            Assert.That(result1.KeyOperations, Has.Count(1));
            Assert.That(result1.IndexOperations, Has.Count(1));

            Assert.That(result1.ColumnOperations.ElementAt(0), Is.SameAs(columnOp));
            Assert.That(result1.TableOperations.ElementAt(0), Is.SameAs(tableOp));
            Assert.That(result1.KeyOperations.ElementAt(0), Is.SameAs(keyOp));
            Assert.That(result1.IndexOperations.ElementAt(0), Is.SameAs(indexOp));
        }
Exemplo n.º 4
0
        public void The_Form_Is_Set_Up_Properly()
        {
            var form    = MockRepository.GenerateMock <ISimpleDBMergeResultForm>();
            var results = new DatabaseMergeResult();
            var panel   = MockRepository.GenerateStub <IMainPanel>();
            var addOp   = new TableAdditionOperation(new Database("db"), new Table("table"));
            var remOp   = new TableRemovalOperation(new Table("table"));

            results.AddTableOperation(addOp);
            results.AddTableOperation(remOp);

            new SimpleDBMergeResultPresenter(form, panel, results);

            // Not the nicest syntax, but this is a test to check that all
            form.AssertWasCalled(f => f.AddedTableOperations = Arg <IEnumerable <IMergeOperation <ITable> > > .Matches(t => t.Count() == 1 &&
                                                                                                                       t.ElementAt(0) == addOp));
            form.AssertWasCalled(f => f.RemovedTableOperations = Arg <IEnumerable <IMergeOperation <ITable> > > .Matches(t => t.Count() == 1 &&
                                                                                                                         t.ElementAt(0) == remOp));
        }
        public void The_Operations_Come_Back_In_A_Good_Order()
        {
            DatabaseMergeResult result = new DatabaseMergeResult();
            result.AddIndexOperation(new IndexAdditionOperation(new Table(), new Index()));
            result.AddKeyOperation(new KeyAdditionOperation(new Table(), new Key()));
            // Not a ITwoStepMergeOperation
            result.AddTableOperation(new TableAdditionOperation(new Database(""), new Table()));

            IEnumerable<ITwoStepMergeOperation> list = result.TwoStepOperations;

            Assert.That(list, Has.Count(2));
            Assert.That(list.ElementAt(0) is KeyAdditionOperation);
            Assert.That(list.ElementAt(1) is IndexAdditionOperation);
        }
Exemplo n.º 6
0
        public void The_Operations_Come_Back_In_A_Good_Order()
        {
            DatabaseMergeResult result = new DatabaseMergeResult();

            result.AddIndexOperation(new IndexAdditionOperation(new Table(), new Index()));
            result.AddKeyOperation(new KeyAdditionOperation(new Table(), new Key()));
            // Not a ITwoStepMergeOperation
            result.AddTableOperation(new TableAdditionOperation(new Database(""), new Table()));

            IEnumerable <ITwoStepMergeOperation> list = result.TwoStepOperations;

            Assert.That(list, Has.Count(2));
            Assert.That(list.ElementAt(0) is KeyAdditionOperation);
            Assert.That(list.ElementAt(1) is IndexAdditionOperation);
        }
Exemplo n.º 7
0
        public void It_Should_Apply_Changes_And_Call_Back_To_The_Main_Panel()
        {
            var form    = MockRepository.GenerateStub <ISimpleDBMergeResultForm>();
            var results = new DatabaseMergeResult();
            var panel   = MockRepository.GenerateMock <IMainPanel>();

            // These are all two step processes
            var tableOp  = new MockMergeOperation <ITable, Table>();
            var columnOp = new MockMergeOperation <IColumn, Column>();
            var keyOp    = new MockMergeOperation <IKey, Key>();
            var indexOp  = new MockMergeOperation <IIndex, Index>();

            results.AddTableOperation(tableOp);
            results.AddColumnOperation(columnOp);
            results.AddKeyOperation(keyOp);
            results.AddIndexOperation(indexOp);

            form.Stub(f => { var v = f.SelectedAddedTableOperations; }).Return(new List <IMergeOperation <ITable> > {
                tableOp
            });
            form.Stub(f => { var v = f.SelectedRemovedTableOperations; }).Return(new List <IMergeOperation <ITable> >());

            new SimpleDBMergeResultPresenter(form, panel, results);
            form.GetEventRaiser(f => f.ChangesAccepted += null).Raise(form, null);

            panel.AssertWasCalled(f => f.CloseDatabaseRefreshResultsForm(Changes.WereAccepted));

            Assert.That(tableOp.OperationRun, Is.True);
            Assert.That(indexOp.OperationRun, Is.True);
            Assert.That(columnOp.OperationRun, Is.True);
            Assert.That(keyOp.OperationRun, Is.True);

            Assert.That(tableOp.SecondStepRun, Is.True);
            Assert.That(indexOp.SecondStepRun, Is.True);
            Assert.That(columnOp.SecondStepRun, Is.True);
            Assert.That(keyOp.SecondStepRun, Is.True);
        }
Exemplo n.º 8
0
        public DatabaseMergeResult MergeDatabases(IDatabase db1, IDatabase db2)
        {
            DatabaseMergeResult mergeResult = new DatabaseMergeResult();

            #region Tables
            IEnumerable<ITable> tables1 = db1.Tables;
            IEnumerable<ITable> tables2 = db2.Tables;

            List<ITable> newTables = tables1.Compliment(tables2).ToList();
            List<ITable> removedTables = tables2.Compliment(tables1).ToList();

            // Check for changed tables.
            Func<ITable, string> sorter = n => n.Name;
            Table.TableComparer comparer = new Table.TableComparer();
            IEnumerable<ITable> intersection1 = tables1.Intersect(tables2, comparer).OrderBy(sorter);
            var commonItems = intersection1.Zip(tables2.Intersect(tables1, comparer).OrderBy(sorter));

            foreach (var memberPair in commonItems)
                if (memberPair.Key.HasChanges(memberPair.Value))
                    mergeResult.AddTableOperation(new TableChangeOperation(memberPair.Key, memberPair.Value));

            foreach (var t in newTables)
                mergeResult.AddTableOperation(new TableAdditionOperation(db1, t));

            foreach (var t in removedTables)
                mergeResult.AddTableOperation(new TableRemovalOperation(t));

            TableProcessor processor = new TableProcessor();
            var tableResults = processor.ProcessTables(tables1, tables2);
            mergeResult.CopyFrom(tableResults);
            #endregion

            #region Views
            IEnumerable<ITable> views1 = db1.Views;
            IEnumerable<ITable> views2 = db2.Views;

            List<ITable> newViews = views1.Compliment(views2).ToList();
            List<ITable> removedViews = views2.Compliment(views1).ToList();

            // Check for changed tables.
            IEnumerable<ITable> viewsIntersection1 = views1.Intersect(views2, comparer).OrderBy(sorter);
            var commonViewItems = intersection1.Zip(views2.Intersect(views1, comparer).OrderBy(sorter));

            foreach (var memberPair in commonViewItems)
                if (memberPair.Key.HasChanges(memberPair.Value))
                    mergeResult.AddViewOperation(new TableChangeOperation(memberPair.Key, memberPair.Value));

            foreach (var t in newViews)
                mergeResult.AddViewOperation(new TableAdditionOperation(db1, t));

            foreach (var t in removedViews)
                mergeResult.AddViewOperation(new TableRemovalOperation(t));

            TableProcessor viewProcessor = new TableProcessor();
            var viewResults = processor.ProcessTables(views1, views2);
            mergeResult.CopyFrom(viewResults);
            #endregion

            return mergeResult;
        }