public void Test_TurnOffUIThread() { ClearAll(); var dispatcher = new CountingMockMainThreadDispatcher(); Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher); var notified = new List<string>(); var t = new TestInpc(); t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName); t.ShouldAlwaysRaiseInpcOnUserInterfaceThread(false); t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo")); Assert.That(dispatcher.Count == 0); Assert.That(notified.Count == 1); Assert.That(notified[0] == "Foo"); t.ShouldAlwaysRaiseInpcOnUserInterfaceThread(true); t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo")); Assert.AreEqual(1, dispatcher.Count); Assert.That(notified.Count == 1); Assert.That(notified[0] == "Foo"); }
public void Test_Interceptor() { ClearAll(); var dispatcher = new CountingMockMainThreadDispatcher(); Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher); var interceptor = new Interceptor(); Ioc.RegisterSingleton<IMvxInpcInterceptor>(interceptor); var notified = new List<string>(); var t = new TestInpc(); t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName); interceptor.Handler = (s, e) => MvxInpcInterceptionResult.RaisePropertyChanged; t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo")); Assert.That(dispatcher.Count == 1); interceptor.Handler = (s, e) => MvxInpcInterceptionResult.DoNotRaisePropertyChanged; t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo")); Assert.That(dispatcher.Count == 1); interceptor.Handler = (s, e) => MvxInpcInterceptionResult.RaisePropertyChanged; t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo")); Assert.That(dispatcher.Count == 2); }