开发者

Mole redirect not working

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 locat开发者_如何转开发ion 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