コード例 #1
0
        public void GroupBy_ObservableKeyChangesEraseGroup_Update()
        {
            var update = false;

            ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >();
            var dummy1 = new Dummy <string>("A");
            var dummy2 = new ObservableDummy <string>("B");

            coll.Add(dummy1);
            coll.Add(dummy2);

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) =>
            {
                Assert.IsTrue(ContainsGroup(e.OldItems, "B"));
                update = true;
            };

            Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "A"), dummy1));
            Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "B"), dummy2));
            Assert.IsFalse(update);

            dummy2.Item = "A";

            Assert.IsTrue(update);
            Assert.AreEqual(1, test.Count());
            Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "A"), dummy2));
        }
コード例 #2
0
        public void GroupBy_NoObservableKeyChangesToNewGroup_NoUpdate()
        {
            var update = false;

            ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >();
            var dummy1 = new Dummy <string>("A");
            var dummy2 = new Dummy <string>("A");

            coll.Add(dummy1);
            coll.Add(dummy2);

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => update = true;

            var group = Sys.Single(test);

            Assert.IsTrue(Sys.Contains(group, dummy1));
            Assert.IsTrue(Sys.Contains(group, dummy2));
            Assert.IsFalse(update);

            dummy2.Item = "B";

            Assert.IsFalse(update);
        }
コード例 #3
0
        public void GroupBy_ObservableKeyChangesBetweenGroups_Update()
        {
            var updateGroups = false;
            var updateGroupA = false;
            var updateGroupB = false;

            ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >();
            var dummy1      = new Dummy <string>("A");
            var dummy2      = new Dummy <string>("B");
            var dummyChange = new ObservableDummy <string>("A");

            coll.Add(dummy1);
            coll.Add(dummy2);
            coll.Add(dummyChange);

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => updateGroups = true;

            var groupA = Sys.Single(test, g => g.Key == "A") as ObservableGroup <string, Dummy <string> >;
            var groupB = Sys.Single(test, g => g.Key == "B") as ObservableGroup <string, Dummy <string> >;

            Assert.IsNotNull(groupA);
            Assert.IsNotNull(groupB);
            Assert.IsTrue(Sys.Contains(groupA, dummy1));
            Assert.IsTrue(Sys.Contains(groupA, dummyChange));
            Assert.IsTrue(Sys.Contains(groupB, dummy2));
            Assert.IsFalse(updateGroups);

            var notifierA = groupA as INotifyCollectionChanged;
            var notifierB = groupB as INotifyCollectionChanged;

            Assert.IsNotNull(notifierA);
            Assert.IsNotNull(notifierB);

            notifierA.CollectionChanged += (o, e) =>
            {
                Assert.IsTrue(e.OldItems.Contains(dummyChange));
                updateGroupA = true;
            };
            notifierB.CollectionChanged += (o, e) =>
            {
                Assert.IsTrue(e.NewItems.Contains(dummyChange));
                updateGroupB = true;
            };
            dummyChange.Item = "B";

            Assert.IsFalse(updateGroups);
            Assert.IsTrue(updateGroupA);
            Assert.IsTrue(updateGroupB);

            Assert.IsTrue(Sys.Contains(groupA, dummy1));
            Assert.IsTrue(Sys.Contains(groupB, dummy2));
            Assert.IsTrue(Sys.Contains(groupB, dummyChange));
        }