private void CreateNewTask(Command command) { Task task = taskHandler.CreateNewTask(); task.Name = command.Argument; taskHandler.SaveTasks(); command.AffectedTask = task; }
private void CompleteTask(Command command) { Task task = taskHandler.FindTask(command.Argument); taskHandler.CompleteTask(task); taskHandler.SaveTasks(); command.AffectedTask = task; }
public void Execute(Command command) { // This has to be refactoring, it is not extensible AT ALL! ^_^ if (command.IsCreateNewTask()) CreateNewTask(command); else if (command.IsCompleteTask()) CompleteTask(command); }
public void Interpret_WhenGivenALineToInterpret_ShouldParseItUsingTheParser() { // Arrange string line = "create new task"; var command = new Command(); parser.Setup(p => p.Parse(line)).Returns(command); var interpreter = GetInterpreter(); // Act interpreter.Interpret(line); // Assert parser.Verify(x => x.Parse(line)); }
public void Interpret_WhenGivenALineToInterpretAndWasntParsedCorrectly_ShouldNotExecuteAnyCommand() { // Arrange string line = "line that cannot be parsed"; var command = new Command { IsValid = false }; parser.Setup(p => p.Parse(line)).Returns(command); var interpreter = GetInterpreter(); // Act interpreter.Interpret(line); // Assert executer.Verify(e => e.Execute(command), Times.Never()); }
public void Parse_WhenGivenACompleteTaskCommand_ShouldParseItAppropriately() { // Arrange var line = "complete task do the dishes"; var parser = GetParser(); // Act var command = parser.Parse(line); // Assert Command expectedCommand = new Command { Line = line, Verb = "complete task", Argument = "do the dishes", Response = "task completed!", IsValid = true }; Assert.AreEqual(expected: expectedCommand, actual: command); }
public void InterpretCommand_WhenGivenACommandAndInterpretingIt_ShouldReturnJsonSerializedCommandResultOfTheInterpretation() { // Arrange var command = new CommandViewModel { Line = "create new task go to the doctor" }; var resultCommand = new Command { Line = "create new task go to the doctor", Verb = "create new task", Argument = "go to the doctor", Response = "new task created!" }; var tasksController = GetTaskController(); interpreter.Setup(i => i.Interpret(command.Line)).Returns(resultCommand); // Act var jsonResult = tasksController.InterpretCommand(command); // Assert Assert.AreEqual(expected: resultCommand, actual: jsonResult.Data); }
public void Interpret_WhenGivenALineToInterpret_ShouldExecuteIt() { // Arrange string line = "create new task do the laundry"; var command = new Command { Verb = "create new task", Argument = "do the laundry", Response = "new task created!", Line = "create new task do the laundry", IsValid = true }; parser.Setup(p => p.Parse(line)).Returns(command); var interpreter = GetInterpreter(); // Act interpreter.Interpret(line); // Assert executer.Verify(e => e.Execute(command)); }
public void Execute_WhenGivenACreateNewTaskCommand_ShouldAddTheAffectedTaskToTheCommand() { // Arrange var newTask = new Task(); var command = new Command { Verb = "create new task", Argument = "do the laundry", Line = "create new task do the laundry", Response = "created new task!", IsValid = true }; taskHandler.Setup(t => t.CreateNewTask()).Returns(newTask); var executer = GetExecuter(); // Act executer.Execute(command); // Assert Assert.AreSame(expected: newTask, actual: command.AffectedTask); }
public void Execute_WhenGivenCompleteTaskCommand_ShouldCompleteTheTaskViaTheTaskHandler() { // Arrange var taskToComplete = new Task(); var command = new Command { Verb = "complete task", Argument = "do the laundry", Line = "complete task do the laundry", Response = "task completed!", IsValid = true }; taskHandler.Setup(x => x.FindTask(command.Argument)).Returns(taskToComplete); taskHandler.Setup(x => x.CompleteTask(taskToComplete)); // Act GetExecuter().Execute(command); // Assert taskHandler.Verify(x => x.FindTask(command.Argument)); taskHandler.Verify(x => x.CompleteTask(taskToComplete)); }
public void Execute_WhenGivenACreateNewTaskCommand_ShouldCreateANewTaskViaTheTaskHandler() { // Arrange var newTask = new Task(); var command = new Command { Verb = "create new task", Argument = "do the laundry", Line = "create new task do the laundry", Response = "created new task!", IsValid = true }; taskHandler.Setup(t => t.CreateNewTask()).Returns(newTask); var executer = GetExecuter(); // Act executer.Execute(command); // Assert taskHandler.Verify(t => t.CreateNewTask()); taskHandler.Verify(t => t.SaveTasks()); }
protected bool Equals(Command other) { return string.Equals(Line, other.Line) && string.Equals(Verb, other.Verb) && string.Equals(Argument, other.Argument) && string.Equals(Response, other.Response) && Equals(AffectedTask, other.AffectedTask) && IsValid.Equals(other.IsValid); }