I'm using NUnit
and RhinoMocks
for unit testing on the (WebApi) project.
There is a method I'm trying to write test for, which is supposed to add an item to HttpContext.Current.Items.
public override void OnActionExecuting(HttpActionContext actionContext)
{
HttpContext.Current.Items.Add("RequestGUID", Guid.NewGuid());
base.OnActionExecuting(actionContext);
}
I have no idea how can I make HttpContext.Current.Items
available to the method when ran from within a test method. How can I achieve this?
Also, how can I check if the item has been added (what kind of assertion can/should I use)
You don't need to refactor your code\use
RhinoMocks
at all for testing it.Your UT should be similar to the following example:
BTW, you can split this test to 2:
Guid.Empty