Inheritance: MvxMainThreadDispatcher, IMvxMainThreadDispatcher
        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_PropertyChanged_Raises_Multiple_CanExecuteChange()
        {
            ClearAll();

            var dispatcher = new InlineMockMainThreadDispatcher();
            Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);

            var testObject = new SharedCommandTestClass();
            var collection = new MvxCommandCollectionBuilder()
                .BuildCollectionFor(testObject);

            var calledByAttrCommand = collection["CalledByAttr"];
            Assert.IsNotNull(calledByAttrCommand);
            var countAttr = 0;
            calledByAttrCommand.CanExecuteChanged += (sender, args) => countAttr++;

            var calledByAttr2Command = collection["CalledByAttr2"];
            Assert.IsNotNull(calledByAttr2Command);
            var countAttr2 = 0;
            calledByAttr2Command.CanExecuteChanged += (sender, args) => countAttr2++;

            testObject.RaisePropertyChanged("CanExecuteAttributed");
            Assert.AreEqual(1, countAttr);
            Assert.AreEqual(1, countAttr2);

            testObject.RaisePropertyChanged("CanExecuteAttributed");
            Assert.AreEqual(2, countAttr);
            Assert.AreEqual(2, countAttr2);
        }
Ejemplo n.º 3
-1
        public void Test_PropertyChanged_Raises_CanExecuteChange()
        {
            ClearAll();

            var dispatcher = new InlineMockMainThreadDispatcher();
            Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);

            var testObject = new CommandTestClass();
            var collection = new MvxCommandCollectionBuilder()
                .BuildCollectionFor(testObject);

            var myCommand = collection["My"];
            Assert.IsNotNull(myCommand);
            var countMy = 0;
            myCommand.CanExecuteChanged += (sender, args) => countMy++;

            var myExCommand = collection["MyEx"];
            Assert.IsNotNull(myExCommand);
            var countMyEx = 0;
            myExCommand.CanExecuteChanged += (sender, args) => countMyEx++;

            var calledByAttrCommand = collection["CalledByAttr"];
            Assert.IsNotNull(calledByAttrCommand);
            var countAttr = 0;
            calledByAttrCommand.CanExecuteChanged += (sender, args) => countAttr++;

            var calledByAttr2Command = collection["CalledByAttr2"];
            Assert.IsNotNull(calledByAttr2Command);
            var countAttr2 = 0;
            calledByAttr2Command.CanExecuteChanged += (sender, args) => countAttr2++;

            this.CheckCounts(testObject);

            testObject.RaisePropertyChanged("CanExecuteAttributed2");
            Assert.AreEqual(0, countMy);
            Assert.AreEqual(0, countMyEx);
            Assert.AreEqual(0, countAttr);
            Assert.AreEqual(1, countAttr2);

            testObject.RaisePropertyChanged("CanExecuteAttributed2");
            Assert.AreEqual(0, countMy);
            Assert.AreEqual(0, countMyEx);
            Assert.AreEqual(0, countAttr);
            Assert.AreEqual(2, countAttr2);

            testObject.RaisePropertyChanged("CanExecuteAttributed");
            Assert.AreEqual(0, countMy);
            Assert.AreEqual(0, countMyEx);
            Assert.AreEqual(0, countAttr);
            Assert.AreEqual(2, countAttr2);

            testObject.RaisePropertyChanged("CanExecuteMyCommand");
            testObject.RaisePropertyChanged("CanExecuteMyCommand");
            testObject.RaisePropertyChanged("CanExecuteMyCommand");
            Assert.AreEqual(3, countMy);
            Assert.AreEqual(0, countMyEx);
            Assert.AreEqual(0, countAttr);
            Assert.AreEqual(2, countAttr2);

            testObject.RaisePropertyChanged("CanExecuteMyExCommand");
            testObject.RaisePropertyChanged("CanExecuteMyCommand");
            testObject.RaisePropertyChanged("CanExecuteMyExCommand");
            testObject.RaisePropertyChanged("CanExecuteMyCommand");
            testObject.RaisePropertyChanged("CanExecuteMyExCommand");
            testObject.RaisePropertyChanged("CanExecuteMyExCommand");
            testObject.RaisePropertyChanged("CanExecuteMyExCommand");
            testObject.RaisePropertyChanged("CanExecuteMyExCommand");
            Assert.AreEqual(5, countMy);
            Assert.AreEqual(6, countMyEx);
            Assert.AreEqual(0, countAttr);
            Assert.AreEqual(2, countAttr2);
        }