예제 #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));
        }
        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");
        }