public void HandleCommand_ShouldAddTaskToRepository()
        {
            // Arrange
            var taskRepository = new InMemoryTaskRepository();

            var addCommandHandler = new AddCommandHandler(taskRepository);

            // Act
            addCommandHandler.HandleCommand(new AddCommand("tasktitle"));

            // Assert
            Assert.That(taskRepository.GetAll(), Is.Not.Empty);
        }
Example #2
0
        static void Main(string[] args)
        {
            var commandProcessor = new CommandProcessor();
            
            var taskRepository = new InMemoryTaskRepository();

            commandProcessor.RegisterCommandHandler(new HelpCommandHandler(Console.Out));
            commandProcessor.RegisterCommandHandler(new QuitCommandHandler());
            commandProcessor.RegisterCommandHandler(new ViewCommandHandler(taskRepository, Console.Out));
            commandProcessor.RegisterCommandHandler(new AddCommandHandler(taskRepository));
  
            var timeLog = new TimeLog(commandProcessor);
            timeLog.Run();
        }
        public void HandleCommand_ShouldAddTaskWithTitle()
        {
            // Arrange
            const string taskTitle = "tasktitle";

            var taskRepository = new InMemoryTaskRepository();

            var addCommandHandler = new AddCommandHandler(taskRepository);

            // Act
            addCommandHandler.HandleCommand(new AddCommand(taskTitle));

            // Assert
            Assert.That(taskRepository.GetAll().First().Title, Is.EqualTo(taskTitle));
        }
        public void HandleCommand_NoExistingTasksShouldAddTaskNumberOne()
        {
            // Arrange
            const string taskTitle = "tasktitle";

            var taskRepository = new InMemoryTaskRepository();

            var addCommandHandler = new AddCommandHandler(taskRepository);

            // Act
            addCommandHandler.HandleCommand(new AddCommand(taskTitle));

            // Assert
            Assert.That(taskRepository.GetAll().Last().Number, Is.EqualTo(1));
        }
        public void HandleCommand_OneTask_OutputsOneTaskToWriter()
        {
            // Arrange
            const string title1 = "fwef";
            const string title2 = "fwefewf";
            var taskRepository = new InMemoryTaskRepository();
            taskRepository.Add(new Task(123, title1));
            taskRepository.Add(new Task(456, title2));

            var stringWriter = new StringWriter();
            var viewCommandHandler = new ViewCommandHandler(taskRepository, stringWriter);

            // Act
            viewCommandHandler.HandleCommand(new ViewCommand());

            // Assert
            var textOutput = stringWriter.GetStringBuilder().ToString();
            Assert.That(textOutput, Is.StringContaining("123"));
            Assert.That(textOutput, Is.StringContaining("456"));
            Assert.That(textOutput, Is.StringContaining(title1));
            Assert.That(textOutput, Is.StringContaining(title2));
        }