Rhino Mock을 사용하여 메서드가 호출되고 (이상적으로는 특정 매개 변수가있는 경우) 어설 션하는 데 문제가 있습니다. Method는 새로운 lamba 구문을 사용하는 Common.Logging 2.0의 ILog.Debug (FormatMessageHandler)입니다. 오래된 ILog.Debug (문자열)을 사용하면 잘 작동합니다.Rhino Mock - Common.Logging에서 AssertWasCalled 사용 ILog.Debug
// 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"))));
}
방금 수정 한 샘플에 약간의 오타가있었습니다. 예, 이것은 간단한 예제 일뿐입니다. TestFunc은 작동하지만 TestFuncLamba는 작동하지 않습니다. 지금 그게 더 명확 해지기를 바랍니다. – ss2k