鼹鼠重定向不起作用
我在单元测试中使用 Moles 将调用重定向到日志记录应用程序块(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 调用会引发配置异常,因为它尝试从配置文件加载日志配置。
我是否缺少一些简单的东西,或者这应该像我写的那样工作?
I am using Moles in a unit test to redirect calls to a logging application block (a wrapped version of the EntLib), and its working for some methods but not all.
This is the test init method where the delegates are getting setup...
[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));
};
}
This is the method signatures that are redirected (from object explorer).
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
The ExceptionEvent and CriticalEvent are able to log to the redirected output location correctly, however the DebugEvent is not. The DebugEvent call throws a configuration exception because its trying to load the logging configuration from the config file.
Is there something simple I am missing, or should this work as I have it written?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,这不是上面代码的直接问题。
我有一个 [ClassInitialize] 正在调用日志记录调用,并且总是在 [TestInitialize] 之前触发。
将 [TestInitialize] 的内容移动到 [ClassInitialize] 的开头修复了该问题。
Turned out not to be a direct problem with the above code.
I had a [ClassInitialize] that was invoking the logging calls, and that always fires before the [TestInitialize].
Moving the content of the [TestInitialize] to the beginning of the [ClassInitialize] fixed the problem.