【问题标题】:.Net Unit test EnterpriseLibrary.ExceptionHandling issue.Net 单元测试 EnterpriseLibrary.ExceptionHandling 问题
【发布时间】:2012-04-09 23:45:12
【问题描述】:
我正在使用 EnterpriseLibrary.ExceptionHandling 版本 5 进行错误处理。在项目中完美工作。但是在项目中运行所有单元测试时出现错误:
检测程序集“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的强名称验证失败。请确保在测试设置中指定了检测后重新签名的正确密钥文件。
尽管如果我仅在调试模式下运行特定测试,则可以正常工作。
请提出建议。谢谢
【问题讨论】:
标签:
c#
.net
enterprise-library-5
vs-unit-testing-framework
【解决方案1】:
我得到了答案,因为在测试 --> 本地设置中检查了代码覆盖率。
所以我创建了一个接口来模拟异常类,比如
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
public interface IExceptionHandler
{
bool HandleException(System.Exception oex, string policy);
}
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class ExceptionHandler : IExceptionHandler
{
public bool HandleException(System.Exception oex, string policy)
{
return ExceptionPolicy.HandleException(oex, policy);
}
}