question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overload for A<>.That.Matches() allowing to access other arguments

See original GitHub issue

It 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:closed
  • Created 7 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
thomaslevesquecommented, Mar 13, 2017

Hi @drauch,

Thanks for the suggestion.

Currently, the only workaround seems to be:

A.CallTo( myObj ).Where( ... )

Actually you can also do this:

A.CallTo(() => obj.Foo(A<Param1Type>._, A<Param2Type>._))
    .WhenArgumentsMatch(args => args.Get<Param2Type>("param2").ID == args.Get<Param1Type>("param1").Param2ID)

It’s a bit verbose, but it works…

It would probably be useful to add helper overloads for WhenArgumentsMatch to enable this syntax:

A.CallTo(() => obj.Foo(A<Param1Type>._, A<Param2Type>._))
    .WhenArgumentsMatch((Param1Type param1, Param2Type param2) => param1.Param2ID == param2.ID)

(we already do this for Invokes, Throws and ReturnsLazily)

0reactions
thomaslevesquecommented, Mar 22, 2017

Added “wontfix” - is that correct?

Yes. We did #1021 instead, which achieves the same result.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found