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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With