chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
There are problems with mocking Log4Net. Here's the production code:
    public class Log4NetTest
    {

        public void TestRun()
        {
            log4net.Config.XmlConfigurator.Configure();
            var log = LogManager.GetLogger(typeof(Log4NetTest));
            log.Error("Worse");
            log.Info("Dont Kid");
        }
    }

    public class Log4NetTypeMock
    {
        public static readonly ILog log
            = LogManager.GetLogger(typeof(Log4NetTypeMock))
            ;

        public static readonly Log4NetTest log4Net;
    }


Now run test two tests:
  
        [Test, Isolated]
        public void Test2()
        {
            Isolate.WhenCalled(() => Log4NetTypeMock.log4Net)
            .ReturnRecursiveFake();
            Assert.AreEqual(2, 1 + 1);
        }


The test passes, fine.

But now uncomment this line
  = LogManager.GetLogger(typeof(Log4NetTypeMock))


Run the Test2() again, this time, it fails!
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon Hui,

Another good issue report. I need to investigate it - let's take it offline
answered by dhelper (11.9k points)
...