public void CreateProduct_ShouldThrowBadRequestException(string title, string descirption, string imageURL, double price, int[] dts, string vendorUID) { ProductsLogic logic = new ProductsLogic(new MockUnitOfWork()); Assert.Throws <BadRequestException>(() => logic.CreateProduct(title, descirption, imageURL, price, dts, vendorUID)); }
public IActionResult CreateProduct(ProductCreationVM product) { try { _logic.CreateProduct(product.Title, product.Description, product.ImageURL, product.Price, product.DietaryTypeIds, product.VendorUID); return(Ok()); } catch (BadRequestException e) { return(BadRequest(new HttpErrorResponse() { Message = e.Message, Subject = e.Subject })); } catch (NotFoundException e) { return(NotFound(new HttpErrorResponse() { Message = e.Message, Subject = e.Subject })); } catch (Exception e) { //Log Error return(StatusCode(500, new HttpErrorResponse() { Message = "Internal Error Occurred", Subject = "Internal" })); } }
public void CreateProduct_ShouldSucceed(string title, string descirption, string imageURL, double price, int[] dts, string vendorUID) { ProductsLogic logic = new ProductsLogic(new MockUnitOfWork()); logic.CreateProduct(title, descirption, imageURL, price, dts, vendorUID); Assert.True(true); }
public IHttpActionResult CreateProduct(string token, int userId, Product product) { if (!ModelState.IsValid || !ApplicationHelper.IsTokenValid(token, userId)) { return(Content(HttpStatusCode.BadRequest, "BadRequest")); } var result = ProductsLogic.CreateProduct(product); if (!result.Success) { ApplicationHelper.Log(result.Message); } return(result.Success ? Content(HttpStatusCode.OK, "OK") : Content(HttpStatusCode.InternalServerError, result.Message)); }