public void WhenAddingPropertyChangedHandler_ThenNotifiesSubscriber()
        {
            var notified = false;
            var foo      = new Foo();
            var manager  = new PropertyChangeManager(foo);
            PropertyChangedEventHandler handler = (sender, args) => notified = true;

            manager.AddHandler(handler);

            manager.NotifyChanged <Foo>(x => x.Name);

            Assert.True(notified);
        }
        public void WhenAddingPropertyChangedHandler_ThenNotifiesSubscriber()
        {
            var notified = false;
            var foo = new Foo();
            var manager = new PropertyChangeManager(foo);
            PropertyChangedEventHandler handler = (sender, args) => notified = true;

            manager.AddHandler(handler);

            manager.NotifyChanged<Foo>(x => x.Name);

            Assert.True(notified);
        }
        public void WhenRemovingPropertyChangedHandler_ThenDoesNotNotifySubscriberAnymore()
        {
            var notified = false;
            var foo      = new Foo();
            var manager  = new PropertyChangeManager(foo);
            PropertyChangedEventHandler handler = (sender, args) => notified = true;

            manager.AddHandler(handler);
            manager.RemoveHandler(handler);

            manager.NotifyChanged <Foo>(x => x.Name);

            Assert.False(notified);
        }
        public void WhenAddedPropertyChangedHandlerTargetIsNotAlive_ThenDoesNotNotify()
        {
            var foo        = new Foo();
            var manager    = new PropertyChangeManager(foo);
            var subscriber = new TestSubscriber("Name", 1);

            manager.AddHandler(subscriber.PropertyChangedHandler);
            manager.NotifyChanged <Foo>(x => x.Name);

            Assert.Equal(1, subscriber.ActualCalls);

            subscriber = null;
            GC.Collect();

            manager.NotifyChanged <Foo>(x => x.Name);
        }
        public void WhenAddedPropertyChangedHandlerTargetIsNotAlive_ThenDoesNotNotify()
        {
            var foo = new Foo();
            var manager = new PropertyChangeManager(foo);
            var subscriber = new TestSubscriber("Name", 1);

            manager.AddHandler(subscriber.PropertyChangedHandler);
            manager.NotifyChanged<Foo>(x => x.Name);

            Assert.Equal(1, subscriber.ActualCalls);

            subscriber = null;
            GC.Collect();

            manager.NotifyChanged<Foo>(x => x.Name);
        }
        public void WhenRemovingPropertyChangedHandler_ThenDoesNotNotifySubscriberAnymore()
        {
            var notified = false;
            var foo = new Foo();
            var manager = new PropertyChangeManager(foo);
            PropertyChangedEventHandler handler = (sender, args) => notified = true;

            manager.AddHandler(handler);
            manager.RemoveHandler(handler);

            manager.NotifyChanged<Foo>(x => x.Name);

            Assert.False(notified);
        }