c# – 错误单元测试webapi控制器
我正在使用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()); 被执行我遇到异常
我使用的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 解决方法
您需要添加一个
assembly redirect:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <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> </assemblyBinding> </runtime> </configuration> (假设Newtonsoft.Json的装配版本正好是6.0.0.0) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |