コード例 #1
0
        public void GenericObservableCommandOfObjectShouldObserveCanExecuteAndObserveOtherProperties()
        {
            var canExecuteChangedRaised = false;
            var commandTestObject       = new CommandTestObject();
            var factory            = new PropertyObserverFactory();
            var canExecuteObserver = factory.ObservesCanExecute(commandTestObject, o => o.BoolProperty);
            var observer1          = factory.ObservesProperty(commandTestObject, o => o.IntProperty);

            ICommand command =
                new ActivatableCanExecuteObserverCommand <object>(o => { }, canExecuteObserver, observer1).Activate();

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            Assert.False(canExecuteChangedRaised);
            Assert.False(command.CanExecute(null));

            commandTestObject.IntProperty = 10;

            Assert.True(canExecuteChangedRaised);
            Assert.False(command.CanExecute(null));

            canExecuteChangedRaised = false;
            Assert.False(canExecuteChangedRaised);

            commandTestObject.BoolProperty = true;

            Assert.True(canExecuteChangedRaised);
            Assert.True(command.CanExecute(null));
        }
コード例 #2
0
        public void GenericObservableCommandOfNullableIntWithNullableParameterShouldObserveCanExecute()
        {
            var canExecuteChangedRaised = false;
            var commandTestObject       = new CommandTestObject();
            var factory   = new PropertyObserverFactory();
            var observer1 = factory.ObservesCanExecute(commandTestObject.BoolPropertyExpression);

            ICommand command = new ActivatableCanExecuteObserverCommand <int?>(o => { }, observer1).Activate();

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            Assert.False(canExecuteChangedRaised);
            Assert.False(command.CanExecute(null));

            commandTestObject.BoolProperty = true;

            Assert.True(canExecuteChangedRaised);
            Assert.True(command.CanExecute(null));
        }