CreateUniqueConstraint() public static method

public static CreateUniqueConstraint ( ) : DataTable
return DataTable
        public void RemoveAt_Integer()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints.RemoveAt(0);
            Assert.Equal(0, dt.Constraints.Count);

            dt = DataProvider.CreateUniqueConstraint();
            Constraint con = new UniqueConstraint(dt.Columns["String1"], false);

            dt.Constraints[0].ConstraintName = "constraint1";
            con.ConstraintName = "constraint2";
            dt.Constraints.Add(con);
            dt.Constraints.RemoveAt(0);
            Assert.Equal(1, dt.Constraints.Count);
            Assert.Equal("constraint2", dt.Constraints[0].ConstraintName);

            dt = DataProvider.CreateUniqueConstraint();
            dt.Constraints.CollectionChanged += new CollectionChangeEventHandler(Constraints_CollectionChanged);
            dt.Constraints.RemoveAt(0);
            Assert.Equal(true, _collectionChanged);

            ArrayList arr = new ArrayList(1);

            arr.Add(new IndexOutOfRangeException());
            TestException(new testExceptionMethodCallback(RemoveAt_I), arr);
        }
        public void Remove()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints.Remove(dt.Constraints[0]);
            Assert.Equal(0, dt.Constraints.Count);
        }
        public void Remove_ByNameSimple()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints[0].ConstraintName = "constraint1";
            dt.Constraints.Remove("constraint1");
            Assert.Equal(0, dt.Constraints.Count);
        }
        public void CollectionChanged()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            _collectionChangedFlag            = false;
            dt.Constraints.CollectionChanged += new CollectionChangeEventHandler(Constraints_CollectionChangedHandler);
            dt = DataProvider.CreateUniqueConstraint(dt);
            Assert.True(_collectionChangedFlag);
        }
        public void Remove_ByNameCollectionChangedEvent()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            _collectionChangedFlag            = false;
            dt.Constraints.CollectionChanged += new CollectionChangeEventHandler(Constraints_CollectionChangedHandler);
            dt.Constraints.Remove("constraint1");
            Assert.True(_collectionChangedFlag);
        }
        public void TestCanRemove_ByDataColumn()
        {
            DataTable  dt       = DataProvider.CreateUniqueConstraint();
            DataColumn dummyCol = new DataColumn();

            Assert.Equal(false, dt.Columns.CanRemove(null));
            Assert.Equal(false, dt.Columns.CanRemove(dummyCol));
            Assert.Equal(false, dt.Columns.CanRemove(dt.Columns[0]));
            Assert.Equal(true, dt.Columns.CanRemove(dt.Columns[1]));
        }
        public void CopyTo()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints.Add("constraint2", dt.Columns["String1"], true);

            var ar = new object[2];

            dt.Constraints.CopyTo(ar, 0);
            Assert.Equal(2, ar.Length);
        }
        public void Clear_Unique()
        {
            DataTable dt        = DataProvider.CreateUniqueConstraint();
            int       rowsCount = dt.Rows.Count;

            dt.Constraints.Clear();
            DataRow dr = dt.NewRow();

            dr[0] = 1;
            dt.Rows.Add(dr);
            Assert.Equal(rowsCount + 1, dt.Rows.Count); // verifying no exception as well
        }
        public void Item()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints[0].ConstraintName = "constraint1";
            Assert.Equal("constraint1", dt.Constraints[0].ConstraintName);
            Assert.Equal("constraint1", dt.Constraints["constraint1"].ConstraintName);

            ArrayList arr = new ArrayList(1);

            arr.Add(new IndexOutOfRangeException());
            TestException(new testExceptionMethodCallback(Item2), arr);
        }
        public void Remove_ByNameWithAdd()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints[0].ConstraintName = "constraint1";
            Constraint con = new UniqueConstraint(dt.Columns["String1"], false);

            dt.Constraints.Add(con);
            dt.Constraints.Remove(con);

            Assert.Equal(1, dt.Constraints.Count);
            Assert.Equal("constraint1", dt.Constraints[0].ConstraintName);
        }
        public void GetEnumerator()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints.Add("constraint2", dt.Columns["String1"], false);

            int         counter      = 0;
            IEnumerator myEnumerator = dt.Constraints.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                counter++;
            }
            Assert.Equal(2, counter);
        }
        public void Count()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            Assert.Equal(1, dt.Constraints.Count);

            //Add

            dt.Constraints.Add("constraint2", dt.Columns["String1"], false);
            Assert.Equal(2, dt.Constraints.Count);

            //Remove

            dt.Constraints.Remove("constraint2");
            Assert.Equal(1, dt.Constraints.Count);
        }
        public void IndexOf()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            Assert.Equal(0, dt.Constraints.IndexOf(dt.Constraints[0]));

            //Add new constraint
            Constraint con = new UniqueConstraint(dt.Columns["String1"], false);

            dt.Constraints.Add(con);
            Assert.Equal(1, dt.Constraints.IndexOf(con));

            //Remove it and try to look for it

            dt.Constraints.Remove(con);
            Assert.Equal(-1, dt.Constraints.IndexOf(con));
        }
        public void GetEnumerator()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            int         counter      = 0;
            IEnumerator myEnumerator = dt.Columns.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                counter++;
            }
            Assert.Equal(6, counter);

            Assert.Throws <InvalidOperationException>(() =>
            {
                DataColumn col = (DataColumn)myEnumerator.Current;
            });
        }
        public void Add_Constraint()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            Assert.Equal(1, dt.Constraints.Count);
            Assert.Equal("Constraint1", dt.Constraints[0].ConstraintName);

            DataSet ds = DataProvider.CreateForeignConstraint();

            Assert.Equal(1, ds.Tables[1].Constraints.Count);
            Assert.Equal(1, ds.Tables[0].Constraints.Count);

            var arr = new ArrayList(1);

            arr.Add(new ConstraintException());
            TestException(new testExceptionMethodCallback(DataProvider.TryToBreakUniqueConstraint), arr);

            arr = new ArrayList(1);
            arr.Add(new InvalidConstraintException());
            TestException(new testExceptionMethodCallback(DataProvider.TryToBreakForigenConstraint), arr);
        }
        private void RemoveAt_I()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints.RemoveAt(2);
        }
        public void IsReadOnly()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            Assert.False(dt.Constraints.IsReadOnly);
        }
        private void Item2()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            dt.Constraints[1].ConstraintName = "error";
        }
        public void IsSynchronized()
        {
            DataTable dt = DataProvider.CreateUniqueConstraint();

            Assert.False(dt.Constraints.IsSynchronized);
        }