Ejemplo n.º 1
0
        public async Task UpdateCategoryById_NotfoundResult()
        {
            int notfountId    = 696969;
            var categoryModel = new CategoryFormVm {
                Name = "UpdateName"
            };
            var controller = new CategoriesController(_dbContext);
            var result     = await controller.UpdateCategory(notfountId, categoryModel);

            Assert.IsType <NotFoundResult>(result);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> CreateCategory([FromForm] CategoryFormVm model)
        {
            var category = new Category
            {
                CategoryName = model.Name
            };

            _dataContext.Categories.Add(category);
            await _dataContext.SaveChangesAsync();

            return(Ok(category.CategoryName));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> UpdateCategory(int id, [FromForm] CategoryFormVm model)
        {
            var category = await _dataContext.Categories.FirstOrDefaultAsync(x => x.CategoryID == id);

            if (category == null)
            {
                return(NotFound());
            }
            category.CategoryName = model.Name;
            await _dataContext.SaveChangesAsync();

            return(Accepted());
        }
Ejemplo n.º 4
0
        public async Task CreateCategory_ReturnCategoryModel()
        {
            var category = new CategoryFormVm
            {
                Name = "Test"
            };
            var controller = new CategoriesController(_dbContext);
            var result     = await controller.CreateCategory(category);

            var acceptedResult = Assert.IsType <OkObjectResult>(result);


            Assert.Equal("Test", acceptedResult.Value);
        }
Ejemplo n.º 5
0
        public async Task UpdateCategoryById_FoundResult()
        {
            _dbContext.Categories.Add(new Category
            {
                CategoryID   = 999,
                CategoryName = "TestName"
            });
            await _dbContext.SaveChangesAsync();

            int    categoryID        = 666;
            string name              = "TestAgain";
            var    duplicateCategory = new CategoryFormVm {
                Name = "TestAgain"
            };
            var controller = new CategoriesController(_dbContext);
            var result     = await controller.UpdateCategory(categoryID, duplicateCategory);

            Assert.Equal(name, duplicateCategory.Name);
        }
 public async Task <IActionResult> CreateCategory(CategoryFormVm CategoryFormVm)
 {
     return(HandleResult(await Mediator.Send(new Create.Command {
         categoryFormVm = CategoryFormVm
     })));
 }