Moq的可链接实现

Moq的可链接实现,moq,method-chaining,Moq,Method Chaining,是否存在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(); mockSchedule.Setu

是否存在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();
mockSchedule.SetupGet(x=>x.Date).Returns(新的日期时间(2011,6,1));
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");
var mockSchedule=
新模拟
.Which().SetupGet(x=>x.Date).返回(新的日期时间(2011,6,1))
.Which().SetupGet(x=>x.Label).Returns(“附表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");
var-mockSchedule=
新建Mock()。
.SetupGetWith(x=>x.Date,新日期时间(2011,6,1))
.SetupGetWith(x=>x.标签“附表A”);

我可以自己写这些,但如果有一个现有的实现,我宁愿不重新发明轮子;还有MOQV4的功能规范

var foo = Mock.Of<IFoo>(f =>
    f.Id == 1 &&
    f.Who == "me" &&
    f.GetBar(It.IsAny<string>()) == Mock.Of<IBar>(
        b => b.Name == "Fred"));
var foo=Mock.Of(f=>
f、 Id==1&&
f、 谁==“我”&&
f、 GetBar(It.IsAny())==Mock.Of(
b=>b.Name==“弗雷德”);

文档可能会更好。我有一本书。另请参见和。

Nice。语法看起来不是很直观,但它确实是一种改进。我在快速入门中没有看到这一点。但是如何设置CallBase和DefaultValue呢?我相信您必须使用
Mock.Get(foo.CallBase()或使用旧语法。有关这方面的更多信息,请参阅上面的讨论线程链接。是的,目前这不在快速入门中。