Exemple #1
0
        public void AddTodoItem()
        {
            Setup();
            //Arrange
            var itemCreate = new TodoItem()
            {
                Title       = "Todo 2",
                Description = "Desc 2",
                IsCompleted = false,
            };

            var itemCreated = new TodoItem()
            {
                Title       = "Todo 2",
                Description = "Desc 2",
                IsCompleted = false,
                Id          = 2
            };

            _repositoryMock.Setup(item => item.Add(itemCreate)).ReturnsAsync(itemCreated);

            //Act
            var result = _todoItemService.Add(itemCreate).Result;

            //Assert
            _repositoryMock.Verify(item => item.Add(It.IsAny <TodoItem>()), Times.Once);
            Assert.Equal(itemCreated, result);
        }
Exemple #2
0
 public IActionResult Index(TodoItemViewModel model)
 {
     if (ModelState.IsValid)
     {
         _todoItemService.Add(_mapper.Map <TodoItem>(model));
     }
     return(RedirectToAction("Index"));
 }
Exemple #3
0
        public IActionResult Post([FromBody] TodoItemModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try {
                _todoItemService.Add(_mapper.Map <TodoItem>(model));
                return(Ok(model));
            }
            catch {
            }
            return(BadRequest());
        }
        public ActionResult Create(TodoItem item)
        {
            if (ModelState.IsValid)
            {
                try {
                    todoService.Add(item);
                    todoService.SaveChanges();
                }
                catch (Exception ex) {
                    TempData["error"] = ex.Message;
                }

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Exemple #5
0
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem todoItem)
        {
            await _todoItemService.Add(todoItem);

            return(CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem));
        }
Exemple #6
0
 public async Task <TodoItem> Post([FromBody] TodoCreateRequest item)
 {
     return(await _todoItemService.Add(_mapper.Map <TodoItem>(item)));
 }
Exemple #7
0
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem todoItem)
        {
            var createdItem = await _todoItemService.Add(todoItem);

            return(CreatedAtAction(nameof(GetTodoItem), new { id = createdItem.Id }, createdItem));
        }