예제 #1
0
        public void TestComparerChangedEvent()
        {
            var root          = CreateTestTree();
            var oldComparer   = root.Comparer;
            var valueComparer = Comparer <ValueClass> .Create((v1, v2) =>
                                                              v1.GetHashCode().CompareTo(v2.GetHashCode()));

            var comparer = ObservableSortedTree <ValueClass> .TransformValueToTreeComparer(valueComparer);

            bool comparerChanged_raised = false;

            root.ComparerChanged += (sender, oldComp) =>
            {
                comparerChanged_raised = true;
                Assert.IsTrue(ReferenceEquals(root, sender));
                Assert.IsTrue(ReferenceEquals(oldComparer, oldComp));
            };
            root.Comparer = comparer;
            Assert.IsTrue(comparerChanged_raised);
        }
예제 #2
0
        public void TestComparersEqualAfterUpdate()
        {
            var root          = CreateTestTree();
            var oldComparer   = root.Comparer;
            var valueComparer = Comparer <ValueClass> .Create((v1, v2) =>
                                                              v1.GetHashCode().CompareTo(v2.GetHashCode()));

            var comparer = ObservableSortedTree <ValueClass> .TransformValueToTreeComparer(valueComparer);

            root.Comparer = comparer;
            foreach (var tree in root.AsEnumerable())
            {
                Assert.IsTrue(ReferenceEquals(tree.Comparer, comparer));
                Assert.IsTrue(ReferenceEquals(tree.Children.Comparer, comparer));
            }
            root.Comparer = oldComparer;
            foreach (var tree in root.AsEnumerable())
            {
                Assert.IsTrue(ReferenceEquals(tree.Comparer, oldComparer));
                Assert.IsTrue(ReferenceEquals(tree.Children.Comparer, oldComparer));
            }
        }