public void Dispatches_visitor()
        {
            var addDefaultConstraintOperation = new AddDefaultConstraintOperation(
                "dbo.MyTable", "Foo", "MyDefault", null);
            var mockVisitor = new Mock<MigrationOperationSqlGenerator>(new RelationalTypeMapper());
            var builder = new Mock<IndentedStringBuilder>();
            addDefaultConstraintOperation.GenerateSql(mockVisitor.Object, builder.Object);

            mockVisitor.Verify(g => g.Generate(addDefaultConstraintOperation, builder.Object), Times.Once());
        }
        public void Create_and_initialize_operation()
        {
            var addDefaultConstraintOperation = new AddDefaultConstraintOperation(
                "dbo.MyTable", "Foo", "MyDefault", null);

            Assert.Equal("dbo.MyTable", addDefaultConstraintOperation.TableName);
            Assert.Same("Foo", addDefaultConstraintOperation.ColumnName);
            Assert.Equal("MyDefault", addDefaultConstraintOperation.DefaultValue);
            Assert.Null(addDefaultConstraintOperation.DefaultSql);
            Assert.False(addDefaultConstraintOperation.IsDestructiveChange);

            var addDefaultConstraintOperation2 = new AddDefaultConstraintOperation(
                "dbo.MyTable", "Foo", null, "GETDATE()");

            Assert.Equal("dbo.MyTable", addDefaultConstraintOperation2.TableName);
            Assert.Same("Foo", addDefaultConstraintOperation2.ColumnName);
            Assert.Null(addDefaultConstraintOperation2.DefaultValue);
            Assert.Equal("GETDATE()", addDefaultConstraintOperation2.DefaultSql);
            Assert.False(addDefaultConstraintOperation2.IsDestructiveChange);
        }
        public override void Generate(AddDefaultConstraintOperation addDefaultConstraintOperation, IndentedStringBuilder stringBuilder)
        {
            Check.NotNull(addDefaultConstraintOperation, "addDefaultConstraintOperation");
            Check.NotNull(stringBuilder, "stringBuilder");

            var tableName = addDefaultConstraintOperation.TableName;
            var columnName = addDefaultConstraintOperation.ColumnName;

            stringBuilder
                .Append("ALTER TABLE ")
                .Append(DelimitIdentifier(tableName))
                .Append(" ADD CONSTRAINT ")
                .Append(DelimitIdentifier("DF_" + tableName + "_" + columnName))
                .Append(" DEFAULT ");

            stringBuilder.Append(addDefaultConstraintOperation.DefaultSql ?? GenerateLiteral(addDefaultConstraintOperation.DefaultValue));

            stringBuilder
                .Append(" FOR ")
                .Append(DelimitIdentifier(columnName));
        }
 public virtual void Visit([NotNull] AddDefaultConstraintOperation addDefaultConstraintOperation, [NotNull] TContext context)
 {
     VisitDefault(addDefaultConstraintOperation, context);
 }
 public override void Generate(
     AddDefaultConstraintOperation addDefaultConstraintOperation,
     IndentedStringBuilder stringBuilder)
 {
     // TODO: Rebuild table
     throw new NotImplementedException();
 }