public ActionResult <Category> Put(string id, [FromBody] Category categoryData) { try { var category = _cs.EditCategory(categoryData); return(Ok(category)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task EditCategoryShouldNotWorkForEmptyImage() { var categoriesRepo = new Mock <IRepository <Category> >(); var categoryId = Guid.NewGuid(); var categories = new List <Category>() { new Category { Name = "Jackets", Id = categoryId, Image = "1" }, new Category { Name = "Suits", Id = Guid.NewGuid() }, new Category { Name = "Something", Id = Guid.NewGuid() }, new Category { Name = "T-shirts", Id = Guid.NewGuid() } }; categoriesRepo.Setup(r => r.All()).Returns(categories.AsQueryable()); var service = new CategoriesService(categoriesRepo.Object); var categoryForEdit = new Category { Id = categoryId, Name = "Jackets Edited", Image = "" }; await service.EditCategory(categoryForEdit); Assert.Contains(categories, c => c.Name == categoryForEdit.Name); Assert.DoesNotContain(categories, c => c.Image == categoryForEdit.Image); categoriesRepo.Verify(r => r.SaveChangesAsync(), Times.Once); }