public void Create_Product_ShouldCreateProduct() { //arrange Product product = new Product("p11", "Hammer", 2.20); //act bool created = sut.Create(product); //assert Assert.True(created); Assert.Equal(productCount + 1, sut.Products.Count); }
static void Main(string[] args) { IAbstractEcommerceFactory factory = new SqlServerEcommerceFactory(); IAccountModel accountModel = factory.AccountModel; accountModel.Create(new Account()); IProductModel productModel = factory.ProductModel; productModel.Create(new Product()); IOrderModel orderModel = factory.OrderModel; orderModel.Create(new Order()); }
// POST: api/productService public IHttpActionResult Post([FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); //400 } try { bool added = productModel.Create(product); if (!added) { return(BadRequest("Product already exists")); } return(Created(new Uri(Request.RequestUri + product.Id), product)); } catch (Exception e) { return(InternalServerError(e)); //500 } }
public ActionResult Create(Product product) { productModel.Create(product); return(RedirectToAction("List")); }