Skip to content

feat: add generic tests to ReflectionTests#2195

Merged
glennawatson merged 2 commits into
reactiveui:mainfrom
TimothyMakkison:generic_reflection
Jul 3, 2026
Merged

feat: add generic tests to ReflectionTests#2195
glennawatson merged 2 commits into
reactiveui:mainfrom
TimothyMakkison:generic_reflection

Conversation

@TimothyMakkison

@TimothyMakkison TimothyMakkison commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Add test for overloads of the same method with different generic type overloads. Think I've found a possible bug with generic interfaces support

Both GetGenericParameter<T1>(T1 @value1) and GetGenericParameter<T1>(T1 @value1, TInterface @value2) result in the error:
No suitable Method found... at Refit.RequestBuilderImplementation.FindMatchingRestMethodInfo(String key, Type[] parameterTypes, Type[] genericArgumentTypes) in

@TimothyMakkison

TimothyMakkison commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Okay, converted to Refit.Tests, it appears that refit doesn't support generic parameters is a generic argument on the class. I don't know if this was always the case or if I'm missing something here. If this is expected I can remove the failing tests.

Suggestion: Refit.Tests should have an "accept anything" function similar to Fallback which would blanket respond with the same thing, having to specify your exact route / header / query may not always be necessary 🤷

_mockHandler
    .Fallback
    .Respond("application/json", nameof(IBasicApi.GetParam));

@glennawatson

Copy link
Copy Markdown
Contributor

Yeah, if its a good use case in our new Refit.Testing framework with the ability to fallback please add it. The refit mocking framework is more flat, so more you add in lists/actions rather than fluent style, so if you can keep that style when adding this new feature that'd be awesome.

@glennawatson

glennawatson commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

eg our goal with Testing is a decent mock framework that is perf/alloc focused but still easy to use, that anyone using refit can then use in their test framework (so it needs to be test framework agnostic also)

@TimothyMakkison

TimothyMakkison commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for making the issue for the fallback, seems like a good first issue TBH.

I'm fairly confident that the error I've been having is a bug, see #2197. Thankfully I think this issue will be unintentionally fixed once Refit is 100% source generated, as the language/compiler will handle disambiguating method overloads and not Refit. I suspect the bug has existed in Refit for a very long time, but no one has noticed up until now. 😅

@TimothyMakkison TimothyMakkison force-pushed the generic_reflection branch 2 times, most recently from 3184841 to 1bc9915 Compare July 3, 2026 12:09
@TimothyMakkison

Copy link
Copy Markdown
Collaborator Author

Fixed the tests by renaming one of the method overloads, hopefully when #2197 is fixed we can changed it back.

@glennawatson

Copy link
Copy Markdown
Contributor

ready for a merge?

@TimothyMakkison

Copy link
Copy Markdown
Collaborator Author

ready for a merge?

Yup, hopefully haven't forgotten any test cases 👍

@glennawatson glennawatson merged commit 88e1c24 into reactiveui:main Jul 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants