public void DetachEventHandler()
        {
            var listener = new Listener();
              var subscription = WeakEventHandler.Register(
            this,
            listener,
            (s, h) => s.Event += h,
            (s, h) => s.Event -= h,
            (l, s, e) => l.OnEvent(s, e));

              subscription.Dispose();
              RaiseEvent();
              Assert.IsFalse(listener.EventReceived);
        }
        public void EventHandlerShouldBeWeak()
        {
            bool eventReceived = false;
              var listener = new Listener();
              WeakEventHandler.Register(
            this,
            listener,
            (s, h) => s.Event += h,
            (s, h) => s.Event -= 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 Listener();
              WeakEventHandler.Register(
            this,
            listener,
            (s, h) => s.Event += h,
            (s, h) => s.Event -= h,
            (l, s, e) => l.OnEvent(s, e));

              RaiseEvent();
              Assert.IsTrue(listener.EventReceived);
        }
 public void ShouldThrowIfSenderIsNull()
 {
     var listener = new Listener();
       WeakEventHandler.Register<WeakEventHandlerTest, Listener>(
     null,
     listener,
     (s, h) => s.Event += h,
     (s, h) => s.Event -= h,
     (l, s, e) => l.OnEvent(s, e));
 }
 public void ShouldThrowIfRemoveHandlerIsNull()
 {
     var listener = new Listener();
       WeakEventHandler.Register(
     this,
     listener,
     (s, h) => s.Event += h,
     null,
     (l, s, e) => l.OnEvent(s, e));
 }
 public void ShouldThrowIfForwardEventIsNull()
 {
     var listener = new Listener();
       WeakEventHandler.Register(
     this,
     listener,
     (s, h) => s.Event += h,
     (s, h) => s.Event -= h,
     null);
 }