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);
        }
        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 TestEnsureInTransaction()
        {
            var testObject         = new TestInpc();
            var reactiveTestObject = new ReactiveInpc <TestInpc>(testObject);

            // Ensure that we only allow changes inside a transaction
            Assert.That(() => testObject.TestProperty = 2, Throws.Exception.TypeOf <InvalidOperationException>());
        }
        public void TestNotifyChanged()
        {
            var           testObject         = new TestInpc();
            var           reactiveTestObject = new ReactiveInpc <TestInpc>(testObject);
            ChangedCalled changedCalled      = EnsureChangedCalled(reactiveTestObject);

            Transaction.Start();
            testObject.TestProperty = 2;
            testObject.TestProperty = 3;
            testObject.TestProperty = 4;
            CompleteTransactionAndAssertChangedCalled(changedCalled);
        }
        public void Test_RaisePropertyChangedDirect()
        {
            ClearAll();
            var dispatcher = new InlineMockMainThreadDispatcher();
            Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);

            var notified = new List<string>();
            var t = new TestInpc();
            t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName);
            t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));

            Assert.That(notified.Count == 1);
            Assert.That(notified[0] == "Foo");
        }
        public void Test_RaisePropertyChangedDirect()
        {
            ClearAll();
            var dispatcher = new InlineMockMainThreadDispatcher();

            Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(dispatcher);

            var notified = new List <string>();
            var t        = new TestInpc();

            t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName);
            t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));

            Assert.That(notified.Count == 1);
            Assert.That(notified[0] == "Foo");
        }
Esempio n. 7
0
        public void Test_RaisePropertyChangedForName()
        {
            _fixture.ClearAll();
            var dispatcher = new InlineMockMainThreadDispatcher();

            _fixture.Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(dispatcher);

            var notified = new List <string>();
            var t        = new TestInpc();

            t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName);
            t.RaisePropertyChanged("Foo");

            Assert.True(notified.Count == 1);
            Assert.True(notified[0] == "Foo");
        }
        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);
        }