You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a method that takes a large readonly struct as an in parameter. I'd like to setup a mock so that I can match against a certain property on the struct.
Because it's passed as in I need to use It.Ref. However, there's no option to attach a predicate. For example I'd like to say:
Unfortunately, something like It.Ref<T>.Is(predicate) cannot currently be implemented, because the C# compilers do not allow ref returns in LINQ expression trees. (If you try to do so, you'll get an error CS8153: An expression tree lambda may not contain a call to a method, property, or indexer that returns by reference.) So as far as I can tell, what you're asking for is currently not possible.
I have a method that takes a large readonly struct as an
in
parameter. I'd like to setup a mock so that I can match against a certain property on the struct.Because it's passed as
in
I need to useIt.Ref
. However, there's no option to attach a predicate. For example I'd like to say:myMock1.Setup(x => x.Visit(ref It.Ref<LargeStruct>.Is(r = r.UserID == 10))
The only option available is to match any instance of
LargeStruct
which isn't a narrow enough condition.Is there an alternative way to handle this scenario?
The text was updated successfully, but these errors were encountered: