I am trying to unit-test a piece of code that gets called from a WebAPI (OData) controller and takes in an HttpControllerContext:
public string MethodToTest(HttpControllerContext context)
{
string pub = string.Empty;
if (context != null)
{
pub = context.Request.RequestUri.Segments[2].TrimEnd('/');
}
return pub;
}
To Unit-test this i need an HttpControllerContext object. How should i go about it? I was initially trying to stub it with Microsoft Fakes, but HttpControllerContext doesnt seem to have an interface (why??), so thats doesnt seem to be an option. Should i just new up a new HttpControllerContext object and maybe stub its constructor parameters? Or use the Moq framework for this (rather not!)