示例#1
0
        public void GenericDelegateCommandOfObjectShouldObserveCanExecuteAndObserveOtherProperties()
        {
            var canExecuteChangedRaised = false;
            var commandTestObject       = new CommandTestObject();

            ICommand command = new ActivatablePropertyObserverCommand <object>(o => { })
                               .ObservesCanExecute(commandTestObject.BoolPropertyExpression)
                               .ObservesProperty(commandTestObject.IntPropertyExpression);

            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 GenericDelegateCommandOfNullableIntWithNullableParameterShouldObserveCanExecute()
        {
            var canExecuteChangedRaised = false;
            var commandTestObject       = new CommandTestObject();

            ICommand command =
                new ActivatablePropertyObserverCommand <int?>(o => { }).ObservesCanExecute(commandTestObject.BoolPropertyExpression);

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

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

            commandTestObject.BoolProperty = true;

            Assert.True(canExecuteChangedRaised);
            Assert.True(command.CanExecute(null));
        }
示例#3
0
        public void GenericDelegateCommandOfObjectShouldObserveWithOwnerCanExecute()
        {
            var canExecuteChangedRaised = false;
            var commandTestObject       = new CommandTestObject();

            ICommand command =
                new ActivatablePropertyObserverCommand <object>(o1 => { }).ObservesCanExecute(commandTestObject, o2 => o2.BoolProperty);

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

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

            commandTestObject.BoolProperty = true;

            Assert.True(canExecuteChangedRaised);
            Assert.True(command.CanExecute(null));
        }
示例#4
0
        public void CanExecuteOfObjectReturnsTrueWithoutCanExecuteDelegate()
        {
            var handlers = new DelegateObjectHandlers();
            var command  = new ActivatablePropertyObserverCommand <object>(handlers.Execute);

            var retVal = command.CanExecute(null);

            Assert.True(retVal);
        }
示例#5
0
        public void CanExecuteOfObjectCallsPassedInCanExecuteDelegate()
        {
            var handlers  = new DelegateObjectHandlers();
            var command   = new ActivatablePropertyObserverCommand <object>(handlers.Execute, handlers.CanExecute);
            var parameter = new object();

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

            Assert.AreSame(parameter, handlers.CanExecuteParameter);
            Assert.AreEqual(handlers.CanExecuteReturnValue, retVal);
        }
示例#6
0
        public void ShouldPassParameterInstanceOnCanExecute()
        {
            var      canExecuteCalled = false;
            var      testClass        = new MyClass();
            ICommand command          = new ActivatablePropertyObserverCommand <MyClass>(
                p => { },
                delegate(MyClass parameter)
            {
                Assert.AreSame(testClass, parameter);
                canExecuteCalled = true;
                return(true);
            });

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