public void Action_event_handler_should_be_called_on_event() { // Arrange var view = new SomeView(); var model = new SomeModel(); SubscribeWeakly.OnGenericAction <SomeDataChangedEvent, SomeView>( h => model.SomeDataChanged += h, h => model.SomeDataChanged -= h, view, (v, e) => v.OnSomeDataChanged()); // Act model.NotifySomeDataChanged(new SomeDataChangedEvent()); // Assert view.Observer.IsSomeDataChangedHandled.Should().BeTrue(); }
public void Action_event_subscription_can_be_safely_disposed_multiple_times() { // Arrange var view = new SomeView(); var model = new SomeModel(); var subscription = SubscribeWeakly.OnGenericAction <SomeDataChangedEvent, SomeView>( h => model.SomeDataChanged += h, h => model.SomeDataChanged -= h, view, (x, e) => { }); // Act subscription.Dispose(); subscription.Dispose(); // Assert // No exception should be raised }
public void Action_event_handler_should_not_be_called_when_subscription_is_disposed() { // Arrange var view = new SomeView(); var model = new SomeModel(); var subscription = SubscribeWeakly.OnGenericAction <SomeDataChangedEvent, SomeView>( h => model.SomeDataChanged += h, h => model.SomeDataChanged -= h, view, (x, e) => x.OnSomeDataChanged()); // Act subscription.Dispose(); model.NotifySomeDataChanged(new SomeDataChangedEvent()); // Assert view.Observer.IsSomeDataChangedHandled.Should().BeFalse(); }
public void Action_event_handler_should_not_be_called_when_GC_collected_and_subscriber_is_not_used_aftrewards() { // Arrange var view = new SomeView(); var model = new SomeModel(); SubscribeWeakly.OnGenericAction <SomeDataChangedEvent, SomeView>( h => model.SomeDataChanged += h, h => model.SomeDataChanged -= h, view, (v, e) => v.OnSomeDataChanged()); // Act var observer = view.Observer; // ReSharper disable RedundantAssignment view = null; // ReSharper restore RedundantAssignment GC.Collect(); model.NotifySomeDataChanged(new SomeDataChangedEvent()); // Assert observer.IsSomeDataChangedHandled.Should().BeFalse(); }