예제 #1
0
        public void BusinessList_Contains_Empty_DataList()
        {
            var dl = new List <TestItemDM>();
            var bl = new ListBM <TestItemBM> {
                Metadata =
                {
//TODO:				LogicProvider=new CustomListLogicProvider(OnCollectionChanged,OnCollectionChanged),
                    DataProvider = { Data = dl }
                }
            };
            var di = (TestItemDM)null;
            var bi = (TestItemBM)null;

            Assert.AreEqual(false, bl.IsReadOnly);
            Assert.AreEqual(false, ((IList)bl).IsFixedSize);

            bl.CollectionChanged += OnCollectionChanged;

            ((IList)bl).Add(bi            = new TestItemBM());
            bi.Metadata.DataProvider.Data = di = new TestItemDM(0);
            Assert.AreEqual(1, ((IList)bl).Count);
            Assert.AreEqual(1, dl.Count);
            Assert.AreEqual(0, bl.IndexOf(bi));
            Assert.AreEqual(0, ((IList)bl).IndexOf(bi));
            Assert.AreEqual(true, ((IList)bl).Contains(bi));
            Assert.AreEqual(bi, bl[0]);
            Assert.AreEqual(bi, ((IList)bl)[0]);
            Assert.AreEqual(bl, bl[0].Parent);
            bl.Add(new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(1) } }
            });
            Assert.AreEqual(2, dl.Count);
            bl.Add(new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(2) } }
            });
            Assert.AreEqual(3, dl.Count);
            ((IList)bl).RemoveAt(1);
            Assert.AreEqual(2, dl.Count);
            ((IList)bl).Remove(bi);
            Assert.IsNull(bi.Parent);
            Assert.AreEqual(1, dl.Count);
            ((IList)bl).Clear();
            Assert.AreEqual(0, dl.Count);
            ((IList)bl).Insert(0, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(0) } }
            });
            bl.Insert(0, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(1) } }
            });
            Assert.AreEqual(bl, bl[0].Parent);
            bl.Insert(2, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(2) } }
            });
            Assert.AreEqual(3, dl.Count);

            foreach (var item in bl)
            {
                Assert.IsTrue(bl.Contains(item));
            }
            foreach (var item in (IEnumerable)bl)
            {
                Assert.IsTrue(bl.Contains(item));
            }

            bl.CopyTo(new TestItemBM[3], 0);
            bl[0] = new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(0) } }
            };
            ((IList)bl)[0] = TestItemBM.New();
//			bl.Move(0,2);

            bl.CollectionChanged += OnCollectionChanged;
            bl.Dispose();
        }