public void DeattachingFromCommandDoesNotInvokeItWhenClickingIt() { var mockCommand = new MockCommand(); MockClickableButton button = new MockClickableButton(); button.SetValue(CommandProperties.CommandProperty, mockCommand); button.SetValue(CommandProperties.CommandProperty, null); button.InvokeClick(); Assert.IsFalse(mockCommand.ExecuteCalled); }
public void ButtonClickExecutesCommand() { var mockCommand = new MockCommand(); MockClickableButton button = new MockClickableButton(); button.SetValue(CommandProperties.CommandProperty, mockCommand); Assert.IsFalse(mockCommand.ExecuteCalled); button.InvokeClick(); Assert.IsTrue(mockCommand.ExecuteCalled); }
public void InitialHookupSetButtonAsDisabledIfCanExecuteIsFalse() { var mockCommand = new MockCommand(); var button = new Button(); button.IsEnabled = true; mockCommand.CanExecuteReturnValue = false; button.SetValue(CommandProperties.CommandProperty, mockCommand); Assert.IsFalse(button.IsEnabled); }
public void CommandParameterIsPassedToCommandInvocation() { var mockCommand = new MockCommand(); MockClickableButton button = new MockClickableButton(); button.SetValue(CommandProperties.CommandProperty, mockCommand); object parameter = new object(); button.SetValue(CommandProperties.CommandParameterProperty, parameter); button.InvokeClick(); Assert.IsNotNull(mockCommand.ExecuteArgumentParameter); Assert.AreEqual(parameter, mockCommand.ExecuteArgumentParameter); }
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 BehaviorDoesNotPreventButtonFromBeingGarbageCollected() { var mockCommand = new MockCommand(); var button = new Button(); button.SetValue(CommandProperties.CommandProperty, mockCommand); WeakReference buttonReference = new WeakReference(button); button = null; GC.Collect(); GC.Collect(); GC.WaitForPendingFinalizers(); Assert.IsFalse(buttonReference.IsAlive); }
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 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); }