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)); }
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)); }
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)); }
public void CanExecuteOfObjectReturnsTrueWithoutCanExecuteDelegate() { var handlers = new DelegateObjectHandlers(); var command = new ActivatablePropertyObserverCommand <object>(handlers.Execute); var retVal = command.CanExecute(null); Assert.True(retVal); }
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); }
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); }