public void Create_bad_test() { EditedFoodCategory category = new EditedFoodCategory() { Name = "Category invalid test" }; FoodCategoriesController controller = GetFoodCategoriesController(doNotThrowException); var response = controller.Create(category).GetType().Name; Assert.AreEqual("BadRequestObjectResult", response); }
public void Create_return_ok() { IUnitOfWork unitOfWork = new UnitOfWorkMock(); IFoodsCategories foodCategoriesManager = new FoodsCategories(unitOfWork); EditedFoodCategory category = new EditedFoodCategory() { Name = "New category" }; var response = foodCategoriesManager.Create(category); Assert.IsTrue(response.IsValid); }
public void Create_catch_exception() { EditedFoodCategory category = new EditedFoodCategory() { Name = "Exception" }; FoodCategoriesController controller = GetFoodCategoriesController(throwException); var response = controller.Create(category) as BadRequestObjectResult; var message = response.Value.GetType().Name; Assert.AreEqual("Exception", message); }
private void ValidateModel(EditedFoodCategory model) { if (SearchByName(model.Name) == null) { response.IsValid = true; } else { response.IsValid = false; response.StatusCode = 400; } }
public IActionResult Create([FromBody] EditedFoodCategory model) { IActionResult response; try { response = _responseHandler.ProcessResponse(_foodCategoryManager.Create(model)); }catch (Exception e) { response = BadRequest(e); } return(response); }
public void Create_return_bad() { IUnitOfWork unitOfWork = new UnitOfWorkMock(); IFoodsCategories foodCategories = new FoodsCategories(unitOfWork); EditedFoodCategory category = new EditedFoodCategory() { Name = "Registered category" }; var response = foodCategories.Create(category); Assert.AreEqual(response.StatusCode, 400); Assert.IsFalse(response.IsValid); }
public FoodsCategoriesResponse Create(EditedFoodCategory model) { //TODO: Eliminar el true y cambiarlo por el metodo que verifica que el usuario si tenga los permisos para realizar esta acción if (true) { ValidateModel(model); Create(model.Name); return(response); } else { throw new Exception(); } }
public FoodsCategoriesResponse Create(EditedFoodCategory model) { FoodsCategoriesResponse response = new FoodsCategoriesResponse(); if (_throwException) { throw new Exception(); } if (model.Name == "Category valid test") { response.IsValid = true; } else { response.IsValid = false; } return(response); }