开发者

Moq with relative DateTime values

I'm a bit puzzled why this doesn't work. Probably overlooking something simple.

In the code I'm calling

_view.ResponseExpiresAbsolute = DateTime.Now.AddDays(-1);

In the unit test:

_mockView.SetupSet(v => v.ResponseExpiresAbsolute, It.Is<DateTime>(p => p < DateTime.Today));

The setup never matches (verifies). I've even tried something like:

开发者_如何学运维
_mockView.SetupSet(v => v.ResponseExpiresAbsolute, It.IsAny<DateTime>()));

with no luck.

I've stepped through the code in test and it definitely executes _view.ResponseExpiresAbsolute.

Obviously there's something up with DateTime that I'm not understanding. Thoughts?


Try a different overload of SetupSet or even just VerifySet.

_mockView.VerifySet(v=>v.ResponseExpiresAbsolute = It.IsAny<DateTime>());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