private static SurfaceAreaCalculator BuildSurfaceAreaCalculator() { var logger = new Logger(); var figuresStorage = new FiguresStorage(); var figureCreators = new List <IFigureCreator> { new SquareCreator(), new CircleCreator(), new TriangleCreator(), new RectangleCreator(), new TrapezoidCreator() }; var figureCreationManager = new FigureCreationManager(figureCreators); var commandExecutors = new List <ICommandExecutor> { new CreateCommandExecutor(figuresStorage, figureCreationManager, logger), new PrintCommandExecutor(figuresStorage, logger), new ResetCommandExecutor(figuresStorage, logger), new ExitCommandExecutor() }; var commandExecutionManager = new CommandExecutionManager(commandExecutors, logger); return(new SurfaceAreaCalculator(commandExecutionManager, logger)); }
public void ExecuteCommand_NullCommand_ArgumentNullException() { var commandExecutionManager = new CommandExecutionManager(); var ex = Assert.Throws <ArgumentNullException>( () => commandExecutionManager.ExecuteCommand(null)); Assert.That(ex.ParamName, Is.EqualTo(ExecuteCommandParam)); }
public void ExecuteCommand_ExecutesCommand() { var commandExecutionManager = new CommandExecutionManager(); var commandMock = new Mock <ICommand>(); commandExecutionManager.ExecuteCommand(commandMock.Object); commandMock.Verify(c => c.Execute(), Times.Once()); }
public ContextMenuInitalizer(ClientsContextMenu clientsContextMenu, IEnumerable <ICommandDescription> commandDescriptions, VisualStudioIcons icons, IWindowService windowService, CommandExecutionManager commandExecutionManager) { _clientsContextMenu = clientsContextMenu; _commandDescriptions = commandDescriptions; _icons = icons; _windowService = windowService; _commandExecutionManager = commandExecutionManager; }
public TasksViewModel(IWindowService windowService, IMazeRestClient restClient, IAppDispatcher dispatcher, IServiceProvider services, CommandExecutionManager commandExecutionManager) : base(Tx.T("TasksInfrastructure:Tasks"), PackIconFontAwesomeKind.CalendarCheckRegular) { CommandExecutionManager = commandExecutionManager; _windowService = windowService; _restClient = restClient; _dispatcher = dispatcher; _services = services; }
public void Undo_PerformsUndo() { var commandExecutionManager = new CommandExecutionManager(); var commandMock = new Mock <ICommand>(); commandExecutionManager.ExecuteCommand(commandMock.Object); commandExecutionManager.Undo(); commandMock.Verify(c => c.Undo(), Times.Once()); }
public void Redo_PerformsRedo() { var commandExecutionManager = new CommandExecutionManager(); var commandMock = new Mock <ICommand>(); commandExecutionManager.ExecuteCommand(commandMock.Object); commandExecutionManager.Undo(); commandExecutionManager.Redo(); commandMock.Verify(c => c.Execute(), Times.Exactly(2)); }
public void ExecuteCommand_ClearsUndoHistory() { var commandExecutionManager = new CommandExecutionManager(); var commandMock = new Mock <ICommand>(); commandExecutionManager.ExecuteCommand(commandMock.Object); commandExecutionManager.Undo(); commandExecutionManager.ExecuteCommand(commandMock.Object); Assert.Throws <InvalidOperationException>(() => commandExecutionManager.Redo()); }
/// <summary> /// Initializes a new instance of the <see cref="CommandExample"/> class. /// </summary> /// <param name="robot">The <see cref="IRobot"/> to use in this example.</param> /// <param name="commandFactory">The <see cref="CommandFactory"/> used to create instances /// of <see cref="ICommand"/>.</param> /// <param name="commandExecutionManager">The <see cref="CommandExecutionManager"/> used /// to manage execution of instances of <see cref="ICommand"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="robot"/>, /// <paramref name="commandFactory"/>, or <paramref name="commandExecutionManager"/> is /// <see langword="null"/>.</exception> public CommandExample( IRobot robot, CommandFactory commandFactory, CommandExecutionManager commandExecutionManager) { ParameterValidation.IsNotNull(robot, nameof(robot)); ParameterValidation.IsNotNull(commandFactory, nameof(commandFactory)); ParameterValidation.IsNotNull(commandExecutionManager, nameof(commandExecutionManager)); this.robot = robot; this.commandFactory = commandFactory; this.commandExecutionManager = commandExecutionManager; }
public void Redo_NothingToRedo_InvalidOperationException() { var commandExecutionManager = new CommandExecutionManager(); Assert.Throws <InvalidOperationException>(() => commandExecutionManager.Redo()); }
/// <summary> /// Listen and process messages /// </summary> private void ProcessOperation() { var lastCommandDate = DateTime.Now; var time = 0; _SocketReader.Clear(); _SocketReader.SleepTime = 5; _SocketReader.Socket = _Socket; _SocketReader.Timeout = CommandTimeout; NetResponse response = null; try { while (_ProcessFlag) { response = null; if (_Socket.Available > 0) { OnBeginReceiveData(); _SocketReader.Clear(); _SocketReader.Read(); OnEndReceiveData(); if (_SocketReader.LastStatus == SocketReader.ReadStatus.Success) { if (_SocketReader.Type == SocketReader.ReadType.Command) { NetCommand command = NetCommand.Parse(_SocketReader.Data); command.Id = _SocketReader.CommandId; ServerCommandsManager.PublishCommandExecute(command); command.Status = CommandStatus.Executed; if (command.Response == null) { command.Response = new NetResponse(false, "Server command could not be executed"); } Send(command.Response); } else { var command = _SendCommands[_SocketReader.CommandId] as NetCommand; if (command == null) { OnUnknownServerData(); } else { response = NetResponse.Parse(_SocketReader.Data); command.Response = response; command.Status = CommandStatus.Executed; CommandExecutionManager.PublishCommandExecute(command); _SendCommands.Remove(command.Id); } } } else { Disconnect(); } lastCommandDate = DateTime.Now; } else { NetCommand active = null; for (int k = 0; k < Commands.Count; k++) { NetCommand cd = Commands[k, true]; if (cd.Status == CommandStatus.Waiting) { active = cd; break; } } if (active != null) { Commands.Active = active; OnBeginSendingData(); Send(active); OnEndSendingData(); _SendCommands.Add(active.Id, active); } else { time = Convert.ToInt32(DateTime.Now.Subtract(lastCommandDate).TotalMilliseconds); if (KeepConnection && time >= NoopPeriod) { Commands.Add(new NetCommand(CommandNames.NOOP)); } else { if (time > ConnectionTimeout) { break; } } Thread.Sleep(10); } } } } catch (SocketException ex) { if (ex.NativeErrorCode != 0x2745 && ex.NativeErrorCode != 0x2714) { throw ex; } } catch (Exception ex) { OnSystemError(ex); } finally { Disconnect(); } }