Example #1
0
        public void Delegate_event_handler_should_be_called_when_subscriber_not_GC_collected()
        {
            // Arrange
            var view  = new SomeView();
            var model = new SomeViewModel();

            SubscribeWeakly.OnCustomDelegate <PropertyChangedEventHandler, PropertyChangedEventArgs, SomeView>(
                a => a.Invoke,
                h => model.PropertyChanged += h,
                h => model.PropertyChanged -= h,
                view, (v, sender, args) => v.OnPropertyChanged());

            // Act
            model.NotifyPropertyChanged();

            // Assert
            view.Observer.IsPropertyChangedHandled.Should().BeTrue();
        }
Example #2
0
        public void Delegate_event_method_handler_should_be_called_when_GC_collected_and_subscriber_is_used_aftrewards()
        {
            // Arrange
            var view  = new SomeView();
            var model = new SomeViewModel();

            SubscribeWeakly.OnCustomDelegate <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                a => a.Invoke,
                h => model.PropertyChanged += h,
                h => model.PropertyChanged -= h,
                view.OnPropertyChanged);

            // Act
            GC.Collect();
            model.NotifyPropertyChanged();

            // Assert
            view.Observer.IsPropertyChangedHandled.Should().BeTrue();
        }
Example #3
0
        public void Delegate_event_method_handler_should_not_be_called_when_subscription_disposed()
        {
            // Arrange
            var view  = new SomeView();
            var model = new SomeViewModel();

            var subscription = SubscribeWeakly.OnCustomDelegate <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                a => a.Invoke,
                h => model.PropertyChanged += h,
                h => model.PropertyChanged -= h,
                view.OnPropertyChanged);

            // Act
            subscription.Dispose();
            model.NotifyPropertyChanged();

            // Assert
            view.Observer.IsPropertyChangedHandled.Should().BeFalse();
        }
Example #4
0
        public void Delegate_event_method_handler_should_not_be_called_when_GC_collected_and_subscriber_is_not_used_aftrewards()
        {
            // Arrange
            var view  = new SomeView();
            var model = new SomeViewModel();

            SubscribeWeakly.OnCustomDelegate <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                a => a.Invoke,
                h => model.PropertyChanged += h,
                h => model.PropertyChanged -= h,
                view.OnPropertyChanged);

            // Act
            var observer = view.Observer;

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

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