示例#1
0
        public async Task <IActionResult> GetResourceByIdAsync(int id)
        {
            var command = new GetCategoryById(id);
            var result  = await _mediator.Send(command);

            if (result != null)
            {
                return(Ok(result));
            }
            else
            {
                return(NoContent());
            }
        }
示例#2
0
        public void WhenExistsIdShouldInvokeGetCategoryByIdOnlyOnceTime()
        {
            //Arrange
            var categoryId = 20;
            var command    = new GetCategoryById(categoryId);

            var mock = new Mock <IToDoTaskRepository>();

            var repository = mock.Object;

            var handler = new GetCategoryByIdHandler(repository);

            //Act
            handler.Execute(command);

            //Assert
            mock.Verify(r => r.GetCategoryById(categoryId), Times.Once());
        }
        public IActionResult Post(Models.InsertToDoTask model)
        {
            var categoryCommand = new GetCategoryById(model.CategoryId);
            var category        = new GetCategoryByIdHandler(_repository).Execute(categoryCommand);

            if (category == null)
            {
                return(NotFound("Categoria não encontrada!"));
            }

            var command = new InsertToDoTask(model.Title, category, model.Deadline);
            var handler = new InsertToDoTaskHandler(_repository, _logger);
            var result  = handler.Execute(command);

            if (result.IsSuccess)
            {
                return(Ok());
            }

            return(StatusCode(500));
        }
 public Category Execute(GetCategoryById command)
 {
     return(_repository.GetCategoryById(command.Id));
 }