Example #1
0
        public void Should_throw_InvalidOperationException_if_used_with_CreateIndex()
        {
            Migration.ConfigureUp = builder => builder.CreateIndex("Foo", "Bar", "Col1").IfExists();

            ExecuteMigration.Invoking(a => a())
            .Should().Throw <InvalidOperationException>();
        }
Example #2
0
        public void Should_not_throw_if_used_with_DropColumn_and_column_not_exists()
        {
            Migration.ConfigureUp = builder => builder.DropColumn("Foo", "Bar").IfExists();

            ExecuteMigration.Invoking(a => a())
            .Should().NotThrow();
        }
Example #3
0
        public void Should_throw_InvalidOperationException_if_used_with_AddColumn()
        {
            Migration.ConfigureUp = builder => builder.AddColumn <int>("Foo", "Bar").IfExists();

            ExecuteMigration.Invoking(a => a())
            .Should().Throw <InvalidOperationException>();
        }
Example #4
0
        public void Should_throw_InvalidOperationException_if_used_with_CreateTable()
        {
            Migration.ConfigureUp = builder => builder.CreateTable("Foo", table => new { Bar = table.Column <int>() }).IfExists();

            ExecuteMigration.Invoking(a => a())
            .Should().Throw <InvalidOperationException>();
        }
Example #5
0
        public void Should_throw_InvalidOperationException_if_used_with_DropTable()
        {
            Migration.ConfigureUp = builder => builder.DropTable("Foo").IfNotExists();

            ExecuteMigration.Invoking(a => a())
            .Should().Throw <InvalidOperationException>();
        }
Example #6
0
        public void Should_not_throw_if_used_with_AddUniqueConstraint_and_constraint_exists()
        {
            var tableName      = MethodBase.GetCurrentMethod() !.Name;
            var constraintName = $"UC_{tableName}";

            try
            {
                Migration.ConfigureUp = builder => builder.AddUniqueConstraint(constraintName, tableName, "Col1").IfNotExists();
                Context.Database.ExecuteSqlRaw($"CREATE TABLE [{tableName}] (Col1 INT, Col2 INT)");
                Context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] ADD CONSTRAINT [{constraintName}] UNIQUE (Col1);");

                ExecuteMigration.Invoking(a => a())
                .Should().NotThrow();
            }
            finally
            {
                Context.Database.ExecuteSqlRaw($"DROP TABLE IF EXISTS [{tableName}]");
            }
        }