public void GetConstraint()
        {
            TableDefinition table = new TableDefinition("Foo");
            IConstraintDefinition constraint = new DefaultConstraintDefinition("DF_Bar");

            table.AddConstraint(constraint);

            Assert.AreSame(constraint, table.GetConstraint("df_bar"));
            Assert.AreSame(constraint, table.GetConstraint("Df_BaR"));
            Assert.IsNull(table.GetConstraint("XX_Bar"));
        }
        public void RemoveConstraint()
        {
            TableDefinition table = new TableDefinition("Foo");
            IConstraintDefinition constraint = new DefaultConstraintDefinition("DF_Bar");

            table.AddConstraint(constraint);

            table.RemoveConstraint("XX_Bar");
            Assert.AreEqual(1, table.Constraints.Count);

            table.RemoveConstraint("df_Bar");
            Assert.AreEqual(0, table.Constraints.Count);
        }
        /// <summary>
        /// Visits the given <paramref name="addConstraintNode"/>.
        /// </summary>
        /// <param name="addConstraintNode"></param>
        public override void Visit(IAddConstraintNode addConstraintNode)
        {
            //
            // If we have "table" property, use that as a value for "table" property
            if(addConstraintNode.Properties[MdlSyntax.Table] != null)
                addConstraintNode.Table = AstNodePropertyUtil.AsString(addConstraintNode.Properties, MdlSyntax.Table);
            else
            {
                //
                // If we have IAddColumnNode or IAlterColumnNode as a parent, use its table name
                // plus use that column as a target for the constraint
                if(addConstraintNode.Parent is IAddColumnNode || addConstraintNode.Parent is IAlterColumnNode)
                {
                    IColumnNode columnNode = ((IColumnNode)addConstraintNode.Parent);
                    
                    addConstraintNode.Table = columnNode.Table;
                    addConstraintNode.Columns.Add(columnNode.Name);
                } // if

                //
                // If parent is IAddTableNode or IAlterTableNode, use its name
                if(addConstraintNode.Parent is IAddTableNode || addConstraintNode.Parent is IAlterTableNode)
                    addConstraintNode.Table = ((ITableNode)addConstraintNode.Parent).Name;

                addConstraintNode.Properties.AddProperty(new AstNodeProperty(MdlSyntax.Table, 
                    new StringAstNodePropertyValue(addConstraintNode.Table)));
            } // else

            //
            // If we have "default" property, this is is IDefaultConstraintDefinition
            IConstraintDefinition constraintDefinition = null;
            if(addConstraintNode.Properties[MdlSyntax.Default] != null)
            {
                IAstNodePropertyValue value = addConstraintNode.Properties[MdlSyntax.Default].Value;
                constraintDefinition =
                    new DefaultConstraintDefinition(addConstraintNode.Name,
                        addConstraintNode.Table,
                        value is IIntegerAstNodePropertyValue ?
                            AstNodePropertyUtil.AsInteger(value).ToString() :
                            AstNodePropertyUtil.AsString(value));
                Environment.Schema.GetTable(constraintDefinition.Table).AddConstraint(constraintDefinition);
            } // if

            if(addConstraintNode.Columns.Count > 0)
                constraintDefinition.Columns.Add(addConstraintNode.Columns[0]);

            //
            // Look for "columns" or "column" properties
            if(addConstraintNode.Properties[MdlSyntax.Column] != null)
            {
                string columnName = AstNodePropertyUtil.AsString(
                    addConstraintNode.Properties[MdlSyntax.Column].Value);
                
                addConstraintNode.Columns.Add(columnName);
                constraintDefinition.Columns.Add(columnName);
            } // if

            if(addConstraintNode.Properties[MdlSyntax.Columns] != null)
            {
                IListAstNodePropertyValue columns =
                    (IListAstNodePropertyValue)addConstraintNode.Properties[MdlSyntax.Columns].Value;
                foreach (IAstNodePropertyValue column in columns.Items)
                {
                    string columnName = AstNodePropertyUtil.AsString(column);
                    
                    addConstraintNode.Columns.Add(columnName);
                    constraintDefinition.Columns.Add(columnName);
                }
            } // if
        }