public HttpResponseMessage Post(CreateTodoListModel model) { if (ModelState.IsValid) { // Bind the model to a TodoList object var mapper = new CreateTodoListMapper(); mapper.Configure(); var todoList = mapper.Map(model); // Create the todoList var createTodoListHandler = new CreateTodoListHandler(); createTodoListHandler.Handle(todoList); // Map the todoList to the todoList result var mapperResult = new TodoListMapper(); mapperResult.Configure(); var todoListResult = mapperResult.Map(todoList); // Return the todoListResult var response = Request.CreateResponse <TodoListResult>(HttpStatusCode.Created, todoListResult); return(response); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ModelState)); }
public async System.Threading.Tasks.Task CreateTodoList_creates_a_valid_todolistAsync() { using (var context = new TodoListContext(InMemoryOptions())) { var logger = GetMockedLogger(); var handler = new CreateTodoListHandler(context, logger); var id = await handler.Handle(new CreateNewTodoListCommand("A new todo list"), default(CancellationToken)); Assert.Equal(1, id); Assert.Equal("A new todo list", context.TodoLists.Where(t => t.Id == 1).SingleOrDefault().Name); } }