Esempio n. 1
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 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)
            {
            }
        }