public void AddNewTodoNegativeTest() { fixture.MockRepo.Setup(t => t.Create(It.IsAny <Todo>())); var todoService = new TodoService(fixture.MockRepo.Object); Assert.Throws <Exception>(() => todoService.AddNewTodo(null)); }
public ActionResult AddNewTopic(string topic) { _todoService.AddNewTodo(topic); TodoListServiceModel serviceVM = _todoService.GetShow(); return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(serviceVM))); }
public void AddNewTodoPostiveTest() { fixture.MockRepo.Setup(t => t.Create(It.IsAny <Todo>())); var todoService = new TodoService(fixture.MockRepo.Object); todoService.AddNewTodo(CreateTodo("test")); fixture.MockRepo.Verify(r => r.Create(It.IsAny <Todo>()), Times.Once); }
public async Task <ActionResult <ToDoDTO> > PostTodo(Todo todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { return(Ok(await _todoService.AddNewTodo(todo))); } catch (ArgumentException exception) { _logger.LogError(exception.Message); return(BadRequest(exception.Message)); } catch (Exception exception) { _logger.LogCritical(exception.Message); return(BadRequest(exception.Message)); } }