I have an interface with a number of generic methods. These methods perform operations based on the type of data that is passed in. How do I mock this with NSubstitute? At t
NSubstitute doesn't support setting up multiple instances of a generic method automatically.
The way we'd normally see IInstanceSource
used in a test is to configure it for a specific bit of code under test, so T
would be known. If a single fixture needed to work for a few different T
s, we could make configuration simpler by having a helper method like ConfigureInstanceSource<T>()
which would do the configurations steps for a specific T
.
In your case though it seems like you want a fixed behaviour for all fake instances of IInstanceSource
, in which case I believe you are going the right way about it by hand-coding your own test double.