-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReturnsForAnyArgs and WhenForAnyArgs and generic arguments #152
Comments
…Args and generic arguments)
I think whether it is obvious or not depends on how we think about generic methods. AFAICT when we use a generic method it will be compiled as a specific, non-generic instance of that generic method. I think we tend to approximate this to "calling a generic method" with a varying type parameter, in which case we'd conclude that we should be able to setup calls to It could still be useful to come up with a way off configuring all instances of |
I think it's more a question of how we treat Your position is fine for me but for But it's not so obvious for |
I take your point. I've had this cause confusion for people before. I think a good example could be
To me the former still makes sense provided we're thinking of generics accurately (i.e. "ForAnyArgs" means any arguments passed to the closed generic |
Came here via #185, this would be useful for a generic repository pattern. I think it would need its own syntax though; The syntax could look something like
|
Closed #185 so we can continue discussion here. How frequently do you need something like this? In my tests I haven't run in to a case where I've had to stub numerous generic instances of calls with the same logic. I think we could come up with a way of stubbing/getting callbacks for multiple generic instances, but I'm not sure it is worth the complexity (compared to, say, hand-rolling a fake |
I think this is a nice functionality to have. I want this behaviour for my repo stubs - if someone somewhere asks for some IQueryable just give an empty one to him. I'll probably be happy with just #67(should look into it as it seems much easier to implement). However, I understands the concerns about complexity. Faking doesn't looks as nice as mocking (one of repos that we use have 13 methods and I really care about 1 or 2 generic ones) but I could live with it. |
Would be great to have #67 sorted! :) |
Stumbled upon this while attempting to validate a call into The logger interface takes a For example, consumer code calls it like this: logger.Critical("A critical problem has occurred!"); This is translated into a call to the interface's method, which has this signature: public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter) The I actually solved this before by creating an I'd really appreciate if NSubstitute provided a way to specify |
@julealgon Thanks for the good example. I've created #634 for this feature request. |
I assume the questions has been answered in this issue, if not, please let us know! |
This is more a question rather than a bug report. Inspired by a question on SO
Suppose we have an interface with a generic method:
Then when we specify the sub to return a value for any argument then it fails on the call with another generic type.
The same is right for
WhenForAnyArgs()
.Imo this isn't obvious behavior. Thoughts?
The text was updated successfully, but these errors were encountered: