c# - Setup Moq to increment value when method called -
i've got poco im saving, this:
_myrepo.save(somepoco); _myrepo mocked, e.g:
var myrepo = new mock<irepo>(); when save method called, want set somepoco.id 1.
how do it?
i see there callback method on .setup, doesn't pass through poco, e.g:
myrepo.setup(x => x.save(it.isany<somepoco>()) .callback(x => // how poco?);
the parameters passed callback method need specify types explicitly.
so following should work:
myrepo.setup(x => x.save(it.isany<somepoco>())) .callback<somepoco>(poco => { poco.id = 1; }); see samples in quick start:
// access invocation arguments mock.setup(foo => foo.execute(it.isany<string>())) .returns(true) .callback((string s) => calls.add(s));
Comments
Post a Comment