public void WhenInstanceIsNull_ThenHandlerIsDetached() { WeakEventListenerFixture instance = null; var sender = new EventSource(); var invoked = false; var detached = false; var weakHandler = new WeakEventHandler <WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { invoked = true; }, handler => { sender.Event -= handler.OnEvent; detached = true; }); sender.Event += weakHandler.OnEvent; sender.FireEvent(new EventArgs()); Assert.IsFalse(invoked); Assert.IsTrue(detached); }
public void WhenDetached_ThenDoesNotInvokeCallbackOnEvent() { var instance = this; var sender = new EventSource(); var invoked = false; var weakHandler = new WeakEventHandler <WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { invoked = true; }, handler => { sender.Event -= handler.OnEvent; }); sender.Event += weakHandler.OnEvent; weakHandler.Detach(); sender.FireEvent(new EventArgs()); Assert.IsFalse(invoked); }
public void WhenDetachedWithNullDetachAction_ThenInvokesCallbackOnEvent() { var instance = this; var sender = new EventSource(); var invoked = false; var weakHandler = new WeakEventHandler <WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { invoked = true; }, null); sender.Event += weakHandler.OnEvent; weakHandler.Detach(); sender.FireEvent(new EventArgs()); Assert.IsTrue(invoked); }
public void WhenDetached_ThenDoesNotInvokeCallbackOnEvent() { var instance = this; var sender = new EventSource(); var invoked = false; var weakHandler = new WeakEventHandler<WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { invoked = true; }, handler => { sender.Event -= handler.OnEvent; }); sender.Event += weakHandler.OnEvent; weakHandler.Detach(); sender.FireEvent(new EventArgs()); Assert.IsFalse(invoked); }
public void WhenAttachedToAnEvent_ThenInvokesCallbackOnEvent() { var instance = this; var sender = new EventSource(); var args = new EventArgs(); var invoked = false; var weakHandler = new WeakEventHandler <WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { Assert.AreSame(this, i); Assert.AreSame(sender, s); Assert.AreSame(args, e); invoked = true; }, handler => { sender.Event -= handler.OnEvent; }); sender.Event += weakHandler.OnEvent; sender.FireEvent(args); Assert.IsTrue(invoked); }
public void WhenAttachedToAnEvent_ThenInvokesCallbackOnEvent() { var instance = this; var sender = new EventSource(); var args = new EventArgs(); var invoked = false; var weakHandler = new WeakEventHandler<WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { Assert.AreSame(this, i); Assert.AreSame(sender, s); Assert.AreSame(args, e); invoked = true; }, handler => { sender.Event -= handler.OnEvent; }); sender.Event += weakHandler.OnEvent; sender.FireEvent(args); Assert.IsTrue(invoked); }
public void WhenInstanceIsNull_ThenHandlerIsDetached() { WeakEventListenerFixture instance = null; var sender = new EventSource(); var invoked = false; var detached = false; var weakHandler = new WeakEventHandler<WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { invoked = true; }, handler => { sender.Event -= handler.OnEvent; detached = true; }); sender.Event += weakHandler.OnEvent; sender.FireEvent(new EventArgs()); Assert.IsFalse(invoked); Assert.IsTrue(detached); }
public void WhenDetachedWithNullDetachAction_ThenInvokesCallbackOnEvent() { var instance = this; var sender = new EventSource(); var invoked = false; var weakHandler = new WeakEventHandler<WeakEventListenerFixture, object, EventArgs>( instance, (i, s, e) => { invoked = true; }, null); sender.Event += weakHandler.OnEvent; weakHandler.Detach(); sender.FireEvent(new EventArgs()); Assert.IsTrue(invoked); }