Moq的可链接实现(Chainable Implementation for Moq)
Moq是否有可链接的实现? 我在想,而不是这个:
var mockSchedule = new Mock<Schedule>(); mockSchedule.SetupGet(x => x.Date).Returns(new DateTime(2011,6,1)); mockSchedule.SetupGet(x => x.Label).Returns("Schedule A");我可以这样称呼它:
var mockSchedule = new Mock<Schedule>() .Which().SetupGet(x => x.Date).Returns(new DateTime(2011,6,1)) .Which().SetupGet(x => x.Label).Returns("Schedule A");或者像这样:
var mockSchedule = new Mock<Schedule>(). .SetupGetWith(x => x.Date,new DateTime(2011,6,1)) .SetupGetWith(x => x.Label,"Schedule A");我自己可以写这些,但如果有现有的实现,我宁愿不重新发明轮子
Is there a chainable implementation of Moq out there? I was thinking that instead of this:
var mockSchedule = new Mock<Schedule>(); mockSchedule.SetupGet(x => x.Date).Returns(new DateTime(2011,6,1)); mockSchedule.SetupGet(x => x.Label).Returns("Schedule A");I can call it like this:
var mockSchedule = new Mock<Schedule>() .Which().SetupGet(x => x.Date).Returns(new DateTime(2011,6,1)) .Which().SetupGet(x => x.Label).Returns("Schedule A");or like this:
var mockSchedule = new Mock<Schedule>(). .SetupGetWith(x => x.Date,new DateTime(2011,6,1)) .SetupGetWith(x => x.Label,"Schedule A");I could write these myself but if there's an existing implementation I'd rather not reinvent the wheel
最满意答案
有点; 有Moq v4功能规格。
var foo = Mock.Of<IFoo>(f => f.Id == 1 && f.Who == "me" && f.GetBar(It.IsAny<string>()) == Mock.Of<IBar>( b => b.Name == "Fred"));文档可能会更好。 我的博客上有一篇简短的文章 。 另请参阅旧式命令式模拟与moq功能规范以及此Moq讨论主题 。
Sort of; there's the Moq v4 functional specifications.
var foo = Mock.Of<IFoo>(f => f.Id == 1 && f.Who == "me" && f.GetBar(It.IsAny<string>()) == Mock.Of<IBar>( b => b.Name == "Fred"));The documentation could be better. I've got a short writeup on my blog. See also Old style imperative mocks vs moq functional specifications and this Moq Discussions thread.
更多推荐
发布评论