Beispiel #1
0
        public async void DeleteTodoFromTodoListInDb()
        {
            // Setup our database
            // Set values
            DbContextOptions <TodosDBContext> options = new DbContextOptionsBuilder <TodosDBContext>().UseInMemoryDatabase("DbCanAddTodoToTodoList").Options;

            using (TodosDBContext context = new TodosDBContext(options))
            {
                // Arrange
                TodoList TodoList = new TodoList();
                TodoList.Name = "School";
                context.TodoList.Add(TodoList);
                context.SaveChanges();

                Todo Todo = new Todo();
                Todo.Name       = "Finish Homework";
                Todo.TodoListID = TodoList.ID;
                context.Todos.Add(Todo);

                await context.SaveChangesAsync();

                // Act
                context.Todos.Remove(Todo);
                await context.SaveChangesAsync();


                var TodoListName = await context.TodoList.FirstOrDefaultAsync();

                // Assert
                Assert.Empty(TodoListName.Todos);
            }
        }
        public async Task <IActionResult> Post([FromBody] TodoList toDoList)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _context.TodoList.AddAsync(toDoList);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetToDoList", new { id = toDoList.ID }, toDoList));
        }