コード例 #1
0
        public void TestSwap()
        {
            List <int>  list1, list2;
            AList <int> alist1 = this.NewList(10, out list1);
            AList <int> alist2 = this.NewList(100, out list2);

            // Can't Swap with a frozen list
            AList <int> frozen = alist1.Clone();

            frozen.Freeze();
            if (this._testExceptions)
            {
                AssertThrows <ReadOnlyException>(() => alist1.Swap(frozen));
            }

            // Swap, and ensure that ListChanging and NodeObserver are swapped.
            alist1.ListChanging += (sender, args) => Assert.Fail();
            alist1.AddObserver(new AListTestObserver <int, int>());
            alist1.Swap(alist2);
            Assert.AreEqual(0, alist1.ObserverCount);
            Assert.AreEqual(1, alist2.ObserverCount);

            list2.Add(999);
            alist1.Add(999);
            ExpectList(alist1, list2, false);
            ExpectList(alist2, list1, true);
        }