public void CanExecuteChangedMakesButtonRequeryCommandAndSetsIsEnabledAppropriately() { var mockCommand = new MockCommand(); var button = new Button(); button.IsEnabled = true; button.SetValue(CommandProperties.CommandProperty, mockCommand); mockCommand.CanExecuteReturnValue = false; mockCommand.RaiseCanExecuteChanged(); Assert.IsFalse(button.IsEnabled); mockCommand.CanExecuteReturnValue = true; mockCommand.RaiseCanExecuteChanged(); Assert.IsTrue(button.IsEnabled); }
public void WhenDesubscribedDontCallCanExecute() { var mockCommand = new MockCommand(); var button = new Button(); button.IsEnabled = true; button.SetValue(CommandProperties.CommandProperty, mockCommand); button.SetValue(CommandProperties.CommandProperty, null); mockCommand.CanExecuteCalled = false; mockCommand.RaiseCanExecuteChanged(); Assert.IsFalse(mockCommand.CanExecuteCalled); }
public void CanExecuteChangedGetsCalledPassingTheCommandParameter() { var mockCommand = new MockCommand(); var button = new Button(); button.IsEnabled = true; button.SetValue(CommandProperties.CommandProperty, mockCommand); object parameter = new object(); button.SetValue(CommandProperties.CommandParameterProperty, parameter); mockCommand.CanExecuteArgumentParameter = null; mockCommand.RaiseCanExecuteChanged(); Assert.IsNotNull(mockCommand.CanExecuteArgumentParameter); Assert.AreSame(parameter, mockCommand.CanExecuteArgumentParameter); }