I'm looking for a way to capture the actual parameter passed to method to examine it later. The idea being to get the passed parameter and then execute assertions against it.
For instance:
var foo = Mock<Foo>();
var service = Mock<IService>();
service.Expect(s => s.Create(foo));
service.Create(new Foo { Currency = "USD" });
Assert(foo.Object.Currency == "USD");
Or a bit more complex example:
Foo foo = new Foo { Title = "...", Description = "..." };
var bar = Mock.NewHook<Bar>();
var service = new Mock<IService>();
service.Expect(s => s.Create(bar));
new Controller(service.Object).Create(foo);
Assert(foo.Title == bar.Object.Title);
Assert(foo.Description == bar.Object.Description);
I think you're looking for something equivalent to Moq's Callback:
var foo = Mock<Foo>();
var service = Mock<IService>();
service.Setup(s => s.Create(foo.Object)).Callback((T foo) => Assert.AreEqual("USD", foo.Currency))
service.Object.Create(new Foo { Currency = "USD" });
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