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); }
public IActionResult Index(TodoItemViewModel model) { if (ModelState.IsValid) { _todoItemService.Add(_mapper.Map <TodoItem>(model)); } return(RedirectToAction("Index")); }
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)); }
public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem todoItem) { await _todoItemService.Add(todoItem); return(CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem)); }
public async Task <TodoItem> Post([FromBody] TodoCreateRequest item) { return(await _todoItemService.Add(_mapper.Map <TodoItem>(item))); }
public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem todoItem) { var createdItem = await _todoItemService.Add(todoItem); return(CreatedAtAction(nameof(GetTodoItem), new { id = createdItem.Id }, createdItem)); }