public void ShouldDisableTableColumnPropertyIfTableRemovedByMerge()
        {
            var op       = new AddExtendedPropertyOperation("schema", "table", "column", "name", "value", false);
            var removeOp = new RemoveTableOperation("SCHEMA", "TABLE");

            op.Merge(removeOp);
            Assert.That(op.Disabled, Is.True);
            Assert.That(removeOp.Disabled, Is.False);
        }
        public void ShouldRemoveUpdateOperationIfTableRemoved()
        {
            var op            = new UpdateTableOperation("schema", "table Name", new Column[0], new Column[0], new string[0]);
            var removeTableOp = new RemoveTableOperation("SCHEMA", "TABLE NAME");

            op.Merge(removeTableOp);
            Assert.That(op.Disabled, Is.True);
            Assert.That(removeTableOp.Disabled, Is.True);
        }
        public void ShouldNotRemoveUpdateOperationIfItIsADifferentTable()
        {
            var op            = new UpdateTableOperation("schema", "tableName", new Column[0], new Column[0], new string[0]);
            var removeTableOp = new RemoveTableOperation("SCHEMA", "tableName2");

            op.Merge(removeTableOp);
            Assert.That(op.Disabled, Is.False);
            Assert.That(removeTableOp.Disabled, Is.False);
        }
Exemple #4
0
        public void ShouldDisableWhenMergedWithRemoveOperation()
        {
            var op       = new AddTableOperation("schema", "name", new Column[0], false, "filegroup", "textimagefilegroup", "filestreamgroup", new string[0]);
            var removeOp = new RemoveTableOperation("SCHEMA", "NAME");

            op.Merge(removeOp);
            Assert.That(op.Disabled, Is.True);
            Assert.That(removeOp.Disabled, Is.True);
        }
        public void ShouldNotDisableOperationWhenItsIsForAViewAndATableWithTheSameNameIsRemoved()
        {
            var op            = new AddExtendedPropertyOperation("schema", "view", "name", "value", true);
            var removeTableOp = new RemoveTableOperation("SCHEMA", "VIEW");

            op.Merge(removeTableOp);
            Assert.That(op.Disabled, Is.False);
            Assert.That(removeTableOp.Disabled, Is.False);
        }
        public void ShouldWriteQueryForRemoveTable()
        {
            var schemaName = "schemaName";
            var tableName  = "tableName";

            var op            = new RemoveTableOperation(schemaName, tableName);
            var expectedQuery = string.Format("drop table [{0}].[{1}]", schemaName, tableName);

            Assert.That(op.ToQuery(), Is.EqualTo(expectedQuery));
        }
        public void ShouldSetPropertiesForRemoveTable()
        {
            var schemaName = "schemaName";
            var tableName  = "tableName";

            var op = new RemoveTableOperation(schemaName, tableName);

            Assert.AreEqual(schemaName, op.SchemaName);
            Assert.AreEqual(tableName, op.Name);
            Assert.That(op.ObjectName, Is.EqualTo(string.Format("{0}.{1}", schemaName, tableName)));
        }
        public void ShouldDisableObjectOperationIfPartOfARemovedTable()
        {
            var tableObjectOps = new TableObjectOperation[]
            {
                new AddCheckConstraintOperation("schema", "table", "column", "expression", false, false),
                new AddDefaultConstraintOperation("schema", "table", "name", "column", "expression", false),
                new AddForeignKeyOperation("schema", "table", "name", new[] { "column" }, "ref_schema", "ref_table", new[] { "ref_column" }, "onDelete", "onUpdate", false, false),
                new AddIndexOperation("schema", "table", "name", null, false, false, null, null, null, null, null),
                new AddPrimaryKeyOperation("schema", "table", "name", new[] { "column" }, false, new string[0]),
                new AddRowGuidColOperation("schema", "table", "column"),
                new AddUniqueKeyOperation("schema", "table", "name", new[] { "column" }, false, 0, new string[0], "filegroup"),
                new DisableConstraintOperation("schema", "table", "name"),
                new EnableConstraintOperation("schema", "table", "name", false),
                new RemoveCheckConstraintOperation("schema", "table", "name"),
                new RemoveDefaultConstraintOperation("schema", "table", "column", "name"),
                new RemoveForeignKeyOperation("schema", "table", "name"),
                new RemoveIndexOperation("schema", "table", "name", new[] { "column" }, true),
                new RemovePrimaryKeyOperation("schema", "table", "name"),
                new RemoveRowGuidColOperation("schema", "table", "name"),
                new RemoveUniqueKeyOperation("schema", "table", "name", new[] { "column" }),
            };

            // first, make sure we have them all.
            var expectedOps = AppDomain.CurrentDomain.GetAssemblies()
                              .Where(assembly => assembly.GetName().Name == "Rivet")
                              .SelectMany(assembly => assembly.GetTypes())
                              .Where(type => type.IsSubclassOf(typeof(TableObjectOperation)))
                              .Where(type => !type.IsAbstract);

            Assert.That(expectedOps, Is.Not.Empty);
            foreach (var expectedOp in expectedOps)
            {
                var count = tableObjectOps.Where(t => t.GetType() == expectedOp).Count();
                Assert.That(count, Is.Not.EqualTo(0),
                            $"Class {expectedOp.FullName} is missing. Please add an instance of this type to this test.");
            }

            foreach (var op in tableObjectOps)
            {
                var removeTableOp = new RemoveTableOperation("SCHEMA", "TABLE");
                op.Merge(removeTableOp);
                Assert.That(op.Disabled, Is.True,
                            $"{op.GetType().Name} should be disabled when its table is removed.");
                Assert.That(removeTableOp.Disabled, Is.False);
            }
        }