Exemple #1
0
        public void EventHandler_event_handler_should_be_called_on_event()
        {
            // Arrange
            var view  = new SomeView();
            var model = new SomeModel();

            SubscribeWeakly.OnEventHandler(
                h => model.Updated += h,
                h => model.Updated -= h,
                view, (v, sender, e) => v.OnOtherDataChanged());

            // Act
            model.Update();

            // Assert
            view.Observer.IsOtherDataChangedHandled.Should().BeTrue();
        }
Exemple #2
0
        public void EventHandler_event_handler_should_not_be_called_when_subscriber_is_garbage_collected()
        {
            // Arrange
            var view  = new SomeView();
            var model = new SomeModel();

            SubscribeWeakly.OnEventHandler(
                h => model.Updated += h,
                h => model.Updated -= h,
                view, (v, sender, e) => v.OnOtherDataChanged());

            // Act
            var observer = view.Observer;

            // ReSharper disable RedundantAssignment
            view = null;
            // ReSharper restore RedundantAssignment
            GC.Collect();

            model.Update();

            // Assert
            observer.IsOtherDataChangedHandled.Should().BeFalse();
        }