I'm mocking some objects using Moq, and some of them can have fairly lengthy parameter-collection request objects passed in as arguments.
For ease of re-use and style, I'd like to be able to store these requests, with specific arguments, for use in the mocking setup. For example:
mockedObject
.Setup(mo =>
mo.GetBobbins(It.Is<GetBobbinsRequest>
(r.Parameter1 == value1 && [...] & r.ParameterN == valueN))
.Returns(someBobbins);
becomes:
var request = It.Is<GetBobbinsRequest>
(r.Parameter1 == value1 && [...] & r.ParameterN == valueN);
mockedObject
.Setup(mo => mo.GetBobbins(request))
.Returns(someBobbins);
But that doesn't seem to work. I also tried:
Func<GetBobbinsRequest> request = () => It.Is<GetBobbinsRequest>
(r.Parameter1 == value1 && [...] & r.ParameterN == valueN);
mockedObject
.Setup(mo => mo.GetBobbins(request()))
.Returns(someBobbins);
But no joy there either. Is there any way I can save an It
style object as a variable? Or am I missing some other obvious way of handling this?