public void TestAddProductOptionFail() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductRepository productRepository = new ProductRepository(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); ProductsController productController = new ProductsController(productRepository, productOptionRepository); Func <Task> act = async() => await productController.AddProductOptionsForProdId(new ProductOptionDto { Id = productOptions[0].Id }); act.Should().Throw <HttpResponseException>(); context.Database.EnsureDeleted(); } }