Exemple #1
0
        public void RemoveAt()
        {
            DataRelationCollection drcol = _dataset.Relations;
            DataRelation           dr1   = new DataRelation("CustOrder"
                                                            , _dataset.Tables["Customer"].Columns["custid"]
                                                            , _dataset.Tables["Order"].Columns["custid"]);
            DataRelation dr2 = new DataRelation("ItemOrder"
                                                , _dataset.Tables["Item"].Columns["itemid"]
                                                , _dataset.Tables["Order"].Columns["custid"]);

            drcol.Add(dr1);
            drcol.Add(dr2);

            try
            {
                drcol.RemoveAt(-1);
                Assert.False(true);
            }
            catch (IndexOutOfRangeException e)
            {
            }
            try
            {
                drcol.RemoveAt(101);
                Assert.False(true);
            }
            catch (IndexOutOfRangeException e)
            {
            }

            drcol.RemoveAt(1);
            Assert.False(drcol.Contains(dr2.RelationName));
            drcol.RemoveAt(0);
            Assert.False(drcol.Contains(dr1.RelationName));
        }
Exemple #2
0
        public void Remove()
        {
            DataRelationCollection drcol = _dataset.Relations;
            DataRelation           dr1   = new DataRelation("CustOrder"
                                                            , _dataset.Tables["Customer"].Columns["custid"]
                                                            , _dataset.Tables["Order"].Columns["custid"]);
            DataRelation dr2 = new DataRelation("ItemOrder"
                                                , _dataset.Tables["Item"].Columns["itemid"]
                                                , _dataset.Tables["Order"].Columns["custid"]);

            drcol.Add(dr1);
            drcol.Add(dr2);

            drcol.Remove(dr1);
            Assert.False(drcol.Contains(dr1.RelationName));
            drcol.Add(dr1);

            drcol.Remove("CustOrder");
            Assert.False(drcol.Contains("CustOrder"));
            drcol.Add(dr1);

            DataRelation drnull = null;

            drcol.Remove(drnull);

            DataRelation newdr = new DataRelation("newdr"
                                                  , _dataset.Tables["Customer"].Columns["custid"]
                                                  , _dataset.Tables["Order"].Columns["custid"]);

            AssertExtensions.Throws <ArgumentException>(null, () => drcol.Remove(newdr));
        }
        public void RemoveAt()
        {
            DataRelationCollection drcol = _dataset.Relations;
            DataRelation           dr1   = new DataRelation("CustOrder"
                                                            , _dataset.Tables ["Customer"].Columns ["custid"]
                                                            , _dataset.Tables ["Order"].Columns ["custid"]);
            DataRelation dr2 = new DataRelation("ItemOrder"
                                                , _dataset.Tables ["Item"].Columns ["itemid"]
                                                , _dataset.Tables ["Order"].Columns ["custid"]);

            drcol.Add(dr1);
            drcol.Add(dr2);

            try {
                drcol.RemoveAt(-1);
                Assert.Fail("the index was out of bound: must have failed");
            } catch (IndexOutOfRangeException e) {
            }
            try {
                drcol.RemoveAt(101);
                Assert.Fail("the index was out of bound: must have failed");
            } catch (IndexOutOfRangeException e) {
            }

            drcol.RemoveAt(1);
            Assert.That(drcol.Contains(dr2.RelationName), Is.False, "test#5");
            drcol.RemoveAt(0);
            Assert.That(drcol.Contains(dr1.RelationName), Is.False, "test#6");
        }
Exemple #4
0
        public void Contains()
        {
            DataRelationCollection drcol     = _dataset.Relations;
            DataColumn             parentCol = _dataset.Tables["Customer"].Columns["custid"];
            DataColumn             childCol  = _dataset.Tables["Order"].Columns["custid"];
            DataRelation           dr        = new DataRelation("CustOrder", parentCol, childCol);

            drcol.Add(dr);
            Assert.True(drcol.Contains(dr.RelationName));
            string drnull = "";

            Assert.False(drcol.Contains(drnull));
            dr = new DataRelation("newRelation", childCol, parentCol);
            Assert.False(drcol.Contains("NoSuchRelation"));
        }
        public void Remove()
        {
            DataRelationCollection drcol = _dataset.Relations;
            DataRelation           dr1   = new DataRelation("CustOrder"
                                                            , _dataset.Tables["Customer"].Columns["custid"]
                                                            , _dataset.Tables["Order"].Columns["custid"]);
            DataRelation dr2 = new DataRelation("ItemOrder"
                                                , _dataset.Tables["Item"].Columns["itemid"]
                                                , _dataset.Tables["Order"].Columns["custid"]);

            drcol.Add(dr1);
            drcol.Add(dr2);

            drcol.Remove(dr1);
            AssertEquals("test#1", false, drcol.Contains(dr1.RelationName));
            drcol.Add(dr1);

            drcol.Remove("CustOrder");
            AssertEquals("test#2", false, drcol.Contains("CustOrder"));
            drcol.Add(dr1);

            DataRelation drnull = null;

            drcol.Remove(drnull);

            DataRelation newdr = new DataRelation("newdr"
                                                  , _dataset.Tables["Customer"].Columns["custid"]
                                                  , _dataset.Tables["Order"].Columns["custid"]);

            try
            {
                drcol.Remove(newdr);
                Fail("Err: removed relation which not part of collection");
            }
            catch (Exception e)
            {
                AssertEquals("test#4", typeof(ArgumentException), e.GetType());
            }
            try
            {
                drcol.Remove("newdr");
                Fail("Err: removed relation which not part of collection");
            }
            catch (ArgumentException e)
            {
            }
        }