鼹鼠重定向不起作用

发布于 2024-12-02 00:27:50 字数 2003 浏览 1 评论 0原文

我在单元测试中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2024-12-09 00:27:50

事实证明,这不是上面代码的直接问题。

我有一个 [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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文