Is it possible to assign an out
/ref
parameter using Moq (3.0+)?
I've looked at using Callback()
, but Action<>
does not support ref parameters because it's based on generics. I'd also preferably like to put a constraint (It.Is
) on the input of the ref
parameter, though I can do that in the callback.
I know that Rhino Mocks supports this functionality, but the project I'm working on is already using Moq.
While the question is about Moq 3 (probably due to its age), allow me to post a solution for Moq 4.8, which has much improved support for by-ref parameters.
By the way:
It.Ref<T>.IsAny
also works for C# 7in
parameters (since they are also by-ref).This is documentation from Moq site:
This can be a solution .