Esempio n. 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));
        }
        public void CanExecuteReturnsTrueWithoutCanExecuteDelegate()
        {
            var handlers = new DelegateObjectHandlers();
            var command  = new ActivatableCanExecuteObserverCommand <object>(handlers.Execute, new CommandManagerObserver());

            var condition = command.CanExecute(null);

            Assert.True(condition);
        }
Esempio n. 3
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));
        }
        public void CanExecuteCallsPassedInCanExecuteDelegate()
        {
            var handlers = new DelegateObjectHandlers();
            var command  = new ActivatableCanExecuteObserverCommand <object>(
                handlers.Execute,
                handlers.CanExecute,
                new CommandManagerObserver());
            var parameter = new object();

            handlers.CanExecuteReturnValue = true;
            var actual = command.CanExecute(parameter);

            Assert.AreSame(parameter, handlers.CanExecuteParameter);
            Assert.AreEqual(handlers.CanExecuteReturnValue, actual);
        }
Esempio n. 5
0
        public void ShouldPassParameterInstanceOnCanExecute()
        {
            var      canExecuteCalled = false;
            var      testClass        = new MyClass();
            ICommand command          = new ActivatableCanExecuteObserverCommand <MyClass>(
                p => { },
                delegate(MyClass parameter)
            {
                Assert.AreSame(testClass, parameter);
                canExecuteCalled = true;
                return(true);
            },
                new DummyObserver());

            command.CanExecute(testClass);
            Assert.True(canExecuteCalled);
        }