Пример #1
0
        public void Add_DataColumn1()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();
            int     originalRelationsCount = ds.Relations.Count;

            DataRelation rel = new DataRelation("rel1", ds.Tables[0].Columns["ParentId"]
                                                , ds.Tables[1].Columns["ParentId"]);

            ds.Relations.Add(rel);

            Assert.Equal(originalRelationsCount + 1, ds.Relations.Count);

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

            Assert.Equal(typeof(UniqueConstraint), ds.Tables[0].Constraints[0].GetType());
            Assert.Equal(typeof(ForeignKeyConstraint), ds.Tables[1].Constraints[0].GetType());

            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                ds.Relations.Add(rel);
            });

            ds.Relations.Add(null);
        }
Пример #2
0
        public void TestCanRemove_ForigenConstraint()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            Assert.Equal(false, ds.Tables["child"].Columns.CanRemove(ds.Tables["child"].Columns["parentId"]));
            Assert.Equal(false, ds.Tables["parent"].Columns.CanRemove(ds.Tables["child"].Columns["parentId"]));
        }
Пример #3
0
        public void CanRemove_PartOfConstraint()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            Assert.False(ds.Tables.CanRemove(ds.Tables[0]));
            Assert.False(ds.Tables.CanRemove(ds.Tables[1]));
        }
Пример #4
0
        public void CanRemove_ParentAndChildForeign()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            //remove the forigen and ask about the unique
            ds.Tables["child"].Constraints.Remove(ds.Tables["child"].Constraints[0]);
            Assert.True(ds.Tables["parent"].Constraints.CanRemove(ds.Tables["parent"].Constraints[0]));
        }
Пример #5
0
        public void Clear2()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                ds.Tables[0].Columns.Clear();
            });
        }
        public void DataRowCollection_Clear2()
        {
            Assert.Throws <InvalidConstraintException>(() =>
            {
                DataSet ds = DataProvider.CreateForeignConstraint();

                ds.Tables[0].Rows.Clear(); //Try to clear the parent table
            });
        }
Пример #7
0
        public void Clear3()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            ds.Tables[1].Constraints.RemoveAt(0);
            ds.Tables[0].Constraints.RemoveAt(0);
            ds.Tables[0].Columns.Clear();
            ds.Tables[1].Columns.Clear();
            Assert.Equal(0, ds.Tables[0].Columns.Count);
            Assert.Equal(0, ds.Tables[1].Columns.Count);
        }
Пример #8
0
        public void Clear_Foreign()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            foreach (DataTable dt in ds.Tables)
            {
                dt.Constraints.Clear();
            }
            Assert.Equal(0, ds.Tables[0].Constraints.Count);
            Assert.Equal(0, ds.Tables[0].Constraints.Count);
        }
Пример #9
0
        public void Contains_ByName()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            //changing the constraints's name

            ds.Tables["child"].Constraints[0].ConstraintName  = "name1";
            ds.Tables["parent"].Constraints[0].ConstraintName = "name2";


            Assert.True(ds.Tables["child"].Constraints.Contains("name1"));
            Assert.False(ds.Tables["child"].Constraints.Contains("xxx"));
            Assert.True(ds.Tables["parent"].Constraints.Contains("name2"));
            Assert.False(ds.Tables["parent"].Constraints.Contains("xxx"));
        }
Пример #10
0
        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);
        }
Пример #11
0
        public void CanRemove_ChildForeign()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            Assert.True(ds.Tables["child"].Constraints.CanRemove(ds.Tables["child"].Constraints[0]));
        }
Пример #12
0
        public void CanRemove_ParentForeign()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            Assert.False(ds.Tables["parent"].Constraints.CanRemove(ds.Tables["parent"].Constraints[0]));
        }
Пример #13
0
        public void DataTableCollection_RemoveAt_I3()
        {
            DataSet ds = DataProvider.CreateForeignConstraint();

            AssertExtensions.Throws <ArgumentException>(null, () => ds.Tables.RemoveAt(0)); //Parent table
        }