Rhino Mocks を使用してメソッドが呼び出されたことをアサートするのに問題があります (理想的には特定のパラメーターを使用して)。メソッドは、 Common.Logging 2.0のILog.Debug(FormatMessageHandler) で、新しいラムバ構文を使用します。古い方法の単純な ILog.Debug(string) を使用して正常に動作します。
// Sample Code to Test
public int TestFuncLambda(ILog log, int a, int b)
{
log.Debug(m => m("TestFunc START"));
int c = a + b;
log.Debug(m => m("TestFunc END"));
return c;
}
public int TestFunc(ILog log, int a, int b)
{
log.Debug("TestFunc START");
int c = a + b;
log.Debug("TestFunc END");
return c;
}
[TestMethod]
public void Should_log_start_TestFuncLamba()
{
var logger = MockRepository.GenerateMock<ILog>();
logger.Stub(x => x.IsDebugEnabled).Return(true);
TestFuncLambda(logger, 1, 2);
// Doesn't work, says zero calls plus I'm not sure how to check for the word "START" in the string either
logger.AssertWasCalled(x => x.Debug(Arg<FormatMessageHandler>.Is.Anything), o => o.IgnoreArguments());
}
[TestMethod]
public void Should_log_start_TestFunc()
{
var logger = MockRepository.GenerateMock<ILog>();
logger.Stub(x => x.IsDebugEnabled).Return(true);
TestFunc(logger, 1, 2);
// Works fine
logger.AssertWasCalled(x => x.Debug(Arg<string>.Matches(Text.Contains("START"))));
}