G
Guest
I am working on a web/webservice application that has a service layer. Most
service methods will perform an access-check before executing. This check
uses the IPrincipal credentials available in HttpContext.Current. This works
great.
My issue is that I need to write unit tests for those service methods. These
tests then run outside of IIS, thus there is no HttpContext.Current
available - and the servicemethod will not execute.
The two courses of action that seem possible:
a) somehow "forge" an HttpContext, so that the code will work unaltered
or
b) wrap the call to HttpContext.Current, so that I can supply a different
credential for testing purposes.
is a) a viable solution? or is there a substantial amount code that must be
written in order to set something like that up? The nice thing would be if
there was some simple way to create an HttpContext and set the
HttpContext.Current to this context - but I fear it may not be that simple.
Thanks
service methods will perform an access-check before executing. This check
uses the IPrincipal credentials available in HttpContext.Current. This works
great.
My issue is that I need to write unit tests for those service methods. These
tests then run outside of IIS, thus there is no HttpContext.Current
available - and the servicemethod will not execute.
The two courses of action that seem possible:
a) somehow "forge" an HttpContext, so that the code will work unaltered
or
b) wrap the call to HttpContext.Current, so that I can supply a different
credential for testing purposes.
is a) a viable solution? or is there a substantial amount code that must be
written in order to set something like that up? The nice thing would be if
there was some simple way to create an HttpContext and set the
HttpContext.Current to this context - but I fear it may not be that simple.
Thanks