我正在使用AspNet Web Api Client 5.0,我正在尝试对web api控制器进行单元测试。
var encservice = new EncryptionService();
var acctservice = FakeServices.GetAccountService();
var controller = new AccountController(acctservice, encservice);
controller.Request = new HttpRequestMessage();
当代码
controller.Request.SetConfiguration(new HttpConfiguration());
执行后我遇到了异常
信息:无法加载文件或程序集'Newtonsoft.Json,Version = 4.5.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed'或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)
资源: System.Net.Http.Formatting
堆栈跟踪:at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() 在System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() 在System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor() 在System.Web.Http.HttpConfiguration.DefaultFormatters() 在System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection路由) 在System.Web.Http.HttpConfiguration..ctor() 在c:\ PremiumProjectsCollection \ emr \ src \ EMRAzure \ EMRAzure \ EMR.Test \ Controller \ AccountControllerTest.cs中的EMR.Test.Controller.AccountControllerTest.Should_Get():第34行
我使用的newsoft.json的版本是6.0
我的配置文件中也有一个程序集重定向
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
我使用的测试运行器是 MStest,VS2012