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've been trying to write a test for some functionality where a class has a large number of protected methods which are called based on dynamic deserialization behaviour.
Rather than a hand-rolled mock that needs maintaining, I instead wanted to leverage the existing data-driven tests for the deserialization to use the same approach.
However, the part where I've gotten stuck is that I don't know the type of the parameters on the protected methods at runtime, so I haven't been able to get the setup to work. I do however know what types the parameters will be derived from based on the pattern of conventions in the code.
This fails to match the method as the type check here only works for a more derived-type matching a less derived-type on the declaration, but in my case as I don't know the specific type I wanted to match it the other way around (i.e. a parameter that is of this type):
As I don't have a type parameter, I can't use ItExpr.IsAny<T>(), and ItExtra.IsAny<It.IsAnyType>() didn't seem to work either.
I see there's some extensibility around matching, but after much head-scratching I couldn't seem to find a way around it to get it to work the way I wanted it to.
Is what I'm trying to achieve even currently possible with Moq (#887 suggests maybe not)? If it is, any help on what I'm missing to get the setup and verify to work would be appreciated.
I've been trying to write a test for some functionality where a class has a large number of protected methods which are called based on dynamic deserialization behaviour.
Rather than a hand-rolled mock that needs maintaining, I instead wanted to leverage the existing data-driven tests for the deserialization to use the same approach.
However, the part where I've gotten stuck is that I don't know the type of the parameters on the protected methods at runtime, so I haven't been able to get the setup to work. I do however know what types the parameters will be derived from based on the pattern of conventions in the code.
This is as far as I managed to get:
This fails to match the method as the type check here only works for a more derived-type matching a less derived-type on the declaration, but in my case as I don't know the specific type I wanted to match it the other way around (i.e. a parameter that is of this type):
https://github.com/moq/moq4/blob/1c4c72309bd1abf265974ffff9e3a72d5be0632a/src/Moq/Extensions.cs#L329
As I don't have a type parameter, I can't use
ItExpr.IsAny<T>()
, andItExtra.IsAny<It.IsAnyType>()
didn't seem to work either.I see there's some extensibility around matching, but after much head-scratching I couldn't seem to find a way around it to get it to work the way I wanted it to.
Is what I'm trying to achieve even currently possible with Moq (#887 suggests maybe not)? If it is, any help on what I'm missing to get the setup and verify to work would be appreciated.
More context can be found here octokit/webhooks.net#244 (comment).
The text was updated successfully, but these errors were encountered: