November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Havre you tried passing the AccessLevel.NoAccess
into Save action?
cmsContext.CategoryRepository.Save(authorJohn, AccessLevel.NoAccess);
Hello There,
I am using EpiServer CMS version 11.14. I have created a unit test project and I am using FakeItEasy to create Fake instances and Nunit for unit test. At one place I have to create CMS categories in category repository and have to attach category to page. By following code I am trying to create categories, but couldn't able to save it.
-- Faking --
public CategoryRepository CategoryRepository { get; set; }
A.CallTo(() => ServiceLocator.Current.GetInstance<CategoryRepository>()).Returns(this.CategoryRepository);
--- Category Creation --
var rootCategory = cmsContext.CategoryRepository.GetRoot();
rootCategory = rootCategory.CreateWritableClone();
rootCategory.Name = "Root";
rootCategory.ID = 0;
cmsContext.CategoryRepository.Save(rootCategory);
var parentCategory = new Category(rootCategory, SiteConstants.AuthorsCategoryName)
{
Selectable = true,
Name = SiteConstants.AuthorsCategoryName,
ID = 1
};
cmsContext.CategoryRepository.Save(parentCategory);
var authorJohn = new Category(parentCategory, "John")
{
Selectable = true,
Name = "John",
ID = 2
};
cmsContext.CategoryRepository.Save(authorJohn);
var testCat = cmsContext.CategoryRepository.Get("John");
// testCat - give me category with 0 id.
Please help me out.