コード例 #1
0
        public void CollectValidationErrorsShouldReturnNoErrorsIfForeignTableNameAndForeignKeyNameAreSet()
        {
            var expression = new DeleteForeignKeyExpression { ForeignKey = new ForeignKeyDefinition { ForeignTable = "ForeignTable", Name = "FK"} };
            var errors = ValidationHelper.CollectErrors(expression);

            Assert.That(errors.Count, Is.EqualTo(0));
        }
コード例 #2
0
        public void Delete_Foreign_Key_Should_Throw_Exception_If_Table_Name_Is_Null()
        {
            // Setup empty FK
            var deleteFKExpression = new DeleteForeignKeyExpression();
            var fkDef = new ForeignKeyDefinition();
            deleteFKExpression.ForeignKey = fkDef;

            // Setup empty mock object
            var mockGenerator = new MockGenerator(null, null, null);

            Assert.Throws<ArgumentNullException>(() => mockGenerator.Generate(deleteFKExpression));
        }
コード例 #3
0
        public void CollectValidationErrorsShouldReturnErrorsIfForeignColumnsAreSetButNotPrimaryTable()
        {
            var expression = new DeleteForeignKeyExpression
            {
                ForeignKey = new ForeignKeyDefinition
                {
                    ForeignColumns = new Collection<string> { "User_id" },
                    ForeignTable = "UserRoles",
                    Name = "FK"
                }
            };
            var errors = ValidationHelper.CollectErrors(expression);

            errors.ShouldContain(ErrorMessages.PrimaryTableNameCannotBeNullOrEmpty);
        }
コード例 #4
0
 public void ReverseReturnsDeleteForeignKeyExpressionAfterApplyingConventions()
 {
     var expression = new DeleteForeignKeyExpression
     {
         ForeignKey = new ForeignKeyDefinition
         {
             ForeignColumns = new Collection<string> { "User_id" },
             ForeignTable = "UserRoles",
             PrimaryColumns = new Collection<string> { "Id" },
             PrimaryTable = "User",
         }
     };
     expression.ApplyConventions(new MigrationConventions());
     var reverse = expression.Reverse();
     reverse.ShouldBeOfType<CreateForeignKeyExpression>();
 }
コード例 #5
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     truncator.Truncate(expression);
     return base.Generate(expression);
 }
コード例 #6
0
        public override string Generate(DeleteForeignKeyExpression expression)
        {
            if (expression.ForeignKey.ForeignTable == null)
                throw new ArgumentNullException("Table name not specified, ensure you have appended the OnTable extension. Format should be Delete.ForeignKey(KeyName).OnTable(TableName)");

            return string.Format(DeleteConstraint, Quoter.QuoteTableName(expression.ForeignKey.ForeignTable), Quoter.QuoteColumnName(expression.ForeignKey.Name));
        }
コード例 #7
0
 public IDeleteForeignKeyFromTableSyntax ForeignKey()
 {
     var expression = new DeleteForeignKeyExpression();
     _context.Expressions.Add(expression);
     return new DeleteForeignKeyExpressionBuilder(expression);
 }
コード例 #8
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     return string.Format(DeleteConstraint, Quoter.QuoteTableName(expression.ForeignKey.ForeignTable), Quoter.QuoteColumnName(expression.ForeignKey.Name));
 }
コード例 #9
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     return string.Format("ALTER TABLE {0}.{1} DROP CONSTRAINT {2}", Quoter.QuoteSchemaName(expression.ForeignKey.ForeignTableSchema), Quoter.QuoteTableName(expression.ForeignKey.ForeignTable), Quoter.Quote(expression.ForeignKey.Name));
 }
コード例 #10
0
 public static DeleteForeignKeyExpression GetDeleteForeignKeyExpression()
 {
     var expression = new DeleteForeignKeyExpression();
     expression.ForeignKey.Name = "FK_Test";
     expression.ForeignKey.ForeignTable = TestTableName1;
     return expression;
 }
コード例 #11
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     return string.Format("ALTER TABLE {0}.{1} DROP CONSTRAINT {2}", FormatSchema(expression.ForeignKey.ForeignTableSchema), FormatIdentifier(expression.ForeignKey.ForeignTable), FormatIdentifier(expression.ForeignKey.Name));
 }
コード例 #12
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
        public void CollectValidationErrorsShouldReturnErrorsIfForeignColumnsAreSetButNotPrimaryColumns()
        {
            var expression = new DeleteForeignKeyExpression
            {
                ForeignKey = new ForeignKeyDefinition
                {
                    ForeignColumns = new Collection<string> { "User_id" },
                    ForeignTable = "UserRoles",
                    PrimaryTable = "User",
                    Name = "FK"
                }
            };
            var errors = ValidationHelper.CollectErrors(expression);

            errors.ShouldContain(ErrorMessages.ForeignKeyMustHaveOneOrMorePrimaryColumns);
        }
