开发者

Moq with relative DateTime values

开发者 https://www.devze.com 2023-01-26 07:09 出处:网络
I\'m a bit puzzled why this doesn\'t work. Probably overlooking something simple. In the code I\'m calling

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

精彩评论

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