The point is not the NullLogger, suppose this code without that class:
using System;
using MbUnit.Framework;
using TypeMock;
[TestFixture]
public class FailSuppressionBug
{
private ILogger m_logger;
ILogger m_mockFileLogger = (ILogger) RecorderManager.CreateMockedObject(typeof(ILogger));
ILogger m_mockDBLogger = (ILogger) RecorderManager.CreateMockedObject(typeof(ILogger));
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
MockManager.Init();
}
[TearDown]
public void TearDown()
{
MockManager.Verify();
}
[Test]
public void DBLoggerShouldBeDisabledUponFirstFailure()
{
m_logger = new CompositeLogger(m_mockFileLogger, m_mockDBLogger);
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
m_mockFileLogger.Log("OpenDataFile", "a message to log");
m_mockDBLogger.Log("OpenDataFile", "a message to log");
recorder.Throw(new Exception("MOCK: db problem"));
m_mockFileLogger.Log("OpenDataFile", "another message to log");
}
m_logger.Log("OpenDataFile", "a message to log");
m_logger.Log("OpenDataFile", "another message to log");
}
}
internal interface ILogger
{
void Log(string operationId, string detail);
}
internal class CompositeLogger : ILogger
{
private ILogger m_fileLogger;
private ILogger m_DBLogger;
public CompositeLogger(ILogger fileLogger, ILogger dbLogger)
{
m_fileLogger = fileLogger;
m_DBLogger = dbLogger;
}
public void Log(string operationId, string detail)
{
m_fileLogger.Log(operationId, detail);
try
{
m_DBLogger.Log(operationId, detail);
}
catch (Exception)
{
//do nothing
}
}
}
This test pass when it should not.
When I write a test at first stage I want to see it to fail.
In this case the test say that dblogger.log should be called only 1 time but in the production code it is called 2 times, and TypeMock say nothing about this.
Only after I seeing the test fail I'll change my test to write the correct behaviour.
I hope I was clear,
thank you,
Antonio.