-
-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added generic constrained method tests (#1868)
- Loading branch information
1 parent
f7f9c00
commit b6f8eeb
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Refit.GeneratorTests; | ||
|
||
public class MethodTests | ||
{ | ||
[Fact] | ||
public Task MethodsWithGenericConstraints() | ||
{ | ||
return Fixture.VerifyForBody( | ||
""" | ||
[Get("/users")] | ||
Task<string> Get<T1, T2, T3, T4, T5>() | ||
where T1 : class | ||
where T2 : unmanaged | ||
where T3 : struct | ||
where T4 : notnull | ||
where T5 : class, IDisposable, new(); | ||
void NonRefitMethod<T1, T2, T3, T4, T5>() | ||
where T1 : class | ||
where T2 : unmanaged | ||
where T3 : struct | ||
where T4 : notnull | ||
where T5 : class, IDisposable, new(); | ||
"""); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...Tests/_snapshots/MethodTests.MethodsWithGenericConstraints#IGeneratedClient.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//HintName: IGeneratedClient.g.cs | ||
#nullable disable | ||
#pragma warning disable | ||
namespace Refit.Implementation | ||
{ | ||
|
||
partial class Generated | ||
{ | ||
|
||
/// <inheritdoc /> | ||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] | ||
[global::System.Diagnostics.DebuggerNonUserCode] | ||
[global::RefitInternalGenerated.PreserveAttribute] | ||
[global::System.Reflection.Obfuscation(Exclude=true)] | ||
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
partial class RefitGeneratorTestIGeneratedClient | ||
: global::RefitGeneratorTest.IGeneratedClient | ||
|
||
{ | ||
/// <inheritdoc /> | ||
public global::System.Net.Http.HttpClient Client { get; } | ||
readonly global::Refit.IRequestBuilder requestBuilder; | ||
|
||
/// <inheritdoc /> | ||
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) | ||
{ | ||
Client = client; | ||
this.requestBuilder = requestBuilder; | ||
} | ||
|
||
|
||
/// <inheritdoc /> | ||
public async global::System.Threading.Tasks.Task<string> Get<T1, T2, T3, T4, T5>() | ||
where T1 : class | ||
where T2 : unmanaged | ||
where T3 : struct | ||
where T4 : notnull | ||
where T5 : class, global::System.IDisposable, new() | ||
{ | ||
var ______arguments = global::System.Array.Empty<object>(); | ||
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>(), new global::System.Type[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) } ); | ||
|
||
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get<T1, T2, T3, T4, T5>() | ||
where T1 : class | ||
where T3 : struct | ||
where T5 : class | ||
{ | ||
var ______arguments = global::System.Array.Empty<object>(); | ||
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>(), new global::System.Type[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) } ); | ||
|
||
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
void global::RefitGeneratorTest.IGeneratedClient.NonRefitMethod<T1, T2, T3, T4, T5>() | ||
where T1 : class | ||
where T3 : struct | ||
where T5 : class | ||
{ | ||
throw new global::System.NotImplementedException("Either this method has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument."); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#pragma warning restore |
14 changes: 14 additions & 0 deletions
14
Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
Diagnostics: [ | ||
{ | ||
Id: RF001, | ||
Title: Refit types must have Refit HTTP method attributes, | ||
Severity: Warning, | ||
WarningLevel: 1, | ||
Location: : (21,5)-(21,19), | ||
MessageFormat: Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, | ||
Message: Method IGeneratedClient.NonRefitMethod either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument, | ||
Category: Refit | ||
} | ||
] | ||
} |