I've got my Fake object for HttpRequest ready (a wrapper and an interface)... since I don't need to call a constructor, how do I pass in the fake HttpRequest without breaking the interface of this method?
public static int ParseQueryInt(string key, int defaultValue)
{
NameValueCollection nvc;
if (HttpContext.Current.Request.QueryString["name"] != null)
{
//Parse strings.
}
}
EDIT: Akselson's solution is the most creative and this proof of concept worked, much to my surprise, although I also used Skeet's solution as it look more likely to work in all situations.
public class Class1
{
[Test]
public void Test()
{
HttpContext.Current = new HttpContext(
new HttpRequest("test.aspx", "http://test.com/test.aspx", "querystring=value"),
new HttpResponse(new StringWriter())
);
Assert.AreEqual(HttpContext.Current.Request.QueryString["querystring"], "value");
}
}