コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 private void ValidateModel(EditedFoodCategory model)
 {
     if (SearchByName(model.Name) == null)
     {
         response.IsValid = true;
     }
     else
     {
         response.IsValid    = false;
         response.StatusCode = 400;
     }
 }
コード例 #5
0
        public IActionResult Create([FromBody] EditedFoodCategory model)
        {
            IActionResult response;

            try
            {
                response = _responseHandler.ProcessResponse(_foodCategoryManager.Create(model));
            }catch (Exception e)
            {
                response = BadRequest(e);
            }
            return(response);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 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();
     }
 }
コード例 #8
0
        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);
        }