Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Mocking the Request in GlassController
public class GlassControllerHttpContextTests
public void GlassController_can_get_query_string_from_http_context_mock()
// Arrange
var testHarness = new GlassControllerTestHarness();
NameValueCollection nvc = new NameValueCollection();
nvc.Add("fred", "flintstone");
// Act
var result = testHarness.GlassController.HttpContext.Request.QueryString["fred"];
// 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.