trying to inspect and argument and need to retrieve it. what is the equivalent in Moq? or a way to do it in Moq?
figured it out, utilizing the callback functionality on the Mock Setup
int captured_int;
mocked_obj.Setup(x => x.SomeMethod(It.IsAny<int>()))
.Callback<int>(x => captured_int = x);
if your method has multiple params
int captured_int;
object captured_object;
mocked_obj.Setup(x => x.SomeMethod(It.IsAny<int>(), It.IsAny<object>()))
.Callback<int, object>((i, o) => {
captured_int = i;
captured_object = o;
});
then you can do asserts on the captured values;
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