示例#1
0
        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);
        }
示例#2
0
文件: Class1.cs 项目: robmedlock/Net
        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());
        }
示例#3
0
 // 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
     }
 }
示例#4
0
 public ActionResult Create(Product product)
 {
     productModel.Create(product);
     return(RedirectToAction("List"));
 }