moqContext = new Mock<HttpContextBase>();
moqRequest = new Mock<HttpRequestBase>();
moqRequest.Setup(x => x.QueryString).Returns(new NameValueCollection {{"email", "bad@gmail.com"}});
moqRequest.Setup(x => x.HttpMethod).Returns("Get");
moqRequest.Setup(x => x.Headers).Returns(new System.Net.WebHeaderCollection
{
{"Host", "localhost"},
{"Content-MD5", "123456abcd"},
{"Content-Type", "application/x-www-form-urlencoded"},
{"Date", DateTime.Now.ToString(CultureInfo.CurrentCulture)},
});
moqContext.Setup(x => x.Request).Returns(moqRequest.Object);
ConfidentialeController controller = new ConfidentialeController{ControllerContext = new HttpControllerContext()};
我无法将我的moqContext设置为构造函数HttpControllerContext()两种不同的类型
答案 0 :(得分:0)
如果您的目标是单元测试ASP.NET Web API 2控制器,我建议您按照官方文档中的示例进行操作:Unit Testing Controllers in ASP.NET Web API 2。
希望有所帮助。