Although you cannot make fun of HttpContext, you can configure HttpContext.Current in your test.
var req = new HttpRequest(string.Empty, "https://www.domain.tld", null); var res = new HttpResponse(null); HttpContext.Current = new HttpContext(req, res);
I am not sure which parts of the context are used by Elmah.
Third Party Editing:
ELMAH also requires System.Web.HttpContext.Current.ApplicationInstance
Dim req As System.Web.HttpRequest = New System.Web.HttpRequest(String.Empty, "https://www.domain.tld", Nothing) Dim res As System.Web.HttpResponse = New System.Web.HttpResponse(Nothing) System.Web.HttpContext.Current = New System.Web.HttpContext(req, res) System.Web.HttpContext.Current.ApplicationInstance = New System.Web.HttpApplication()
otherwise it throws an exception because the application name is NULL.
Further editing:
Here is the final code in C #:
var req = new HttpRequest(string.Empty, "https://www.domain.tld", null); var res = new HttpResponse(null); HttpContext.Current = new HttpContext(req, res) {ApplicationInstance = new HttpApplication()};
danludwig
source share