public void AddingASingleColumnShouldAddItToToColumnList()
        {
            CreateConstraintExpression expression = new CreateConstraintExpression(ConstraintType.Unique);

            CreateConstraintExpressionBuilder builder = new CreateConstraintExpressionBuilder(expression);
            builder.OnTable("FOO").Column("BAR");

            expression.Constraint.Columns.First().ShouldBe("BAR");
        }
        public void SettingTheTableNameSetsTheTableName()
        {
            CreateConstraintExpression expression = new CreateConstraintExpression(ConstraintType.Unique);

            CreateConstraintExpressionBuilder builder = new CreateConstraintExpressionBuilder(expression);
            builder.OnTable("FOO");

            expression.Constraint.TableName.ShouldBe("FOO");
        }
        protected string GetConstraintClusteringString(CreateConstraintExpression constraint)
        {
            object indexType;

            if (!constraint.Constraint.AdditionalFeatures.TryGetValue(
                SqlServerExtensions.ConstraintType, out indexType)) return string.Empty;

            return (indexType.Equals(SqlServerConstraintType.Clustered)) ? " CLUSTERED" : " NONCLUSTERED";
        }
        public void AddingMultipleColumnShouldAddThenToToColumnList()
        {
            CreateConstraintExpression expression = new CreateConstraintExpression(ConstraintType.Unique);

            CreateConstraintExpressionBuilder builder = new CreateConstraintExpressionBuilder(expression);
            builder.OnTable("FOO").Columns(new string[]{"BAR","BAZ" });

            expression.Constraint.Columns.First().ShouldBe("BAR");
            expression.Constraint.Columns.ElementAt(1).ShouldBe("BAZ");
        }
        public void ATableShouldBeAllowedToSpecifyASchema()
        {
            CreateConstraintExpression expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);

            CreateConstraintExpressionBuilder builder = new CreateConstraintExpressionBuilder(expression);
            builder.OnTable("FOO").WithSchema("BAR").Column("BAZ");

            expression.Constraint.SchemaName.ShouldBe("BAR");
            expression.Constraint.TableName.ShouldBe("FOO");
            expression.Constraint.Columns.First().ShouldBe("BAZ");
        }
        public void ErrorIsReturnedWhenHasNoColumns()
        {
            var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey)
            {
                Constraint =
                {
                    TableName = "table1"
                }
            };

            var errors = ValidationHelper.CollectErrors(expression);
            errors.ShouldContain(ErrorMessages.ConstraintMustHaveAtLeastOneColumn);
        }
        public void ErrorIsNotReturnedWhenTableNameIsSetAndHasAtLeastOneColumn()
        {
            var expression = new CreateConstraintExpression(ConstraintType.Unique)
            {
                Constraint =
                {
                    TableName = "table1"
                }
            };
            expression.Constraint.Columns.Add("column1");

            var errors = ValidationHelper.CollectErrors(expression);
            Assert.That(errors.Count, Is.EqualTo(0));
        }
        public void ErrorIsReturnedWhenTableNameIsEmptyString()
        {
            var expression = new CreateConstraintExpression(ConstraintType.Unique)
                                 {
                                     Constraint =
                                         {
                                             TableName =
                                                 String.Empty
                                         }
                                 };

            var errors = ValidationHelper.CollectErrors(expression);
            errors.ShouldContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
        }
        public override string Generate(CreateConstraintExpression expression)
        {
            var constraintType = (expression.Constraint.IsPrimaryKeyConstraint) ? "PRIMARY KEY" : "UNIQUE";

            var constraintClustering = GetConstraintClusteringString(expression);

            string columns = String.Join(", ", expression.Constraint.Columns.Select(x => Quoter.QuoteColumnName(x)).ToArray());

            return string.Format(CreateConstraint, Quoter.QuoteTableName(expression.Constraint.TableName),
                Quoter.Quote(expression.Constraint.ConstraintName),
                constraintType,
                constraintClustering,
                columns);
        }
Ejemplo n.º 10
0
        public override string Generate(CreateConstraintExpression expression)
        {
            var constraintType = (expression.Constraint.IsPrimaryKeyConstraint) ? "PRIMARY KEY" : "UNIQUE";

            string[] columns = new string[expression.Constraint.Columns.Count];

            for (int i = 0; i < expression.Constraint.Columns.Count; i++) {
                columns[i] = Quoter.QuoteColumnName(expression.Constraint.Columns.ElementAt(i));
            }

            return string.Format(CreateConstraint, Quoter.QuoteSchemaName(expression.Constraint.SchemaName),  Quoter.QuoteTableName(expression.Constraint.TableName),
                Quoter.Quote(expression.Constraint.ConstraintName),
                constraintType,
                String.Join(", ", columns));
        }
 public ICreateConstraintOnTableSyntax UniqueConstraint()
 {
     var expression = new CreateConstraintExpression(ConstraintType.Unique);
     _context.Expressions.Add(expression);
     return new CreateConstraintExpressionBuilder(expression);
 }
 public Constraint.ICreateConstraintOnTableSyntax PrimaryKey(string primaryKeyName)
 {
     var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
     expression.Constraint.ConstraintName = primaryKeyName;
     _context.Expressions.Add(expression);
     return new CreateConstraintExpressionBuilder(expression);
 }
 public Constraint.ICreateConstraintOnTableSyntax PrimaryKey()
 {
     var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
     _context.Expressions.Add(expression);
     return new CreateConstraintExpressionBuilder(expression);
 }
