Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

Not able to save the CMS category using fake respository

$
0
0

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.


Viewing all articles
Browse latest Browse all 8020

Trending Articles