예제 #1
0
        public async void CreateToDoListItem_ReturnsValidDto_ReturnsOKResult()
        {
            //Arrange
            var httpContext = new DefaultHttpContext();

            var items = await GetToDoListItemsFromFileAsync();

            CreateToDoItemCommand command = new CreateToDoItemCommand();

            command.Name      = "Test";
            command.Completed = false;

            var mediator = new Mock <IMediator>();

            mediator.Setup(m => m.Send(It.IsAny <CreateToDoItemCommand>(), new System.Threading.CancellationToken()))
            .Returns(Task.FromResult(items.First()));

            var controller = new ToDoListController(mediator.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = httpContext,
                }
            };

            //ACT
            var result = await controller.CreateToDoListItem(command);

            //ASSERT
            Assert.IsType <OkObjectResult>(result.Result);
            Assert.NotNull(result.Result);
        }
예제 #2
0
        public void CreateToDoListItem_ReturnsOKResult()
        {
            //Arrange
            var httpContext = new DefaultHttpContext();

            CreateToDoItemCommand command = new CreateToDoItemCommand();

            command.Name      = "Test";
            command.Completed = false;

            var mediator = new Mock <IMediator>();

            mediator.Setup(m => m.Send(It.IsAny <CreateToDoItemCommand>(), new System.Threading.CancellationToken()));

            var controller = new ToDoListController(mediator.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = httpContext,
                }
            };

            //ACT
            var result = controller.CreateToDoListItem(command);

            //ASSERT
            Assert.IsType <ActionResult <ToDoItemListDto> >(result.Result);
            Assert.Null(result.Result.Value);
        }
        public async Task <IActionResult> Post([FromBody] ToDoItemDTO item)
        {
            var createCommand = new CreateToDoItemCommand()
            {
                Title       = item.Title,
                Description = item.Description
            };

            return(Ok(await _mediator.Send(createCommand)));
        }
예제 #4
0
        public async Task <IActionResult> Create(CreateToDoItemCommand command)
        {
            if (ModelState.IsValid)
            {
                await Mediator.Send(command);

                return(View("Items"));
            }

            return(View("Create", command));
        }
예제 #5
0
        public async Task <ActionResult> AddItem(ToDoItemDTO item)
        {
            var command = new CreateToDoItemCommand(
                item.Id,
                item.Title,
                item.Description,
                item.CategoryId,
                item.DueTo,
                item.Status,
                item.Path);

            await _commandHandler.HandleAsync(command);

            return(Ok());
        }
예제 #6
0
        public async Task <IActionResult> CreateToDoItemAsync([FromBody] CreateToDoItemCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            bool commandResult = false;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var identifiedCommand = new IdentifiedCommand <CreateToDoItemCommand, bool>(command, guid);

                _logger.LogInformation("Log Information ...");

                commandResult = await _mediator.Send(identifiedCommand);
            }

            if (!commandResult)
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public async void CreateItemsHandler_IsVerifiable_ReturnsNotNullResult()
        {
            //Arrange
            var _serviceContextMock = new Mock <IServiceContext>();

            _serviceContextMock.Setup(a => a.AddToDoListItemAsync(It.IsAny <ToDoListItem>())).Verifiable();

            CreateToDoItemCommand command = new CreateToDoItemCommand();

            command.Name      = "Test";
            command.Completed = false;

            IToDoListRepository _todoListRepository = new ToDoListRepository(_serviceContextMock.Object);

            CreateToDoItemHandler handler = new CreateToDoItemHandler(_todoListRepository, _mapper);

            //Act
            var result = await handler.Handle(command, new System.Threading.CancellationToken());

            //Assert
            Assert.IsType <Guid>(result.Id);
            Assert.Matches(command.Name, result.Name);
            Assert.Equal(command.Completed, result.Completed);
        }
예제 #8
0
        public async Task <ActionResult <ToDoItemViewModel> > Create(CreateToDoItemCommand command)
        {
            var response = await Mediator.Send(command, new System.Threading.CancellationToken());

            return(Ok(response));
        }
예제 #9
0
 public async Task <ActionResult <CreateToDoItemViewModel> > Create(CreateToDoItemCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }
예제 #10
0
 public void Given_I_have_composed_an_invalid_new_ToDo()
 {
     _command = new CreateToDoItemCommand();
 }