I've got a POCO which im saving, like this:
_myRepo.Save(somePoco);
_myRepo
is mocked, e.g:
var myRepo = new Mock<IRepo>();
When that Save method is called, i want to set somePoco.Id
to 1.
How do i do it?
I see there is a Callback
method on the .Setup
, but it doesn't pass through the POCO, e.g:
myRepo.Setup(x => x.Save(It.IsAny<SomePoco>())
.Callback(x => // how do i get the poco?);
The parameters get passed to the Callback
method you just need to specify the types explicitly.
So the following should work:
myRepo.Setup(x => x.Save(It.IsAny<SomePoco>()))
.Callback<SomePoco>(poco => { poco.Id = 1; });
See also the samples in the quick start:
// access invocation arguments
mock.Setup(foo => foo.Execute(It.IsAny<string>()))
.Returns(true)
.Callback((string s) => calls.Add(s));
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