public void SlowDownBecauseOfPropertyChangeEventsShouldBeSmall()
        {
            var parentObject = new ParentObject();
            var strings = new string[1000000]; // pre-cache strings to have less timing variance

            for (var i = 0; i < 1000000; i++)
            {
                parentObject.Children.Add(new ChildObject());
                strings[i] = i.ToString();
            }

            // without property changed
            var children = parentObject.Children;
            var t = DateTime.Now;
            for (int i = 0; i < 10; i++)
            {
                ChangeChildrenWithoutEvents(children, strings);
            }
            var dtWithoutPropertyChanged = (DateTime.Now - t).TotalMilliseconds;

            // with property changed
            t = DateTime.Now;
            for (int i = 0; i < 10; i++)
            {
                ChangeChildrenWithEvents(children, strings);
            }
            var dtWithPropertyChanged = (DateTime.Now - t).TotalMilliseconds;

            log.InfoFormat("1000 changes without NotifyPropertyChanged: {0} milliseconds", dtWithoutPropertyChanged);
            log.InfoFormat("1000 changes with NotifyPropertyChanged: {0} milliseconds", dtWithPropertyChanged);

            var percentsSlower = (dtWithPropertyChanged / dtWithoutPropertyChanged - 1.0) * 100;

            log.InfoFormat("{0:0.000000}% slower", percentsSlower);

            Assert.LessOrEqual(percentsSlower, 600); // it is still buggy, measured time variaes a lot
        }
        public void EventBubblingChildObjectInAList()
        {
            //same situation but now with a child in a list
            ParentObject parent = new ParentObject();
            int changeCount = 0;

            //add the child in a list
            ChildObject child = new ChildObject();
            parent.Children.Add(child);

            Post.Cast<ParentObject, INotifyPropertyChanged>(parent).PropertyChanged +=
                delegate(object sender, PropertyChangedEventArgs e)
                    {
                        Assert.AreEqual("Name", e.PropertyName);
                        changeCount++;
                    };
            child.Name = "newName";
            Assert.AreEqual(1, changeCount);
        }
        public void SkipNotificationForSelectedProperty()
        {
            ParentObject parentObject = new ParentObject();

            ChildObject childObject = new ChildObject();
            parentObject.Child = childObject;

            int changeCount = 0;
            Post.Cast<ParentObject, INotifyPropertyChanged>(parentObject).PropertyChanged +=
                delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
                    {
                        Assert.AreEqual("Name", e.PropertyName);
                        changeCount++;
                    };

            childObject.Parent = parentObject;
            Assert.AreEqual(0, changeCount);

            childObject.Name = "newName";
            Assert.AreEqual(1, changeCount);
        }
        public void EventBubblingChildObject()
        {
            ParentObject parent = new ParentObject();
            int changeCount = 0;
            ChildObject child = new ChildObject();
            parent.Child = child;

            Post.Cast<ParentObject, INotifyPropertyChanged>(parent).PropertyChanged +=
                delegate(object sender, PropertyChangedEventArgs e)
                    {
                        Assert.AreEqual("Name", e.PropertyName);
                        changeCount++;
                    };
            child.Name = "newName";
            Assert.AreEqual(1, changeCount);
        }