Courses.Buisness.CategoryService.Edit C# (CSharp) Method

Edit() public method

Обновление категории
public Edit ( CategoryViewModel categoryView ) : void
categoryView CategoryViewModel
return void
        public void Edit(CategoryViewModel categoryView)
        {
            categoryView.UpdatedDate = DateTime.Now;
            Category category = Convert(categoryView);
            if (categoryView.ParentCategoryId == 0)
                category.ParentCategory = null;
            else
            {
                category.ParentCategory = categoryRepository.Get(categoryView.ParentCategoryId.Value);
            }
            categoryRepository.Update(category);
        }

Usage Example

 public void EditTest()
 {
     ICategoryService _categoryService = new CategoryService(new CategoryRepository(), new CategoryFilterFactory());
     CategoryViewModel _categoryViewModel = GetCategoryViewModel();
     _categoryService.Add(_categoryViewModel);
     _categoryViewModel.Description = "otherDescription";
     _categoryService.Edit(_categoryViewModel);
     bool actual, expected = true;
     if(_categoryService.GetByID(1).Description.CompareTo("otherDescription") == 0)
     {
         actual = true;
     }
     else
     {
         actual = false;
     }
     Assert.AreEqual(expected, actual);
 }