鼹鼠重定向不起作用
本文关键字:不起作用 重定向 鼹鼠 | 更新日期: 2023-09-27 18:06:57
我在单元测试中使用mole来重定向对日志应用程序块(EntLib的包装版本)的调用,它适用于某些方法,但不是全部。
这是测试初始化方法,委托在这里得到设置…
[TestInitialize()]
public void TestInit()
{
Common.Logging.Moles.MExceptionEvent.LogExceptionStringStringStringString = delegate(Exception ex, string a, string b, string c, string d)
{
Debug.WriteLine(String.Format("Exception occurred in test context '{0}' : {1} ", TestContext.TestName, ex.ToString()));
};
Common.Logging.Moles.MCriticalEvent.LogStringStringTraceEventTypeStringString = delegate(string a, string b, TraceEventType tet, string c, string d)
{
Debug.WriteLine(String.Format("Critical Event occurred in test context '{0}' : {1} ", TestContext.TestName, a));
};
Common.Logging.Moles.MDebugEvent.LogStringStringTraceEventTypeStringString = delegate(string a, string b, TraceEventType tet, string c, string d)
{
Debug.WriteLine(String.Format("Debug Event occurred in test context '{0}' : {1} ", TestContext.TestName, a));
};
}
这是重定向的方法签名(从对象资源管理器)。
Public Shared Sub Log(exc As System.Exception, Optional sessionId As String = "", Optional msg As String = "", Optional encoreNamespace As String = "", Optional methodName As String = "")
Member of Common.Logging.ExceptionEvent
Public Shared Sub Log(msg As String, Optional sessionId As String = "", Optional severity As System.Diagnostics.TraceEventType = Information, Optional encoreNamespace As String = "", Optional methodName As String = "")
Member of Common.Logging.CriticalEvent
Public Shared Sub Log(msg As String, Optional sessionId As String = "", Optional severity As System.Diagnostics.TraceEventType = Information, Optional encoreNamespace As String = "", Optional methodName As String = "")
Member of Common.Logging.DebugEvent
ExceptionEvent和CriticalEvent能够正确地记录到重定向的输出位置,但是DebugEvent不能。DebugEvent调用抛出一个配置异常,因为它试图从配置文件加载日志配置。
是否有一些简单的我错过了,或者应该这个工作,因为我有它写?
结果不是上面代码的直接问题。
我有一个[ClassInitialize]调用日志调用,它总是在[TestInitialize]之前触发。
将[TestInitialize]的内容移到[ClassInitialize]的开头可以解决这个问题。