Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Mocking the GlassController context
[TestFixture] // using NSubstitute, NUnit and Fluent Assertions
public class GlassControllerContextItemTests
public void GlassController_can_set_and_get_context()
// Arrange
StubClass classToReturn = new StubClass();
var testHarness = new GlassControllerTestHarness();
// Act
var result = testHarness.GlassController.GetContextItem<StubClass>();
// Assert
public class StubClass
public class GlassControllerTestHarness
public GlassControllerTestHarness()
SitecoreContext = Substitute.For<ISitecoreContext>();
GlassHtml = Substitute.For<IGlassHtml>();
RenderingContextWrapper = Substitute.For<IRenderingContextWrapper>();
HttpContext = Substitute.For<HttpContextBase>();
GlassController = new GlassController(SitecoreContext, GlassHtml, RenderingContextWrapper, HttpContext);
public HttpContextBase HttpContext { get; private set; }
public IRenderingContextWrapper RenderingContextWrapper { get; private set; }
public IGlassHtml GlassHtml { get; private set; }
public ISitecoreContext SitecoreContext { get; private set; }
public GlassController GlassController { get; private set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.