November Happy Hour will be moved to Thursday December 5th.

Not able to save the CMS category using fake respository

Vote:
 

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.

#225592
Jul 21, 2020 9:05
Vote:
 

Havre you tried passing the AccessLevel.NoAccess into Save action?

cmsContext.CategoryRepository.Save(authorJohn, AccessLevel.NoAccess);
#225633
Jul 22, 2020 3:13
- Jul 22, 2020 6:21
There is no overload method "Save" which will accept the access level parameter
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.