Exemple #1
0
        public void ClearsFilterOnEachItem()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           item;
            HierarchyTreeViewItem           childA;
            HierarchyTreeViewItem           childB;
            HierarchyTreeViewItem           childC;


            childA = Factory.CreateTreeViewItem(name: "A");
            childB = Factory.CreateTreeViewItem(name: "B");
            childC = Factory.CreateTreeViewItem(name: "C");
            item   = Factory.CreateTreeViewItem(name: "Root", children: new[] { childA, childB, childC });

            collection = new HierarchyTreeViewItemCollection(new[] { item });
            collection.Filter(new RegexTextFilter("B"));

            Assert.Equal(new[] { item }, collection);
            Assert.Equal(new[] { childB }, item.Children);

            collection.ClearFilter();

            Assert.Equal(new[] { item }, collection);
            Assert.Equal(new[] { childA, childB, childC }, item.Children);
        }
Exemple #2
0
        public void IncludesFilteredItems()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           root1;
            HierarchyTreeViewItem           root2;
            HierarchyTreeViewItem           child1;
            HierarchyTreeViewItem           child2;
            HierarchyTreeViewItem           grandchild1;
            HierarchyTreeViewItem           grandchild2;


            grandchild1 = Factory.CreateTreeViewItem(name: "x");
            grandchild2 = Factory.CreateTreeViewItem(name: "a");
            child1      = Factory.CreateTreeViewItem(name: "x", children: new[] { grandchild1 });
            child2      = Factory.CreateTreeViewItem(name: "x", children: new[] { grandchild2 });
            root1       = Factory.CreateTreeViewItem(name: "x", children: new[] { child1 });
            root2       = Factory.CreateTreeViewItem(name: "a", children: new[] { child2 });

            collection = new HierarchyTreeViewItemCollection(new[] { root1, root2 });

            collection.Filter(new RegexTextFilter("x"));

            Assert.Equal(
                new[] {
                root1,
                child1,
                grandchild1,
                root2,
                child2,
                grandchild2
            },
                collection.GetFullHierarchy()
                );
        }
Exemple #3
0
        public void UsesOriginalItemsWhenFilteringIfCollectionHasAlreadyBeenFiltered()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo");
            bar  = Factory.CreateTreeViewItem(name: "bar");
            meep = Factory.CreateTreeViewItem(name: "meep");

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("foo"));

            Assert.Equal(new[] { foo }, collection);

            collection.Filter(new RegexTextFilter("bar"));

            Assert.Equal(new[] { bar }, collection);
        }
Exemple #4
0
        public void DoesNotRaiseCollectionChangedEventWhenCollectionIsEmpty()
        {
            HierarchyTreeViewItemCollection collection;
            bool raised;


            raised = false;

            collection = new HierarchyTreeViewItemCollection(Enumerable.Empty <HierarchyTreeViewItem>());
            collection.CollectionChanged += (s, e) => raised = true;

            collection.Filter(new RegexTextFilter("foo"));

            Assert.False(raised);
        }
Exemple #5
0
        public void FiltersCollectionToOnlyContainItemsThatMatchFilterOrHaveChildrenThatMatchFilter()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo", children: new[] { Factory.CreateTreeViewItem(name: "x") });
            bar  = Factory.CreateTreeViewItem(name: "bar", children: new[] { Factory.CreateTreeViewItem(name: "y") });
            meep = Factory.CreateTreeViewItem(name: "meep", children: new[] { Factory.CreateTreeViewItem(name: "fff") });

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("f"));

            Assert.Equal(new[] { foo, meep }, collection);
        }
Exemple #6
0
        public void FiltersCollectionToOnlyContainItemsThatMatchFilterWhenItemshaveNoChildren()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo");
            bar  = Factory.CreateTreeViewItem(name: "bar");
            meep = Factory.CreateTreeViewItem(name: "meep");

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("foo"));

            Assert.Equal(new[] { foo }, collection);
        }
Exemple #7
0
        public void RaisesCollectionChangedEventWhenCollectionIsNotEmpty()
        {
            HierarchyTreeViewItemCollection collection;

            Assert.RaisedEvent <NotifyCollectionChangedEventArgs> e;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(name: "foo"),
                Factory.CreateTreeViewItem(name: "bar")
            });

            e = Assert.Raises <NotifyCollectionChangedEventArgs>(
                (x) => collection.CollectionChanged += new NotifyCollectionChangedEventHandler(x),
                (x) => collection.CollectionChanged -= new NotifyCollectionChangedEventHandler(x),
                () => collection.Filter(new RegexTextFilter("foo"))
                );

            Assert.Equal(NotifyCollectionChangedAction.Reset, e.Arguments.Action);
        }
Exemple #8
0
        public void ReturnsCountOfFilteredItems()
        {
            HierarchyTreeViewItemCollection collection;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(name: "foo"),
                Factory.CreateTreeViewItem(name: "bar")
            });

            Assert.Equal(2, collection.Count);

            collection.Filter(new RegexTextFilter("f"));

            Assert.Single(collection);

            collection.ClearFilter();

            Assert.Equal(2, collection.Count);
        }
Exemple #9
0
        public void DoesNotIncludeFilteredItems()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           root1;
            HierarchyTreeViewItem           root2;
            HierarchyTreeViewItem           root3;


            root1 = Factory.CreateTreeViewItem(name: "x");
            root2 = Factory.CreateTreeViewItem(name: "a");
            root3 = Factory.CreateTreeViewItem(name: "x");

            collection = new HierarchyTreeViewItemCollection(new[] { root1, root2, root3 });

            collection.Filter(new RegexTextFilter("x"));

            Assert.Equal(
                new[] { root1, root3 },
                collection
                );
        }
Exemple #10
0
        public void RestoresOriginalItems()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo");
            bar  = Factory.CreateTreeViewItem(name: "bar");
            meep = Factory.CreateTreeViewItem(name: "meep");

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("foo"));

            Assert.Equal(new[] { foo }, collection);

            collection.ClearFilter();

            Assert.Equal(new[] { foo, bar, meep }, collection);
        }