diff --git a/Refit.GeneratorTests/MathodTests.cs b/Refit.GeneratorTests/MathodTests.cs new file mode 100644 index 000000000..8a27f1a66 --- /dev/null +++ b/Refit.GeneratorTests/MathodTests.cs @@ -0,0 +1,26 @@ +namespace Refit.GeneratorTests; + +public class MethodTests +{ + [Fact] + public Task MethodsWithGenericConstraints() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get() + where T1 : class + where T2 : unmanaged + where T3 : struct + where T4 : notnull + where T5 : class, IDisposable, new(); + + void NonRefitMethod() + where T1 : class + where T2 : unmanaged + where T3 : struct + where T4 : notnull + where T5 : class, IDisposable, new(); + """); + } +} diff --git a/Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..3b8ce9976 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints#IGeneratedClient.g.verified.cs @@ -0,0 +1,70 @@ +//HintName: IGeneratedClient.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [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 + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + /// + public async global::System.Threading.Tasks.Task Get() + 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(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + where T1 : class + where T3 : struct + where T5 : class + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + + /// + void global::RefitGeneratorTest.IGeneratedClient.NonRefitMethod() + 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 diff --git a/Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints.verified.txt b/Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints.verified.txt new file mode 100644 index 000000000..37eceea43 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/MethodTests.MethodsWithGenericConstraints.verified.txt @@ -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 + } + ] +} \ No newline at end of file