Mocking the Request in GlassController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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