Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing Rhino Mocks-Assertwas在一个参数为DateTime时被调用_Unit Testing_Rhino Mocks - Fatal编程技术网

Unit testing Rhino Mocks-Assertwas在一个参数为DateTime时被调用

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.

我正在为一个C#Log类编写单元测试,该类调用接口ILogHandler上的Log方法,并在前面加上时间戳,如下所示:

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部分添加到参数