internal TimeSpan NotifyMethodsWithReflection(int times) { var view = new SomeView(); var viewModel = new SomeViewModel(); viewModel.SubscribeWeakly(x => x.Flag, view.OnFlagChanged); var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < times; i++) viewModel.NotifyPropertyChanged(); stopwatch.Stop(); return stopwatch.Elapsed; }
public void PropertyChanged_event_handler_should_be_called_when_GC_collected_and_subscriber_is_used_aftrewards() { // Arrange var view = new SomeView(); var viewModel = new SomeViewModel(); viewModel.SubscribeWeakly(view, (x, _, e) => x.OnPropertyChanged()); // Act GC.Collect(); viewModel.NotifyPropertyChanged(); // Assert view.Observer.IsPropertyChangedHandled.Should().BeTrue(); }
internal TimeSpan SubcribeMethodsWithReflection(int times) { var view = new SomeView(); var viewModel = new SomeViewModel(); var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < times; i++) { viewModel.SubscribeWeakly(x => x.Flag, view.OnFlagChanged); } stopwatch.Stop(); return(stopwatch.Elapsed); }
internal TimeSpan SubcribeHandlers(int times) { var view = new SomeView(); var viewModel = new SomeViewModel(); var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < times; i++) { viewModel.SubscribeWeakly(view, (v, m, e) => v.OnFlagChanged(false)); } stopwatch.Stop(); return(stopwatch.Elapsed); }
public void PropertyChanged_event_handler_should_not_be_called_when_GC_collected_and_subscriber_is_not_used_aftrewards() { // Arrange var view = new SomeView(); var viewModel = new SomeViewModel(); viewModel.SubscribeWeakly(view, (x, _, e) => x.OnPropertyChanged()); // Act var observer = view.Observer; // ReSharper disable RedundantAssignment view = null; // ReSharper restore RedundantAssignment GC.Collect(); viewModel.NotifyPropertyChanged(); // Assert observer.IsPropertyChangedHandled.Should().BeFalse(); }
internal TimeSpan SubcribeHandlers(int times) { var view = new SomeView(); var viewModel = new SomeViewModel(); var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < times; i++) viewModel.SubscribeWeakly(view, (v, m, e) => v.OnFlagChanged(false)); stopwatch.Stop(); return stopwatch.Elapsed; }