Overload for A<>.That.Matches() allowing to access other arguments
See original GitHub issueIt would be nice to have an overload of A<>.That.Matches() which allows me to access other arguments passed in, e.g. something like this:
A.CallTo( ()=>myObj.Foo(
A<Param1Type>._,
A<Param2Type>.That.Matches( (arg, ctx) => arg.ID == ctx.Arguments[0].Param2ID )
This would help if you want to assert that a parameter is passed correctly if it depends on another one (yes, I know, a good API should not have parameters which are transitively dependent on each other, but we are not living in an ivory tower).
Currently, the only workaround seems to be:
A.CallTo( myObj ).Where( ... )
Unfortunately you must specify the method name in the Where() as well, and do no longer have refactoring safety for method name and number of arguments.
I’d like to provide a PR too, but I do not have time at the moment. So I thought, I’ll just post a feature request.
Best regards, D.R.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
why does calling an overloaded function with arguments ...
Overload 2 exactly matches one of the parameters and none of the others do. And because the first parameter can be implicitly converted, ......
Read more >Function overload resolution and ambiguous matches
There are a few ways to resolve ambiguous matches: Often, the best way is simply to define a new overloaded function that takes...
Read more >Support overload resolution with type union arguments
When resolving overloads, an overload must match for every tuple in the cartesian product of all union argument types. Again the return type ......
Read more >Overload resolution
In simple terms, the overload whose parameters match the arguments most closely is the one that is called. In detail, overload resolution ...
Read more >Parameter type interface for overloaded functions as union ...
Inferring parameters from a union of function types (which is how overloads are represented internally iirc) typically creates intersections ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @drauch,
Thanks for the suggestion.
Actually you can also do this:
It’s a bit verbose, but it works…
It would probably be useful to add helper overloads for
WhenArgumentsMatch
to enable this syntax:(we already do this for
Invokes
,Throws
andReturnsLazily
)Yes. We did #1021 instead, which achieves the same result.