public void ShouldFailAddingDuplicateProperty()
        {
            PropertyItemMock property = new PropertyItemMock("property");
            CategoryItem     category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(property);
            category.AddProperty(property);
        }
        public void ShouldRedirectFilterMatchToProperties()
        {
            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(new PropertyItemMock("property1"));
            category.AddProperty(new PropertyItemMock("property2"));

            Assert.IsTrue(category.MatchesPredicate(new PropertyFilterPredicate("property")));
            Assert.IsFalse(category.MatchesPredicate(new PropertyFilterPredicate("missing")));
        }
        public void ShouldOrderPropertiesUponAdding()
        {
            PropertyItem property1 = new PropertyItemMock("property1");
            PropertyItem property2 = new PropertyItemMock("property2");

            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(property2);
            category.AddProperty(property1);

            Assert.AreEqual <PropertyItem>(property1, category.Properties[0]);
            Assert.AreEqual <PropertyItem>(property2, category.Properties[1]);
        }
        public void ShouldRetreivePropertyByName()
        {
            PropertyItemMock property1 = new PropertyItemMock("property1");
            PropertyItemMock property2 = new PropertyItemMock("property2");

            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(property1);
            category.AddProperty(property2);

            Assert.AreEqual <PropertyItem>(property1, category["property1"]);
            Assert.AreEqual <PropertyItem>(property2, category["property2"]);
        }
        public void ShouldApplyHasVisiblePropertiesByAtLeastOneOccurrence()
        {
            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            Assert.IsFalse(category.HasVisibleProperties);

            category.AddProperty(new PropertyItemMock("property1")
            {
                IsBrowsable = true
            });
            Assert.IsTrue(category.HasVisibleProperties);

            category.AddProperty(new PropertyItemMock("property2"));
            Assert.IsTrue(category.HasVisibleProperties);
        }
        public void ShouldExpandOnAppliedFilterMatch()
        {
            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(new PropertyItemMock("property1")
            {
                IsBrowsable = true
            });
            category.AddProperty(new PropertyItemMock("property2")
            {
                IsBrowsable = true
            });
            category.IsExpanded = false;

            category.ApplyFilter(new PropertyFilter("property"));
            Assert.IsTrue(category.MatchesFilter);
            Assert.IsTrue(category.IsExpanded);
        }
        public void ShouldSortUponSettingNewComparer()
        {
            PropertyItem property1 = new PropertyItemMock("property1");
            PropertyItem property2 = new PropertyItemMock("property2");

            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(property2);
            category.AddProperty(property1);

            Assert.AreEqual <PropertyItem>(property1, category.Properties[0]);
            Assert.AreEqual <PropertyItem>(property2, category.Properties[1]);

            category.Comparer = new PropertyItemComparerMock();

            Assert.AreEqual <PropertyItem>(property2, category.Properties[0]);
            Assert.AreEqual <PropertyItem>(property1, category.Properties[1]);
        }
        public void ShouldNotifyFilterApplied()
        {
            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(new PropertyItemMock("property1")
            {
                IsBrowsable = true
            });
            category.AddProperty(new PropertyItemMock("property2")
            {
                IsBrowsable = true
            });

            bool filterApplied = false;

            category.FilterApplied += delegate { filterApplied = true; };
            category.ApplyFilter(new PropertyFilter("property"));

            Assert.IsTrue(filterApplied);
        }
        public void ShouldApplyFilterToPropertiesContained()
        {
            CategoryItem category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());

            category.AddProperty(new PropertyItemMock("property1")
            {
                IsBrowsable = true
            });
            category.AddProperty(new PropertyItemMock("property2")
            {
                IsBrowsable = true
            });

            category.ApplyFilter(new PropertyFilter("missing"));
            Assert.IsFalse(category.MatchesFilter);
            Assert.IsFalse(category.HasVisibleProperties);

            category.ApplyFilter(new PropertyFilter("property"));
            Assert.IsTrue(category.MatchesFilter);
            Assert.IsTrue(category.HasVisibleProperties);
        }
        public void ShouldListenToPropertyVisibilityChanges()
        {
            CategoryItem     category = new CategoryItem(new PropertyGrid(), new CategoryAttribute());
            PropertyItemMock property = new PropertyItemMock("property");

            category.AddProperty(property);
            Assert.IsFalse(category.HasVisibleProperties);

            property.IsBrowsable = true;
            Assert.IsTrue(category.HasVisibleProperties);

            property.IsBrowsable = false;
            Assert.IsFalse(category.HasVisibleProperties);
        }
        public void ShouldNotifyOnVisiblePropertiesChange()
        {
            CategoryItem category     = new CategoryItem(new PropertyGrid(), new CategoryAttribute());
            int          raisedNumber = 0;

            category.PropertyChanged += (sender, e) => { if (e.PropertyName == "HasVisibleProperties")
                                                         {
                                                             raisedNumber++;
                                                         }
            };

            category.AddProperty(new PropertyItemMock("property1"));
            category.AddProperty(new PropertyItemMock("property2")
            {
                IsBrowsable = true
            });
            category.AddProperty(new PropertyItemMock("property3")
            {
                IsBrowsable = true
            });

            Assert.AreEqual <int>(1, raisedNumber);
        }