Skip to content

Instantly share code, notes, and snippets.

@cardinal252
Last active September 16, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cardinal252/00f2d89eee11ad156245 to your computer and use it in GitHub Desktop.
Save cardinal252/00f2d89eee11ad156245 to your computer and use it in GitHub Desktop.
Mocking the Request in GlassController
[TestFixture]
public class GlassControllerHttpContextTests
{
[Test]
public void GlassController_can_get_query_string_from_http_context_mock()
{
// Arrange
var testHarness = new GlassControllerTestHarness();
NameValueCollection nvc = new NameValueCollection();
nvc.Add("fred", "flintstone");
testHarness.HttpContext.Request.QueryString.Returns(nvc);
// Act
var result = testHarness.GlassController.HttpContext.Request.QueryString["fred"];
// Assert
result.Should().Be("flintstone");
}
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