Пример #1
0
        public void RemoveAtIBindingList()
        {
            ViewFactory factory = ViewFactory.IBindingListSimpleItems();

            factory.List.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            SimpleClass bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12));

            factory.List.Add(bbb);
            factory.List.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            factory.ClearEventCounts();

            int removingIndex = -1;

            factory.View.RemovingItem += delegate(object sender, RemovingItemEventArgs args)
            {
                removingIndex = args.Index;
            };

            factory.View.RemoveAt(0);

            Assert.AreEqual(2, factory.List.Count);
            Assert.AreEqual("bbb", ((SimpleClass)factory.List[0]).StringValue);
            Assert.AreEqual(1, factory.ListChangedDeletedCount);
            Assert.AreEqual(1, factory.RemovingItemCount);
            Assert.AreEqual(0, removingIndex);
        }
Пример #2
0
        public void Add()
        {
            ViewFactory factory = ViewFactory.IListSimpleItems();

            IList          list = factory.List;
            ObjectListView view = factory.View;

            list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            list.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)));
            list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            factory.ClearEventCounts();

            Assert.AreEqual(3, view.Add(new SimpleClass(200, "ddd", new DateTime(1963, 3, 9))));
            Assert.AreEqual(4, list.Count);
            Assert.AreEqual(1, factory.ListChangedAddedCount);
            Assert.AreEqual(0, factory.ListChangedItemChangedCount);

            object item = list[3];

            Assert.IsTrue(item is SimpleClass);
            Assert.AreEqual(200, ((SimpleClass)item).IntegerValue);
            Assert.AreEqual("ddd", ((SimpleClass)item).StringValue);
            Assert.AreEqual(new DateTime(1963, 3, 9), ((SimpleClass)item).DateTimeValue);
        }
Пример #3
0
        public void ClearIBindingList()
        {
            ViewFactory factory = ViewFactory.IBindingListSimpleItems();

            object item = factory.CreateItem();

            factory.List.Add(item);
            factory.ClearEventCounts();

            factory.View.Clear();
            Assert.AreEqual(1, factory.ListChangedResetCount);
            Assert.AreEqual(0, factory.List.Count);
        }
Пример #4
0
        public void Clear()
        {
            ViewFactory factory = ViewFactory.IListSimpleItems();

            IList          list = factory.List;
            ObjectListView view = factory.View;

            list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            list.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)));
            list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            factory.ClearEventCounts();

            view.Clear();

            Assert.AreEqual(1, factory.ListChangedResetCount);
            Assert.AreEqual(0, list.Count);
        }
Пример #5
0
        public void RemoveNotInList()
        {
            ViewFactory factory = ViewFactory.IListSimpleItems();

            IList          list = factory.List;
            ObjectListView view = factory.View;

            list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            list.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)));
            list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            factory.ClearEventCounts();

            SimpleClass ddd = new SimpleClass(66, "ddd", new DateTime(1980, 12, 12));

            view.Remove(ddd);

            Assert.AreEqual(0, factory.ListChangedDeletedCount);
            Assert.AreEqual(0, factory.RemovingItemCount);
        }
Пример #6
0
        public void ItemSetIBindingList()
        {
            ViewFactory factory = ViewFactory.IBindingListSimpleItems();

            factory.List.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            factory.List.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)));
            factory.List.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            factory.ClearEventCounts();

            factory.View[1] = new SimpleClass(200, "ddd", new DateTime(1963, 3, 9));

            Assert.AreEqual(1, factory.ListChangedItemChangedCount);

            object item = factory.List[1];

            Assert.IsTrue(item is SimpleClass);
            Assert.AreEqual(200, ((SimpleClass)item).IntegerValue);
            Assert.AreEqual("ddd", ((SimpleClass)item).StringValue);
            Assert.AreEqual(new DateTime(1963, 3, 9), ((SimpleClass)item).DateTimeValue);
        }