Unit testing Rhino Mocks-Assertwas在一个参数为DateTime时被调用
我正在为一个C#Log类编写单元测试,该类调用接口ILogHandler上的Log方法,并在前面加上时间戳,如下所示:Unit testing Rhino Mocks-Assertwas在一个参数为DateTime时被调用,unit-testing,rhino-mocks,Unit Testing,Rhino Mocks,我正在为一个C#Log类编写单元测试,该类调用接口ILogHandler上的Log方法,并在前面加上时间戳,如下所示: log(string msg, LogLevel lvl) { _handler.log(DateTime.Now, msg, lvl); } 我最初的handler方法在handler方法中添加了时间戳,这使得测试是否调用了handlers日志变得很容易,但是现在我已经添加了时间戳,我不确定应该如何执行测试 有什么建议吗 谢谢:)您可以提供以下参数: handler.
log(string msg, LogLevel lvl)
{
_handler.log(DateTime.Now, msg, lvl);
}
我最初的handler方法在handler方法中添加了时间戳,这使得测试是否调用了handlers日志变得很容易,但是现在我已经添加了时间戳,我不确定应该如何执行测试
有什么建议吗
谢谢:)您可以提供以下参数:
handler.AssertWasCalled(h => h.Log(Arg<DateTime>.Is.Anything,
Arg<string>.Is.Equal(msg),
Arg<LogLevel>.Is.Equal(lvl)));
handler.AssertWasCalled(h=>h.Log(Arg.Is.Anything),
参数等于(msg),
参数等于(lvl));
这将检查传递给依赖项的第一个参数是否为any DateTime。若要设置一些限制,请将Arg.Matches部分添加到参数