Beispiel #1
0
        public BaseViewModel()
        {
            Settings = Mvx.Resolve<ISettingsService>();
            Service = Mvx.Resolve<IJabbrService>();
            Messenger = Mvx.Resolve<IMvxMessenger>();

            Commands = new MvxCommandCollectionBuilder().BuildCollectionFor(this);
        }
        public void Test_PropertyChanged_Raises_Multiple_CanExecuteChange()
        {
            ClearAll();

            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);
        }
        public void Test_PropertyChanged_Raises_CanExecuteChange()
        {
            ClearAll();

            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++;

            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);
        }
        public void Test_Attribute2_Command_CanExecute()
        {
            ClearAll();

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

            var myCommand = collection["CalledByAttr2"];
            Assert.IsNotNull(myCommand);
            CheckCounts(testObject);
            var result = myCommand.CanExecute();
            CheckCounts(testObject, countCanExecuteAttributed2Called: 1);
            result = myCommand.CanExecute();
            result = myCommand.CanExecute();
            result = myCommand.CanExecute();
            CheckCounts(testObject, countCanExecuteAttributed2Called: 4);
        }
        public void Test_Attribute1_Command()
        {
            ClearAll();

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

            var myCommand = collection["CalledByAttr"];
            Assert.IsNotNull(myCommand);
            CheckCounts(testObject);
            myCommand.Execute();
            CheckCounts(testObject, countAttributedCalled: 1);
            myCommand.Execute();
            myCommand.Execute();
            myCommand.Execute();
            CheckCounts(testObject, countAttributedCalled: 4);
        }
        public void Test_IntReturning_Command()
        {
            ClearAll();

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

            var myCommand = collection["AnIntReturning"];
            Assert.IsNotNull(myCommand);
            CheckCounts(testObject);
            myCommand.Execute();
            CheckCounts(testObject, countIntReturningCalled: 1);
            myCommand.Execute();
            myCommand.Execute();
            myCommand.Execute();
            CheckCounts(testObject, countIntReturningCalled: 4);
        }
        public void Test_Conventional_Parameter_Command_CanExecute()
        {
            ClearAll();

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

            var myCommand = collection["MyEx"];
            Assert.IsNotNull(myCommand);
            CheckCounts(testObject);
            var result = myCommand.CanExecute();
            CheckCounts(testObject, countCanExecuteMyExCalled: 1);
            result = myCommand.CanExecute();
            result = myCommand.CanExecute();
            result = myCommand.CanExecute();
            CheckCounts(testObject, countCanExecuteMyExCalled: 4);
        }
        public void Test_Conventional_Command()
        {
            ClearAll();

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

            var myCommand = collection["My"];
            Assert.IsNotNull(myCommand);
            CheckCounts(testObject);
            myCommand.Execute();
            CheckCounts(testObject, countMyCalled: 1, countCanExecuteMyCalled: 1);
            myCommand.Execute();
            myCommand.Execute();
            myCommand.Execute();
            CheckCounts(testObject, countMyCalled: 4, countCanExecuteMyCalled: 4);
        }
 public void Init()
 {
     Commands = new MvxCommandCollectionBuilder()
         .BuildCollectionFor(this);
     PickRandomCommand();
 }