Beispiel #1
0
        public async Task <TodoItem> Post(
            [FromBody] CreateTodoRequest request,
            [FromServices] CreateTodoHandler handler)
        {
            var result = await handler.HandleAsync(request);

            return(result);
        }
        public CreateTodoHandlerTests()
        {
            _todoItemRepository = Substitute.For <ITodoItemRepository>();
            _busPublisher       = Substitute.For <IBusPublisher>();
            _context            = Substitute.For <ICorrelationContext>();

            _commandHandler = new CreateTodoHandler(_todoItemRepository, _busPublisher);
        }
Beispiel #3
0
        public GenericCommandResult Create(
            [FromBody] CreateTodoCommand command,
            [FromServices] CreateTodoHandler handler
            )
        {
            var user = User.Claims.FirstOrDefault(x => x.Type == "user_id")?.Value;

            command.User = user;
            return((GenericCommandResult)handler.Handle(command));
        }
Beispiel #4
0
        public HandlersTests()
        {
            var dbContext = DbContextCreate();

            _getTodoListHandler = new(dbContext);
            _createTodoHandler  = new(dbContext);
            _deleteTodoHandler  = new(dbContext);
            _putTodoHandler     = new(dbContext);
            _getTodoByIdHandler = new(dbContext);
        }
        public async Task <IActionResult> OnPostAsync(
            [FromServices] CreateTodoHandler handler)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await handler.HandleAsync(Input);

            return(RedirectToPage("/Index"));
        }
        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);
        }
Beispiel #8
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);
        }
Beispiel #9
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();
        }
Beispiel #10
0
 private static async Task CreateTodo(CreateTodo item)
 {
     var handler = new CreateTodoHandler(_db.Database);
     await handler.SendAsync(item);
 }