Beispiel #1
0
        public void TestUpdateItemsRemovesCorrectItems()
        {
            var source = new TestItemSource();
            var items  = new List <Item> ();

            items.Add(new Common.TextItem("bar"));
            items.Add(new Common.TextItem("baz"));

            List <Item> items_removed = null;

            source.ItemsAvailable   += delegate { };
            source.ItemsUnavailable += delegate(object sender, ItemsUnavailableEventArgs e) {
                items_removed = new List <Item> (e.unavailableItems);
            };

            // Add items to Universe...
            source.next_items = items;
            source.UpdateAndEmit();

            //...now remove them.
            source.next_items = new List <Item> ();
            source.UpdateAndEmit();

            CollectionAssert.AreEqual(items, items_removed);
        }
Beispiel #2
0
        public void TestMultipleUpdatesProduceCorrectItems()
        {
            var  source = new TestItemSource();
            var  items  = new List <Item> ();
            Item bar    = new Common.TextItem("bar");
            Item baz    = new Common.TextItem("baz");

            items.Add(bar);
            items.Add(baz);

            List <Item> items_removed = null;
            List <Item> items_added   = null;

            source.ItemsAvailable += delegate(object sender, ItemsAvailableEventArgs e) {
                items_added = new List <Item> (e.newItems);
            };
            source.ItemsUnavailable += delegate(object sender, ItemsUnavailableEventArgs e) {
                items_removed = new List <Item> (e.unavailableItems);
            };

            // Add items to Universe...
            source.next_items = items;
            source.UpdateAndEmit();

            CollectionAssert.AreEqual(items, items_added);
            Assert.AreEqual(null, items_removed);

            items_added   = null;
            items_removed = null;

            // Nothing added, nothing should change
            source.UpdateAndEmit();

            Assert.AreEqual(null, items_added);
            Assert.AreEqual(null, items_removed);

            //...now remove something...
            items.Remove(bar);

            source.next_items = items;
            source.UpdateAndEmit();

            Assert.AreEqual(null, items_added);
            CollectionAssert.AreEqual(new Item[] { bar }, items_removed);

            items_added   = null;
            items_removed = null;

            //...finally, add something back.
            items.Add(bar);

            source.next_items = items;
            source.UpdateAndEmit();

            CollectionAssert.AreEqual(new Item[] { bar }, items_added);
            Assert.AreEqual(null, items_removed);
        }
Beispiel #3
0
        public void TestUpdateItemsRaisesItemsUnavailable()
        {
            var source = new TestItemSource();

            bool itemsUnavailableCalled = false;

            source.ItemsUnavailable += delegate(object sender, ItemsUnavailableEventArgs e) {
                itemsUnavailableCalled = true;
            };
            source.ItemsAvailable += delegate {};

            source.next_items = new List <Item> ()
            {
                new Common.TextItem("bar")
            };

            source.UpdateAndEmit();

            source.next_items = new List <Item> ();

            source.UpdateAndEmit();
            Assert.IsTrue(itemsUnavailableCalled);
        }
Beispiel #4
0
        public void TestUpdateItemsAddsCorrectItems()
        {
            var source = new TestItemSource();
            var items  = new List <Item> ();

            items.Add(new Common.TextItem("bar"));
            items.Add(new Common.TextItem("baz"));

            List <Item> items_raised = null;

            source.ItemsAvailable += (object sender, ItemsAvailableEventArgs e) => {
                items_raised = new List <Item> (e.newItems);
            };
            source.ItemsUnavailable += delegate { };

            source.next_items = items;
            source.UpdateAndEmit();

            CollectionAssert.AreEqual(items, items_raised);
        }