bool ValidateProduct(MODELS.Product product) { if (string.IsNullOrWhiteSpace(product.Name) || string.IsNullOrWhiteSpace(product.Description) || product.Price <= 0) { return(false); } return(true); }
public void TestAddProductSuccess() { var product = new MODELS.Product { Id = 0, Name = "GoPro", Description = "Camera", Price = 35000.00, Count = 5 }; MockRepository.GenerateMock <IProduct>().Expect(x => x.AddProduct(new MODELS.Product())).Return(1); var result = _productbdl.AddProduct(product); Assert.True(result > 0); }
public IActionResult DeleteProduct(MODELS.Product product) { var success = _bdlProduct.DeleteProduct(product); if (success == 1) { return(StatusCode((int)HttpStatusCode.Created, 1)); } else { return(StatusCode((int)HttpStatusCode.BadRequest)); } }
int IProduct.UpdateProduct(MODELS.Product product) { try { if (ValidateProduct(product)) { return(_productRepository.UpdateProduct(product)); } else { return(0); } } catch (Exception) { return(-1); } }
int IProduct.DeleteProduct(MODELS.Product product) { return(_productRepository.DeleteProduct(product)); }