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)); }
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)); }
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); }
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>(); }
public override string Generate(DeleteForeignKeyExpression expression) { truncator.Truncate(expression); return base.Generate(expression); }
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)); }
public IDeleteForeignKeyFromTableSyntax ForeignKey() { var expression = new DeleteForeignKeyExpression(); _context.Expressions.Add(expression); return new DeleteForeignKeyExpressionBuilder(expression); }
public override string Generate(DeleteForeignKeyExpression expression) { return string.Format(DeleteConstraint, Quoter.QuoteTableName(expression.ForeignKey.ForeignTable), Quoter.QuoteColumnName(expression.ForeignKey.Name)); }
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)); }
public static DeleteForeignKeyExpression GetDeleteForeignKeyExpression() { var expression = new DeleteForeignKeyExpression(); expression.ForeignKey.Name = "FK_Test"; expression.ForeignKey.ForeignTable = TestTableName1; return expression; }
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)); }
public override string Generate(DeleteForeignKeyExpression expression) { throw new NotImplementedException(); }
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); }
public void CollectValidationErrorsShouldReturnErrorIfForeignTableNameIsNull() { var expression = new DeleteForeignKeyExpression { ForeignKey = new ForeignKeyDefinition { ForeignTable = null } }; var errors = ValidationHelper.CollectErrors(expression); errors.ShouldContain(ErrorMessages.ForeignTableNameCannotBeNullOrEmpty); }
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"); }
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\""); }
public void Truncate(DeleteForeignKeyExpression expression) { Truncate(expression.ForeignKey); }
public override string Generate(DeleteForeignKeyExpression expression) { return string.Format("ALTER TABLE {0}", base.Generate(expression)); }
public virtual void Process(DeleteForeignKeyExpression expression) { Process(Generator.Generate(expression)); }
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); }
public override string Generate(DeleteForeignKeyExpression expression) { return ""; }
public override string Generate(DeleteForeignKeyExpression expression) { return compatabilityMode.HandleCompatabilty("Forign keys are not supported in Sqlite"); }
public override string Generate(DeleteForeignKeyExpression expression) { string sql = "ALTER TABLE {0} DROP CONSTRAINT {1}"; return String.Format(sql, expression.ForeignKey.ForeignTable, expression.ForeignKey.Name); }
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); }
public IDeleteForeignKeyOnTableSyntax ForeignKey(string foreignKeyName) { var expression = new DeleteForeignKeyExpression { ForeignKey = { Name = foreignKeyName } }; _context.Expressions.Add(expression); return new DeleteForeignKeyExpressionBuilder(expression); }
public override string Generate(DeleteForeignKeyExpression expression) { return string.Format("ALTER TABLE {0}.{1}", Quoter.QuoteSchemaName(expression.ForeignKey.ForeignTableSchema), base.Generate(expression)); }
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"); }
public abstract string Generate(DeleteForeignKeyExpression expression);
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`"); }
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>(); }