我更新到 MVC4 的最终版本,现在我的测试因以下错误而失败:
System.MissingMethodException : Method not found: 'Void System.Net.Http.ObjectContent`1..ctor(!0, System.Net.Http.Formatting.MediaTypeFormatter, System.Net.Http.Headers.MediaTypeHeaderValue)'.
at System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration)
在我的单元测试中(它正在使用 RC 版本):
var configuration = new HttpConfiguration();
var request = new HttpRequestMessage();
var controller = ClassUnderTest;
controller.Request = request;
controller.Request.Properties["MS_HttpConfiguration"] = configuration;
当我运行测试时,控制器内的这行代码出现异常:
return Request.CreateResponse(HttpStatusCode.Created, myObj);
我尝试了不同的方法,但无法修复测试。有任何想法吗?