Пример #1
0
        public void FirePropertyChangedEvent_Always_CallsCallback()
        {
            EventListenerStub listener = new EventListenerStub();

            Person person = new Person();

            WeakEventHandler weakEventHandler = WeakPropertyChangedEventHandler.Register(
                person,
                (s, eh) => s.PropertyChanged -= eh,
                listener,
                (me, sender, ea) => me.OnPropertyChanged(sender, ea));

            person.Name = "Bob";

            Assert.AreEqual(1, listener.EventHandlerCallCount);
            Assert.AreEqual("Name", listener.LastPropertyChanged);
        }
        public void FirePropertyChangedEvent_Always_CallsCallback()
        {
            EventListenerStub listener = new EventListenerStub();

            Person person = new Person();

            WeakEventHandler weakEventHandler = WeakPropertyChangedEventHandler.Register(
                person,
                (s, eh) => s.PropertyChanged -= eh,
                listener,
                (me, sender, ea) => me.OnPropertyChanged(sender, ea));

            person.Name = "Bob";

            Assert.AreEqual(1, listener.EventHandlerCallCount);
            Assert.AreEqual("Name", listener.LastPropertyChanged);
        }
Пример #3
0
        public void Register_ListenerSetToNullAndGarbageCollected_ListenerSetToNull()
        {
            EventListenerStub listener    = new EventListenerStub();
            WeakReference     listenerRef = new WeakReference(listener);

            Person person = new Person();

            WeakEventHandler weakEventHandler = WeakPropertyChangedEventHandler.Register(
                person,
                (s, eh) => s.PropertyChanged -= eh,
                listener,
                (me, sender, ea) => me.OnPropertyChanged(sender, ea));

            listener = null;
            GC.Collect();

            Assert.IsFalse(listenerRef.IsAlive);
        }
        public void Register_ListenerSetToNullAndGarbageCollected_ListenerSetToNull()
        {
            EventListenerStub listener = new EventListenerStub();
            WeakReference listenerRef = new WeakReference(listener);

            Person person = new Person();

            WeakEventHandler weakEventHandler = WeakPropertyChangedEventHandler.Register(
                person,
                (s, eh) => s.PropertyChanged -= eh,
                listener,
                (me, sender, ea) => me.OnPropertyChanged(sender, ea));

            listener = null;
            GC.Collect();

            Assert.IsFalse(listenerRef.IsAlive);
        }