Ejemplo n.º 14
0
 public static CreateConstraintExpression GetCreateUniqueConstraintExpression()
 {
     var expression = new CreateConstraintExpression(ConstraintType.Unique);
     expression.Constraint.TableName = TestTableName1;
     expression.Constraint.Columns.Add(TestColumnName1);
     expression.ApplyConventions(new MigrationConventions());
     return expression;
 }
Ejemplo n.º 15
0
 public static CreateConstraintExpression GetCreateNamedUniqueConstraintExpression()
 {
     var expression = new CreateConstraintExpression(ConstraintType.Unique);
     expression.Constraint.TableName = TestTableName1;
     expression.Constraint.Columns.Add(TestColumnName1);
     expression.Constraint.ConstraintName = "TESTUNIQUECONSTRAINT";
     return expression;
 }
 protected string GetConstraintClusteringString(CreateConstraintExpression constraint)
 {
     return string.Empty;
 }
 public void Truncate(CreateConstraintExpression expression)
 {
     Truncate(expression.Constraint);
 }
 protected override string GetConstraintClusteringString(CreateConstraintExpression constraint)
 {
     // Only nonclustered
     return string.Empty;
 }
        public void CanCreatePrimaryKeyWithSchema()
        {
            var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
            expression.Constraint.SchemaName = "Schema";
            expression.Constraint.TableName = "ConstraintTable";
            expression.Constraint.ConstraintName = "PK_Name";
            expression.Constraint.Columns.Add("column1");

            string sql = generator.Generate(expression);
            sql.ShouldBe("ALTER TABLE \"Schema\".\"ConstraintTable\" ADD CONSTRAINT \"PK_Name\" PRIMARY KEY (\"column1\")");
        }
        public void CallingColumnsWithDuplicateNamesAddsSetOfColumnNamesForUnique()
        {
            var expression = new CreateConstraintExpression(ConstraintType.Unique);

            var builder = new CreateConstraintExpressionBuilder(expression);
            builder.Columns(new[] { Column1, Column2, Column1 });

            Assert.That(expression.Constraint.Columns.Count, Is.EqualTo(2));
        }
Ejemplo n.º 21
0
 public virtual void Process(CreateConstraintExpression expression)
 {
     Process(Generator.Generate(expression));
 }
Ejemplo n.º 22
0
 public override string Generate(CreateConstraintExpression expression)
 {
     return string.Format("ALTER TABLE {0}", base.Generate(expression));
 }
 public Constraint.ICreateConstraintOnTableSyntax UniqueConstraint(string constraintName)
 {
     var expression = new CreateConstraintExpression(ConstraintType.Unique);
     expression.Constraint.ConstraintName = constraintName;
     _context.Expressions.Add(expression);
     return new CreateConstraintExpressionBuilder(expression);
 }
Ejemplo n.º 24
0
 public static CreateConstraintExpression GetCreateMultiColumnPrimaryKeyExpression()
 {
     var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
     expression.Constraint.TableName = TestTableName1;
     expression.Constraint.Columns.Add(TestColumnName1);
     expression.Constraint.Columns.Add(TestColumnName2);
     expression.ApplyConventions(new MigrationConventions());
     return expression;
 }
 public void ErrorIsReturnedWhenTableNameisEmpty()
 {
     CreateConstraintExpression expression = new CreateConstraintExpression(Model.ConstraintType.PrimaryKey);
     var errors = ValidationHelper.CollectErrors(expression);
     errors.ShouldContain("Table name cannot be empty");
 }
Ejemplo n.º 26
0
 public static CreateConstraintExpression GetCreateNamedPrimaryKeyExpression()
 {
     var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
     expression.Constraint.TableName = TestTableName1;
     expression.Constraint.Columns.Add(TestColumnName1);
     expression.Constraint.ConstraintName = "TESTPRIMARYKEY";
     return expression;
 }
Ejemplo n.º 27
0
 public override string Generate(CreateConstraintExpression expression)
 {
     return string.Format("ALTER TABLE {0}.{1}", Quoter.QuoteSchemaName(expression.Constraint.SchemaName), base.Generate(expression));
 }
        public void CanCreateUniqueConstraintWithSchema()
        {
            var expression = new CreateConstraintExpression(ConstraintType.Unique);
            expression.Constraint.TableName = "ConstraintTable";
            expression.Constraint.SchemaName = "Schema";
            expression.Constraint.ConstraintName = "Constraint";
            expression.Constraint.Columns.Add("column1");

            string sql = generator.Generate(expression);
            sql.ShouldBe("ALTER TABLE \"Schema\".\"ConstraintTable\" ADD CONSTRAINT \"Constraint\" UNIQUE (\"column1\")");
        }
Ejemplo n.º 29
0
 public override string Generate(CreateConstraintExpression expression)
 {
     truncator.Truncate(expression);
     return base.Generate(expression);
 }
Ejemplo n.º 30
0
 public abstract string Generate(CreateConstraintExpression expression);