public async Task ShouldReturnSuccess()
        {
            var todoRepository = new Mock <ITodoRepository>();

            var handler = new CreateTodoHandler(todoRepository.Object);

            var createTodo = new CreateTodo
            {
                Id       = Guid.NewGuid(),
                Title    = "I have todo something important, I just not know what",
                Deadline = new DateTime(year: 2020, month: 6, day: 13)
            };

            var result = await handler.Execute(createTodo);

            Assert.True(result.IsSuccess);
        }
        public async Task WhenAddHasFailedShouldReturnFailure()
        {
            var todoRepository = new Mock <ITodoRepository>();

            todoRepository.Setup(it => it.Add(It.IsAny <Todo>())).Returns(() => Task.FromResult(Result.Failure("Something has gone wrong")));

            var handler = new CreateTodoHandler(todoRepository.Object);

            var createTodo = new CreateTodo
            {
                Id       = Guid.NewGuid(),
                Title    = "I have todo something important, I just not know what",
                Deadline = new DateTime(year: 2020, month: 6, day: 13)
            };

            var result = await handler.Execute(createTodo);

            Assert.True(result.IsFailure);
        }
Example #3
0
        public async Task ShouldAddANewTodo()
        {
            var todoRepository = new FakeTodoRepository();

            var handler = new CreateTodoHandler(todoRepository);

            var createTodo = new CreateTodo
            {
                Id       = Guid.NewGuid(),
                Title    = "Test",
                Deadline = new DateTime(year: 2020, month: 6, day: 13)
            };

            await handler.Execute(createTodo);

            var count = await todoRepository.Count();

            Assert.Equal(1, count);
        }
Example #4
0
        public async static Task Main(string[] args)
        {
            var context = new ApplicationContext();

            var todoRepository = new EFTodoRepository(context);

            var handler = new CreateTodoHandler(todoRepository);

            Console.WriteLine("Todo title:");

            var title = Console.ReadLine();

            var createTodo = new CreateTodo
            {
                Id       = Guid.NewGuid(),
                Title    = title,
                Deadline = DateTime.Now.AddDays(1)
            };

            var result = await handler.Execute(createTodo);

            if (result.IsFailure)
            {
                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine(result.Error);

                Console.ResetColor();

                return;
            }

            await context.SaveChangesAsync();

            Console.ForegroundColor = ConsoleColor.Green;

            Console.WriteLine("Todo has been added");

            Console.ResetColor();
        }