public void TestComposite_PassParameter() { bool command1Called = false; string command1Result = ""; string checkValue = ""; var composite = new CompositeCommand(); composite.Add(new DelegateCommand <string>((value) => { command1Result = value; command1Called = true; }, (value) => { checkValue = value; return(true); })); if (composite.CanExecute("Ok")) { composite.Execute("Ok"); } Assert.IsTrue(command1Called); Assert.AreEqual("Ok", command1Result); Assert.AreEqual("Ok", checkValue); }
public void ExecuteCompositeCommand() { BindingEnvironment environment = new BindingEnvironment(); SetVariableCommand command1 = new SetVariableCommand("foo", new ConstantExpression("bar")); SetVariableCommand command2 = new SetVariableCommand("one", new ConstantExpression(1)); SetVariableCommand command3 = new SetVariableCommand("bar", new VariableExpression("foo")); List <ICommand> commands = new List <ICommand>(); commands.Add(command1); commands.Add(command2); commands.Add(command3); CompositeCommand command = new CompositeCommand(commands); environment.SetValue("foo", null); environment.SetValue("one", null); command.Execute(environment); Assert.AreEqual("bar", environment.GetValue("foo")); Assert.AreEqual(1, environment.GetValue("one")); Assert.AreEqual("bar", environment.GetValue("bar")); }
protected override void OnDeleteCommandExecutedOverride(object sender, ExecutedRoutedEventArgs e) { var compositeRemoveCommand = new CompositeCommand("Remove Connections"); foreach (var item in this.SelectedItems) { var container = this.ContainerGenerator.ContainerFromItem(item) as IShape; if (container != null) { foreach (var connection in this.GetConnectionsForShape(container).ToList()) { compositeRemoveCommand.AddCommand(new UndoableDelegateCommand("Remove Connection", new Action<object>((o) => this.RemoveConnection(connection)), new Action<object>((o) => this.AddConnection(connection)))); } } } base.OnDeleteCommandExecutedOverride(sender, e); if (compositeRemoveCommand.Commands.Count() > 0) { compositeRemoveCommand.Execute(); ((this.UndoRedoService.UndoStack.FirstOrDefault() as CompositeCommand).Commands as IList<Telerik.Windows.Diagrams.Core.ICommand>).Add(compositeRemoveCommand); } }
// Use this for initialization void Start() { t = new EnterFrameTimer(200); t.OnTimer = onTimer; t.Start(); ConsoleCommand command; CompositeCommand cc = new CompositeCommand(CompositeCommandMode.SEQUENCE); cc.OnCommandItemComplete = delegate(AbstractCommand _command) { Debug.Log("Item Complete" + " " + (_command as ConsoleCommand).index.ToString()); }; cc.OnCommandComplete = delegate(AbstractCommand _command) { Debug.Log("All Complete"); }; int max = 10; for (int i = 0; i < max; i++) { command = new ConsoleCommand(); command.index = i; cc.AddCommand(command); } cc.Execute(); }
public void ExecuteOrderTest() { //Arrange Stack <int> stack = new Stack <int>(); ICommand firstOne = MockRepository.GenerateStrictMock <ICommand>(); firstOne.Expect(c => c.Execute()).Repeat.Once().Do(new Func <bool>((() => { stack.Push(1); return(true); }))); ICommand secondOne = MockRepository.GenerateStrictMock <ICommand>(); secondOne.Expect(c => c.Execute()).Repeat.Once().Do(new Func <bool>((() => { stack.Push(2); return(true); }))); ICommand composite = new CompositeCommand(new [] { firstOne, secondOne }); //Act composite.Execute(); //Assert Assert.AreEqual(2, stack.Pop()); Assert.AreEqual(1, stack.Pop()); firstOne.VerifyAllExpectations(); secondOne.VerifyAllExpectations(); }
/// <summary> /// Allows decouple a sender from a receiver. The sender will talk to the receive through a command. Commands can be undone and persisted. /// /// With Command its easy to build an independent framework that anyone can use. By creating a custom service which implements a base interface, /// any command can be run with the same method, depending on the service. /// </summary> static void Command() { // One command attached to an action. var service = new CustomerService(); var command = new AddCustomerCommand(service); var button = new Command.fx.Button(command); button.Click(); // Multiple commands attached to an action. var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteCommand()); composite.Execute(); // Using the undo mechanism. Multiple commands are implementing the same interface(s) and using the same history. var history = new Command.editor.History(); var document = new Command.editor.HtmlDocument(); document.Content = "Hello"; var boldCommand = new BoldCommand(document, history); boldCommand.Execute(); Console.WriteLine(document.Content); var undoCommant = new UndoCommand(history); undoCommant.Execute(); Console.WriteLine(document.Content); }
public void IfOneOrMoreExecutesWithFalseResultFalseTest(bool[] executeResults) { //Arrange int count = executeResults.Length; ICommand[] commands = new ICommand[count]; for (int i = 0; i < count; ++i) { commands[i] = MockRepository.GenerateStrictMock <ICommand>(); commands[i].Expect(cm => cm.Execute()).Return(executeResults[i]).Repeat.Once(); } ICommand composite = new CompositeCommand(commands); //Act bool result = composite.Execute(); //Assert Assert.IsFalse(result); foreach (ICommand command in commands) { command.VerifyAllExpectations(); } }
public void RunDefaultImageEnchancement() { var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteFilterCommand()); composite.Execute(); }
private void NextClicked(object sender, RoutedEventArgs e) { if (EditableWrapper == null || EditableWrapper.IsDirty) { _saveCompositeCommand.Execute(Content); IsExpanded = false; } }
public void BeAbleToReexecuteTheCommandsAgain() { var subcmd1 = new Mock <ICommand>(); subcmd1.Setup(c => c.CanExecute(null)).Returns(true); var subcmd2 = new Mock <ICommand>(); subcmd2.Setup(c => c.CanExecute(null)).Returns(true); var cmd = new CompositeCommand(new[] { subcmd1.Object, subcmd2.Object }); cmd.Execute(null); cmd.Execute(null); subcmd1.Verify(c => c.Execute(null), Times.Exactly(2)); subcmd2.Verify(c => c.Execute(null), Times.Exactly(2)); }
public static void Behavioral_CommandComposite() { // This is a composite command var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteCommand()); composite.Execute(); }
static void TestCompositeCommand() { var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteCommand()); composite.Execute(); }
private static void EvaluateCommands(string text, Context context) { Parser parser = new Parser(text); var result = parser.ParseCommands(); var command = new CompositeCommand(result); command.Execute(context); }
public void NotExecuteCommandWhenCanExecuteIsFalse() { var subcmd = new Mock <ICommand>(MockBehavior.Strict); subcmd.Setup(c => c.CanExecute(null)).Returns(false); var cmd = new CompositeCommand(subcmd.Object); cmd.Execute(null); }
public void RegistersCommandForExecution() { var vm = new CompositeCommandViewModel(); var compositeCommand = new CompositeCommand(); compositeCommand.RegisterCommand(vm.TestCommand1, vm); compositeCommand.Execute(); Assert.IsTrue(vm.IsTestCommand1Executed); }
public void RegisteredActionsCanBeUnregistered_DynamicAction() { var compositeCommand = new CompositeCommand(); compositeCommand.RegisterAction(RegisteredActionsCanBeUnregistered_TestMethod); compositeCommand.UnregisterAction(RegisteredActionsCanBeUnregistered_TestMethod); compositeCommand.Execute(null); Assert.IsFalse(_registeredActionsCanBeUnregistered_TestValue); }
public void ExecuteOneSubCommand() { var subcmd = new Mock <ICommand>(); subcmd.Setup(c => c.CanExecute(null)).Returns(true); var cmd = new CompositeCommand(subcmd.Object); cmd.Execute(null); subcmd.Verify(c => c.Execute(null)); }
public void MultiDispatchCommandDoesNotExecutesInactiveRegisteredCommands() { CompositeCommand activeAwareCommand = new CompositeCommand(true); MockActiveAwareCommand command = new MockActiveAwareCommand(); command.IsActive = false; activeAwareCommand.RegisterCommand(command); activeAwareCommand.Execute(null); Assert.IsFalse(command.WasExecuted); }
public void MultiDispatchCommandExecutesActiveRegisteredCommands() { CompositeCommand activeAwareCommand = new CompositeCommand(); MockActiveAwareCommand command = new MockActiveAwareCommand(); command.IsActive = true; activeAwareCommand.RegisterCommand(command); activeAwareCommand.Execute(null); Assert.IsTrue(command.WasExecuted); }
public void RegistersActionForExecution() { var compositeCommand = new CompositeCommand(); bool executed = false; var action = new Action <object>(obj => executed = true); compositeCommand.RegisterAction(action); compositeCommand.Execute(); Assert.IsTrue(executed); }
public void RegisteredActionsCanBeInvoked() { var invoked = false; Action action = () => invoked = true; var compositeCommand = new CompositeCommand(); compositeCommand.RegisterAction(action); compositeCommand.Execute(null); Assert.IsTrue(invoked); }
public void CheckEnoughSubCommandsToKnowThatItCanExecuteOrNotBeforeExecuting() { var subcmd1 = new Mock <ICommand>(); subcmd1.Setup(c => c.CanExecute(null)).Returns(false); var subcmd2 = new Mock <ICommand>(MockBehavior.Strict); var cmd = new CompositeCommand(new[] { subcmd1.Object, subcmd2.Object }); cmd.Execute(null); subcmd1.Verify(c => c.CanExecute(null)); }
public void CompositeCommand() { Context context = new Context(); Assert.IsNull(context.GetValue("foo")); Assert.IsNull(context.GetValue("one")); SetCommand setfoo = new SetCommand("foo", new ConstantExpression("bar")); SetCommand setone = new SetCommand("one", new ConstantExpression(1)); CompositeCommand command = new CompositeCommand(new ICommand[] { setfoo, setone }); command.Execute(context); Assert.AreEqual("bar", context.GetValue("foo")); Assert.AreEqual(1, context.GetValue("one")); }
private bool DoDeleteHimSelf(string value, Uri uri) { var deleteInfo = new Tuple <string, Uri>(value, uri); if (_compositeDeleteCommand.RegisteredCommands.Any()) { if (_compositeDeleteCommand.CanExecute(deleteInfo)) { _compositeDeleteCommand.Execute(deleteInfo); return(true); } } return(false); }
public void NotExecuteAnyCommandIfCanExecuteIsFalse() { var subcmd1 = new Mock <ICommand>(MockBehavior.Strict); subcmd1.Setup(c => c.CanExecute(null)).Returns(true); var subcmd2 = new Mock <ICommand>(MockBehavior.Strict); subcmd2.Setup(c => c.CanExecute(null)).Returns(false); var cmd = new CompositeCommand(new[] { subcmd1.Object, subcmd2.Object }); cmd.Execute(null); }
public void PassCorrectParameterForExecute() { var parameter = "parameter"; var subcmd = new Mock <ICommand>(MockBehavior.Strict); subcmd.Setup(c => c.CanExecute(parameter)).Returns(true); subcmd.Setup(c => c.Execute(parameter)); var cmd = new CompositeCommand(subcmd.Object); cmd.Execute(parameter); subcmd.VerifyAll(); }
public void ExecuteMultipleCommands() { bool command1Called = false; bool command2Called = false; var command1 = new DelegateCommand( () => command1Called = true, () => true); var command2 = new DelegateCommand <int>( i => { Assert.AreEqual(123, i); command2Called = true; }, i => { Assert.AreEqual(123, i); return(true); }); var compositeCommand = new CompositeCommand(); compositeCommand.RegisterCommand(command1); compositeCommand.RegisterCommand(command2); compositeCommand.Execute(123); Assert.IsTrue(command1Called); Assert.IsTrue(command2Called); command1Called = false; command2Called = false; compositeCommand.UnregisterCommand(command1); compositeCommand.Execute(123); Assert.IsFalse(command1Called); Assert.IsTrue(command2Called); }
public async Task AutomaticallyUnsubscribesCommandOnViewModelClosed() { var vm = new CompositeCommandViewModel(); var compositeCommand = new CompositeCommand(); compositeCommand.RegisterCommand(vm.TestCommand1, vm); Assert.IsFalse(vm.IsTestCommand1Executed); await vm.CloseViewModel(false); compositeCommand.Execute(); Assert.IsFalse(vm.IsTestCommand1Executed); }
public void CommandAbortingUsesCorrectParameterToCheckIfAbortIsNeeded() { const string parameter = "parameter"; var subcmd = new Mock <ICommand>(); subcmd.Setup(c => c.CanExecute(parameter)).Returns(true); subcmd.Setup(c => c.Execute(It.IsAny <string>())) .Callback(() => subcmd.Raise(c => c.CanExecuteChanged += null, EventArgs.Empty)); var cmd = new CompositeCommand(subcmd.Object); cmd.Execute(parameter); subcmd.Verify(c => c.CanExecute(It.IsNotIn(parameter)), Times.Never()); }
public void ExecuteMultipleSubCommands() { var subcmd1 = new Mock <ICommand>(); subcmd1.Setup(c => c.CanExecute(null)).Returns(true); var subcmd2 = new Mock <ICommand>(); subcmd2.Setup(c => c.CanExecute(null)).Returns(true); var cmd = new CompositeCommand(new[] { subcmd1.Object, subcmd2.Object }); cmd.Execute(null); subcmd1.Verify(c => c.Execute(null)); subcmd2.Verify(c => c.Execute(null)); }
public void CreateAndExecuteCompositeCommand() { IEnumerable <ICommand> commands = new ICommand[] { new SetVariableCommand("a", new ConstantExpression(1)), new SetVariableCommand("b", new ConstantExpression(2)) }; CompositeCommand command = new CompositeCommand(commands); Context context = new Context(); Assert.IsNotNull(command.Commands); Assert.AreEqual(2, command.Commands.Count()); Assert.AreEqual(2, command.Execute(context)); Assert.AreEqual(1, context.GetValue("a")); Assert.AreEqual(2, context.GetValue("b")); }
// Use this for initialization void Start(){ t = new EnterFrameTimer(200); t.OnTimer = onTimer; t.Start(); ConsoleCommand command; CompositeCommand cc = new CompositeCommand(CompositeCommandMode.SEQUENCE); cc.OnCommandItemComplete = delegate(AbstractCommand _command) { Debug.Log("Item Complete" + " " + (_command as ConsoleCommand).index.ToString()); }; cc.OnCommandComplete = delegate(AbstractCommand _command) { Debug.Log("All Complete"); }; int max = 10; for (int i = 0; i < max; i++) { command = new ConsoleCommand(); command.index = i; cc.AddCommand(command); } cc.Execute(); }
private static void DetachConnections(RadDiagram diagram) { if (diagram.SelectedItems.Count() > 1) { CompositeCommand changeSourcesCompositeCommand = new CompositeCommand("Detach ends"); foreach (var connection in diagram.SelectedItems.OfType<IConnection>()) { if (!diagram.SelectedItems.Contains(connection.Source)) { changeSourcesCompositeCommand.AddCommand(new ChangeSourceCommand(connection, null, connection.StartPoint)); } if (!diagram.SelectedItems.Contains(connection.Target)) { changeSourcesCompositeCommand.AddCommand(new ChangeTargetCommand(connection, null, connection.EndPoint)); } } changeSourcesCompositeCommand.Execute(); AttachedProperties.SetPendingCommand(diagram, changeSourcesCompositeCommand); } }
public void ExecuteMultipleCommands() { bool command1Called = false; bool command2Called = false; var command1 = new DelegateCommand( () => command1Called = true, () => true); var command2 = new DelegateCommand<int>( i => { Assert.AreEqual(123, i); command2Called = true; }, i => { Assert.AreEqual(123, i); return true; }); var compositeCommand = new CompositeCommand(); compositeCommand.RegisterCommand(command1); compositeCommand.RegisterCommand(command2); compositeCommand.Execute(123); Assert.IsTrue(command1Called); Assert.IsTrue(command2Called); command1Called = false; command2Called = false; compositeCommand.UnregisterCommand(command1); compositeCommand.Execute(123); Assert.IsFalse(command1Called); Assert.IsTrue(command2Called); }