public async Task Deleting_ToDo_By_Id()
        {
            /*
             * Given that I have a ToDo in the database
             * When I issue a command to delete the ToDo with that Id
             * Then I should remove the ToDo from the database
             */

            var options = new DbContextOptionsBuilder <ToDoContext>()
                          .UseInMemoryDatabase("Add_writes_to_database")
                          .Options;

            var toDoItem = new ToDoItem {
                Title = "Make delete test pass"
            };

            using (var context = new ToDoContext(options))
            {
                context.ToDoItems.Add(toDoItem);
                context.SaveChanges();
            }

            var command = new DeleteToDoByIdCommand(toDoItem.Id);
            var handler = new DeleteToDoByIdCommandHandlerAsync(options);

            await handler.HandleAsync(command);


            using (var context = new ToDoContext(options))
            {
                Assert.IsFalse(context.ToDoItems.Any(t => t.Id == toDoItem.Id));
            }
        }
Example #2
0
        public async Task <IActionResult> Delete(int id)
        {
            var deleteToDoCommand = new DeleteToDoByIdCommand(id);

            await _commandProcessor.SendAsync(deleteToDoCommand);

            return(Ok());
        }