I tried to set PageContext using  RenderingContext.EnterContext but didn’t work

using (RenderingContext.EnterContext(new Rendering(), contextItem))

I have set it using  ContextService.Get().Push(pageContext);

Here is the code, which may help you

using (Db db = new Db using (Db db = new Db {


new DbItem(“Test Item”, ID.NewID, ID.NewID)


new DbField(“Sample Field”)


Value =”Unit Testing”




var pageContext = new PageContext


Item = db.GetItem(“/sitecore/content/Test Item”)


Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Fake DB

How to do unit testing for media items in Sitecore + xUnit testing : Fake DB

Unit testing in Sitecore is a tricky one since you need create an items in Fake dB. I didn’t find much information about Media items unit testing and below piece of code may help you! Read more…

Sitecore 8.2

Mocking a reference field in Sitecore Fake DB for Unit test cases

I’m working on Unit test cases and mocking a reference field could be a complex task. Here is the code, which may help you [Fact] public void ReferenceFieldMockingTest() { ID newTemplateId = ID.NewID; ID referenceItemId Read more…


Sitecore 8 Experience Editor: A serious error has occurred please contact the administrator

In Sitecore version 8.0 rev. 150621 I am experiencing issue when clicking on Experience Editor or Preview button in the Publish tab. The experience editor opens with the “A serious error has occurred please contact Read more…