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>());
精彩评论