最佳答案
I have a function in a controller that I am unit testing that expects values in the header of the http request. I can't initialize the HttpContext because it is readonly.
My controller function expects a http request header value for "device-id"
[TestMethod]
public void TestValuesController()
{
ValuesController controller = new ValuesController();
//not valid controller.HttpContext is readonly
//controller.HttpContext = new DefaultHttpContext();
var result = controller.Get();
Assert.AreEqual(result.Count(), 2);
}
Is there a straight-forward way to do this without using a third party library?