Beispiel #1
0
        public void ClearAsync()
        {
            var sharedSource = new SharedSource <MySharedItem>();

            Assert.AreEqual(0, sharedSource.Items.Count);
            Assert.AreEqual(-1, sharedSource.SelectedIndex);

            var item1 = sharedSource.AddNew("A");
            var item2 = sharedSource.AddNew("B");
            var item3 = sharedSource.AddNew("C");

            Assert.AreEqual(3, sharedSource.Items.Count);
            Assert.AreEqual(item1, sharedSource.Items.ElementAt(0));
            Assert.AreEqual(item2, sharedSource.Items.ElementAt(1));
            Assert.AreEqual(item3, sharedSource.Items.ElementAt(2));
            Assert.AreEqual(2, sharedSource.SelectedIndex);
            Assert.AreEqual(item3, sharedSource.SelectedItem);

            //  C => B => A
            var selections = new Dictionary <int, object>();

            sharedSource.SelectedItemChanged += (s, e) =>
            {
                //  1 B... 0 A
                selections.Add(e.SelectedIndex, e.SelectedItem);
            };

            sharedSource.Clear();
            Assert.AreEqual(true, item1.IsCanDeactivateInvoked);
            Assert.AreEqual(true, item1.IsOnNavigatingFromInvoked);
            Assert.AreEqual(true, item2.IsCanDeactivateInvoked);
            Assert.AreEqual(true, item2.IsOnNavigatingFromInvoked);
            Assert.AreEqual(true, item3.IsCanDeactivateInvoked);
            Assert.AreEqual(true, item3.IsOnNavigatingFromInvoked);
            Assert.AreEqual(0, sharedSource.Items.Count);
            Assert.AreEqual(-1, sharedSource.SelectedIndex);
            Assert.AreEqual(null, sharedSource.SelectedItem);
            //   item3 removed(old index 2) ... select item2(index 1)
            Assert.AreEqual(1, selections.ElementAt(0).Key);
            Assert.AreEqual(item2, selections.ElementAt(0).Value);
            // item1 removed change index, select item1(index 0)
            Assert.AreEqual(0, selections.ElementAt(1).Key);
            Assert.AreEqual(item1, selections.ElementAt(1).Value);
            // empty items
            Assert.AreEqual(-1, selections.ElementAt(2).Key);
            Assert.AreEqual(null, selections.ElementAt(2).Value);
            Assert.AreEqual(3, selections.Count);
        }
Beispiel #2
0
        public void ClearAsync_With_One_Item_CannotDeactivate()
        {
            var sharedSource = new SharedSource <MySharedItem>();

            Assert.AreEqual(0, sharedSource.Items.Count);
            Assert.AreEqual(-1, sharedSource.SelectedIndex);

            var item1 = sharedSource.AddNew("A");
            var item2 = sharedSource.AddNew("B");
            var item3 = sharedSource.AddNew("C");

            Assert.AreEqual(3, sharedSource.Items.Count);
            Assert.AreEqual(item1, sharedSource.Items.ElementAt(0));
            Assert.AreEqual(item2, sharedSource.Items.ElementAt(1));
            Assert.AreEqual(item3, sharedSource.Items.ElementAt(2));
            Assert.AreEqual(2, sharedSource.SelectedIndex);
            Assert.AreEqual(item3, sharedSource.SelectedItem);

            //  C => B X => A
            var selections = new Dictionary <int, object>();

            sharedSource.SelectedItemChanged += (s, e) =>
            {
                //  1 B... 0 B
                selections.Add(e.SelectedIndex, e.SelectedItem);
            };

            item2.CDeactivate = false;

            sharedSource.Clear();
            Assert.AreEqual(true, item1.IsCanDeactivateInvoked);
            Assert.AreEqual(true, item1.IsOnNavigatingFromInvoked);
            Assert.AreEqual(true, item2.IsCanDeactivateInvoked);
            Assert.AreEqual(false, item2.IsOnNavigatingFromInvoked);
            Assert.AreEqual(true, item3.IsCanDeactivateInvoked);
            Assert.AreEqual(true, item3.IsOnNavigatingFromInvoked);
            Assert.AreEqual(1, sharedSource.Items.Count);
            Assert.AreEqual(0, sharedSource.SelectedIndex);
            Assert.AreEqual(item2, sharedSource.SelectedItem);
            // item3 removed(old index 2) ... select item2(index 1 B)
            Assert.AreEqual(1, selections.ElementAt(0).Key);
            Assert.AreEqual(item2, selections.ElementAt(0).Value);
            // item1 removed change index, same seleected item item2
            Assert.AreEqual(0, selections.ElementAt(1).Key);
            Assert.AreEqual(item2, selections.ElementAt(1).Value);
            Assert.AreEqual(2, selections.Count);
        }