コード例 #14
0
 public void CollectValidationErrorsShouldReturnErrorIfForeignTableNameIsNull()
 {
     var expression = new DeleteForeignKeyExpression { ForeignKey = new ForeignKeyDefinition { ForeignTable = null } };
     var errors = ValidationHelper.CollectErrors(expression);
     errors.ShouldContain(ErrorMessages.ForeignTableNameCannotBeNullOrEmpty);
 }
コード例 #15
0
 public void ReverseSetsForeignTableAndForeignColumnsAndPrimaryTableAndPrimaryColumnsAOnGeneratedExpression()
 {
     var expression = new DeleteForeignKeyExpression
     {
         ForeignKey = new ForeignKeyDefinition
         {
             ForeignColumns = new Collection<string> { "ForeignId" },
             ForeignTable = "UserRoles",
             PrimaryColumns = new Collection<string> { "PrimaryId" },
             PrimaryTable = "User",
         }
     };
     var reverse = expression.Reverse() as CreateForeignKeyExpression;
     reverse.ForeignKey.ForeignTable.ShouldBe("User");
     reverse.ForeignKey.PrimaryTable.ShouldBe("UserRoles");
     reverse.ForeignKey.ForeignColumns.First().ShouldBe("PrimaryId");
     reverse.ForeignKey.PrimaryColumns.First().ShouldBe("ForeignId");
 }
コード例 #16
0
        public void CanDropForeignKey()
        {
            var expression = new DeleteForeignKeyExpression();
            expression.ForeignKey.Name = "FK_Test";
            expression.ForeignKey.ForeignTable = "TestPrimaryTable";

            string sql = generator.Generate(expression);
            sql.ShouldBe("ALTER TABLE \"public\".\"TestPrimaryTable\" DROP CONSTRAINT \"FK_Test\"");
        }
コード例 #17
0
 public void Truncate(DeleteForeignKeyExpression expression)
 {
     Truncate(expression.ForeignKey);
 }
コード例 #18
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     return string.Format("ALTER TABLE {0}", base.Generate(expression));
 }
コード例 #19
0
 public virtual void Process(DeleteForeignKeyExpression expression)
 {
     Process(Generator.Generate(expression));
 }
コード例 #20
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     const string sql = "ALTER TABLE {0}[{1}] DROP CONSTRAINT {2}";
     return string.Format(sql, FormatSchema(expression.ForeignKey.ForeignTableSchema), expression.ForeignKey.ForeignTable, expression.ForeignKey.Name);
 }
コード例 #21
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     return "";
 }
コード例 #22
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     return compatabilityMode.HandleCompatabilty("Forign keys are not supported in Sqlite");
 }
コード例 #23
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     string sql = "ALTER TABLE {0} DROP CONSTRAINT {1}";
     return String.Format(sql, expression.ForeignKey.ForeignTable, expression.ForeignKey.Name);
 }
コード例 #24
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     string sql = "ALTER TABLE {0} DROP FOREIGN KEY `{1}`";
     return String.Format(sql, expression.ForeignKey.PrimaryTable, expression.ForeignKey.Name);
 }
コード例 #25
0
 public IDeleteForeignKeyOnTableSyntax ForeignKey(string foreignKeyName)
 {
     var expression = new DeleteForeignKeyExpression { ForeignKey = { Name = foreignKeyName } };
     _context.Expressions.Add(expression);
     return new DeleteForeignKeyExpressionBuilder(expression);
 }
コード例 #26
0
 public override string Generate(DeleteForeignKeyExpression expression)
 {
     return string.Format("ALTER TABLE {0}.{1}", Quoter.QuoteSchemaName(expression.ForeignKey.ForeignTableSchema), base.Generate(expression));
 }
コード例 #27
0
        public void CanDropForeignKey()
        {
            var expression = new DeleteForeignKeyExpression();
            expression.ForeignKey.Name = "FK_Test";
            expression.ForeignKey.ForeignTable = "TestPrimaryTable";

            var sql = generator.Generate(expression);
            sql.ShouldBe("ALTER TABLE [TestPrimaryTable] DROP CONSTRAINT FK_Test");
        }
コード例 #28
0
 public abstract string Generate(DeleteForeignKeyExpression expression);
コード例 #29
0
        public void CanDropForeignKey()
        {
            var expression = new DeleteForeignKeyExpression();
            expression.ForeignKey.Name = "FK_Test";
            expression.ForeignKey.ForeignTable = "TestPrimaryTable";

            var sql = generator.Generate(expression);
            sql.ShouldBe("ALTER TABLE `TestPrimaryTable` DROP FOREIGN KEY `FK_Test`");
        }
コード例 #30
0
 public void ReverseReturnsDeleteForeignKeyExpression()
 {
     var expression = new DeleteForeignKeyExpression
     {
         ForeignKey = new ForeignKeyDefinition
         {
             ForeignColumns = new Collection<string> { "User_id" },
             ForeignTable = "UserRoles",
             PrimaryColumns = new Collection<string> { "Id" },
             PrimaryTable = "User",
             Name = "FK"
         }
     };
     var reverse = expression.Reverse();
     reverse.ShouldBeOfType<CreateForeignKeyExpression>();
 }