Compared to my last question on Mocking the HttpContext, I had to change the method being tested to
public override void OnActionExecuting(HttpActionContext actionContext)
{
HttpContext.Current.GetOwinContext().Set("RequestGUID", NewId.NextGuid());
base.OnActionExecuting(actionContext);
}
Now I need to figure out how to mock the
HttpContext.Current.GetOwinContext()
,
So I could write a stub for the Set()
method, or generally being able to test this particular line. How can I do this?
I have read this article, but in your case, I think that doing such a thing would be an overkill..
Since
GetOwinContext()
return an interface all you have to do is to separate this call from the method, doing such a thing has 2 problems:OnActionExecuting()
is owned by an attribute class.GetOwinContext()
is a static method.The best 2 solutions that I can offer you is:
GetOwinContext()
to a virtual method and then use PartialMock technique(This technique is usually in use for abstract classes):Let's say that
MyCustonAttributte
is your attribute:Then your UT will be: