public EntityBaseView(Window owner, ViewModelBase content) { InitializeComponent(); Owner = owner; EntityContent.Content = content; Title = content.PageTitle; DeleteCommand = new SimpleCommand(() => { content.DeleteCommand.Execute(null); Close(); }, () => content.DeleteCommand.CanExecute(null)); SaveCommand = new SimpleCommand(() => { content.SaveCommand.Execute(null); ((SimpleCommand)DeleteCommand).RaiseCanExecuteChanged(); }, () => content.SaveCommand.CanExecute(null)); SaveAndCloseCommand = new SimpleCommand(() => { SaveCommand.Execute(null); if (!content.HasError) { Close(); } }, () => SaveCommand.CanExecute(null)); }
public void CanExecute_WhenNoCanExecuteDelegateIsPassed_CanExecuteShouldReturnTrue() { var command = new SimpleCommand(() => { }); var result = command.CanExecute(); Assert.IsTrue(result,"CanExecute should always return true when no delgate is given."); }
public void CanExecute_WhenACanExecuteDelegateIsPassedThatEvaluatesToFalse_CanExecuteShouldReturnFalse() { var command = new SimpleCommand(() => { }, () => false); var result = command.CanExecute(); Assert.IsFalse(result, "CanExecute should return false as there is a delegate and it returns false"); }
public SimpleCommandBinding() { CanExecute += (CanExecuteRoutedEventHandler)((o, e) => { e.CanExecute = SimpleCommand != null && SimpleCommand.CanExecute(e.Parameter); }); Executed += (ExecutedRoutedEventHandler)((o, e) => { if (SimpleCommand != null) { SimpleCommand.Execute(e.Parameter); } }); }
public SimpleRoutedCommand(RoutedUICommand routedCommand, SimpleCommand simpleCommand) { _routedCommand = routedCommand; _embeddedCommand = simpleCommand; ExecuteDelegate = x => { _embeddedCommand.Execute(x); this.CommandSucceeded = simpleCommand.CommandSucceeded; }; CanExecuteDelegate = x => { return(_embeddedCommand.CanExecute(x)); }; init(); }
public void GivenSimpleCommandWithCanExec_WhenInvokingCommand_ThenItDoesExecuteBasedOnOutsideState() { TEST_OUTPUT = String.Empty; bool canExecute = false; simpleCommandRelayerSubject = new RelayCommand(() => TEST_OUTPUT += "1", () => { return(canExecute); }); if (SimpleCommand.CanExecute(null)) { for (int i = 0; i < 3; i++) { SimpleCommand.Execute(null); } } Assert.NotEqual("111", TEST_OUTPUT); canExecute = true; SimpleCommand.Execute(null); Assert.Equal("1", TEST_OUTPUT); }
public void GivenSimpleCommand_WhenCheckingForCanExec_ThenItReturnsTrue() { simpleCommandRelayerSubject = new RelayCommand(() => TEST_OUTPUT += "1"); Assert.True(SimpleCommand.CanExecute(null)); }
public void CanExecuteTest() { Assert.True(testCommand.CanExecute(new object())); Assert.True(genericTestCommand.CanExecute(param)); }