Exemple #1
0
        public async Task CheckGetTodoListHandler()
        {
            var pageSize           = 10;
            var pageIndex          = 0;
            var getTodoListRequest = new GetTodoListHandler.GetTodoList(pageSize, pageIndex);
            var getTodoListResult  = await _getTodoListHandler.Handle(getTodoListRequest, CancellationToken.None);

            getTodoListResult.Should().BeOfType <ObjectResult>();
            var objectResult = (ObjectResult)getTodoListResult;

            objectResult.Value.Should().BeOfType <PagedResult <TodoItemDTO> >().Which.Items.Should()
            .BeOfType <List <TodoItemDTO> >();

            objectResult.Value.Should().BeOfType <PagedResult <TodoItemDTO> >().Which.Count.Should().Be(0);
            objectResult.StatusCode.Should().BeNull();

            var dto = new TodoItemDTO();
            var createTodoRequest = new CreateTodoHandler.CreateTodo(dto);
            await _createTodoHandler.Handle(createTodoRequest, CancellationToken.None);

            getTodoListRequest = new GetTodoListHandler.GetTodoList(pageSize, pageIndex);
            getTodoListResult  = await _getTodoListHandler.Handle(getTodoListRequest, CancellationToken.None);

            var newObjectResult = (ObjectResult)getTodoListResult;

            newObjectResult.Value.Should().BeOfType <PagedResult <TodoItemDTO> >().Which.Count.Should().Be(1);
        }
Exemple #2
0
        public void Dado_um_comando_invalido_deve_interromper_a_execucao()
        {
            // MOQ
            var result = (GenericCommandResult)_handler.Handle(_invalidCommand);

            Assert.False(result.Success);
        }
Exemple #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));
        }