public void EventHandlerShouldBeWeak()
        {
            bool eventReceived = false;
            var  listener      = new PropertyChangedListener();

            WeakEventHandler <PropertyChangedEventHandler, PropertyChangedEventArgs> .Register(
                this,
                listener,
                handler => new PropertyChangedEventHandler(handler),
                (s, h) => s.PropertyChanged += h,
                (s, h) => s.PropertyChanged -= h,
                (l, s, e) => { l.OnEvent(s, e); eventReceived = true; });

            RaiseEvent();
            Assert.IsTrue(listener.EventReceived);
            Assert.IsTrue(eventReceived);

            listener.Reset();
            eventReceived = false;
            listener      = null;
            GC.Collect();

            RaiseEvent();
            Assert.IsFalse(eventReceived);
        }
        public void ShouldThrowIfRemoveHandlerIsNull()
        {
            var listener = new PropertyChangedListener();

            WeakEventHandler <PropertyChangedEventHandler, PropertyChangedEventArgs> .Register(
                this,
                listener,
                handler => new PropertyChangedEventHandler(handler),
                (s, h) => s.PropertyChanged += h,
                null,
                (l, s, e) => l.OnEvent(s, e));
        }
        public void ShouldThrowIfConversionNull()
        {
            var listener = new PropertyChangedListener();

            WeakEventHandler <PropertyChangedEventHandler, PropertyChangedEventArgs> .Register(
                this,
                listener,
                null,
                (s, h) => s.PropertyChanged += h,
                (s, h) => s.PropertyChanged -= h,
                (l, s, e) => l.OnEvent(s, e));
        }
        public void ShouldThrowIfSenderIsNull()
        {
            var listener = new PropertyChangedListener();

            WeakEventHandler <PropertyChangedEventHandler, PropertyChangedEventArgs> .Register <WeakEventHandlerCustomTest, PropertyChangedListener>(
                null,
                listener,
                handler => new PropertyChangedEventHandler(handler),
                (s, h) => s.PropertyChanged += h,
                (s, h) => s.PropertyChanged -= h,
                (l, s, e) => l.OnEvent(s, e));
        }
        public void ShouldThrowIfForwardEventIsNull()
        {
            var listener = new PropertyChangedListener();

            WeakEventHandler <PropertyChangedEventHandler, PropertyChangedEventArgs> .Register(
                this,
                listener,
                handler => new PropertyChangedEventHandler(handler),
                (s, h) => s.PropertyChanged += h,
                (s, h) => s.PropertyChanged -= h,
                null);
        }
        public void DetachEventHandler()
        {
            var listener     = new PropertyChangedListener();
            var subscription = WeakEventHandler <PropertyChangedEventHandler, PropertyChangedEventArgs> .Register(
                this,
                listener,
                handler => new PropertyChangedEventHandler(handler),
                (s, h) => s.PropertyChanged += h,
                (s, h) => s.PropertyChanged -= h,
                (l, s, e) => l.OnEvent(s, e));

            subscription.Dispose();
            RaiseEvent();
            Assert.IsFalse(listener.EventReceived);
        }
        public void HandleEvent()
        {
            var listener = new PropertyChangedListener();

            WeakEventHandler <PropertyChangedEventHandler, PropertyChangedEventArgs> .Register(
                this,
                listener,
                handler => new PropertyChangedEventHandler(handler),
                (s, h) => s.PropertyChanged += h,
                (s, h) => s.PropertyChanged -= h,
                (l, s, e) => l.OnEvent(s, e));

            RaiseEvent();
            Assert.IsTrue(listener.EventReceived);
        }
        public void DetachEventHandler()
        {
            var listener = new PropertyChangedListener();
              var subscription = WeakEventHandler<PropertyChangedEventHandler, PropertyChangedEventArgs>.Register(
            this,
            listener,
            handler => new PropertyChangedEventHandler(handler),
            (s, h) => s.PropertyChanged += h,
            (s, h) => s.PropertyChanged -= h,
            (l, s, e) => l.OnEvent(s, e));

              subscription.Dispose();
              RaiseEvent();
              Assert.IsFalse(listener.EventReceived);
        }
        public void EventHandlerShouldBeWeak()
        {
            bool eventReceived = false;
              var listener = new PropertyChangedListener();
              WeakEventHandler<PropertyChangedEventHandler, PropertyChangedEventArgs>.Register(
            this,
            listener,
            handler => new PropertyChangedEventHandler(handler),
            (s, h) => s.PropertyChanged += h,
            (s, h) => s.PropertyChanged -= h,
            (l, s, e) => { l.OnEvent(s, e); eventReceived = true; });

              RaiseEvent();
              Assert.IsTrue(listener.EventReceived);
              Assert.IsTrue(eventReceived);

              listener.Reset();
              eventReceived = false;
              listener = null;
              GC.Collect();

              RaiseEvent();
              Assert.IsFalse(eventReceived);
        }
        public void HandleEvent()
        {
            var listener = new PropertyChangedListener();
              WeakEventHandler<PropertyChangedEventHandler, PropertyChangedEventArgs>.Register(
            this,
            listener,
            handler => new PropertyChangedEventHandler(handler),
            (s, h) => s.PropertyChanged += h,
            (s, h) => s.PropertyChanged -= h,
            (l, s, e) => l.OnEvent(s, e));

              RaiseEvent();
              Assert.IsTrue(listener.EventReceived);
        }
 public void ShouldThrowIfSenderIsNull()
 {
     var listener = new PropertyChangedListener();
       WeakEventHandler<PropertyChangedEventHandler, PropertyChangedEventArgs>.Register<WeakEventHandlerCustomTest, PropertyChangedListener>(
     null,
     listener,
     handler => new PropertyChangedEventHandler(handler),
     (s, h) => s.PropertyChanged += h,
     (s, h) => s.PropertyChanged -= h,
     (l, s, e) => l.OnEvent(s, e));
 }
 public void ShouldThrowIfRemoveHandlerIsNull()
 {
     var listener = new PropertyChangedListener();
       WeakEventHandler<PropertyChangedEventHandler, PropertyChangedEventArgs>.Register(
     this,
     listener,
     handler => new PropertyChangedEventHandler(handler),
     (s, h) => s.PropertyChanged += h,
     null,
     (l, s, e) => l.OnEvent(s, e));
 }
 public void ShouldThrowIfForwardEventIsNull()
 {
     var listener = new PropertyChangedListener();
       WeakEventHandler<PropertyChangedEventHandler, PropertyChangedEventArgs>.Register(
     this,
     listener,
     handler => new PropertyChangedEventHandler(handler),
     (s, h) => s.PropertyChanged += h,
     (s, h) => s.PropertyChanged -= h,
     null);
 }
 public void ShouldThrowIfConversionNull()
 {
     var listener = new PropertyChangedListener();
       WeakEventHandler<PropertyChangedEventHandler, PropertyChangedEventArgs>.Register(
     this,
     listener,
     null,
     (s, h) => s.PropertyChanged += h,
     (s, h) => s.PropertyChanged -= h,
     (l, s, e) => l.OnEvent(s, e));
 }