Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:57:56+00:00 2026-05-25T05:57:56+00:00

I am using Moles in a unit test to redirect calls to a logging

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:57:57+00:00Added an answer on May 25, 2026 at 5:57 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Test::Unit::TestCase to write some unit tests. Currently, I have a setup function
How can you verify interaction test using Moles. For example the following test is
Where can I find some GPS unit test data to validate my code? For
We are using moles 0.94 for some tests in our solution. However, every time
For some reason OpenCover is not covering tests using moles on Windows Server 2003
I want to unit test the code below. I've been working with MSTest and
I need to unit test a method that is using the System.Net.WebClient in the
I've seen samples using Moles to redirect DateTime.Now but when I tried to redirect
Anyone know where i can find some tutorials on how to unit test CRM
Using online interfaces to a version control system is a nice way to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.