public void CanExecuteChanged_RemoveHandler_HandlerIsNotCalled() { SynchronizationContext.SetSynchronizationContext(new TestSynchronizationContext()); var commandExecuted = false; _canExecuteChangedRaised = false; var command = new SimpleRelayCommand(() => { // ReSharper disable once AccessToModifiedClosure Assert.False(commandExecuted); commandExecuted = true; }); command.CanExecuteChanged += CommandOnCanExecuteChanged; command.Execute(null); Assert.True(commandExecuted); Assert.True(_canExecuteChangedRaised); _canExecuteChangedRaised = false; commandExecuted = false; command.CanExecuteChanged -= CommandOnCanExecuteChanged; command.Execute(null); Assert.True(commandExecuted); Assert.False(_canExecuteChangedRaised); }
public void Execute_CanExecuteIsFalse_ActionIsNotExecuted() { var commandExecuted = false; var command = new SimpleRelayCommand(() => { Assert.False(commandExecuted); commandExecuted = true; }, () => false); command.Execute(null); Assert.False(commandExecuted); }
public void Execute_Wait_ActionIsExecuted() { SynchronizationContext.SetSynchronizationContext(new TestSynchronizationContext()); var commandExecuted = false; var canExecuteChangedRaised = false; var command = new SimpleRelayCommand(() => { Assert.False(commandExecuted); commandExecuted = true; }); command.CanExecuteChanged += (_, _) => { Assert.False(canExecuteChangedRaised); canExecuteChangedRaised = true; }; command.Execute(null); Assert.True(commandExecuted); Assert.True(canExecuteChangedRaised); }