diff --git a/Refit.GeneratorTests/InterfaceTests.cs b/Refit.GeneratorTests/InterfaceTests.cs index 2cdf1deea..92e462663 100644 --- a/Refit.GeneratorTests/InterfaceTests.cs +++ b/Refit.GeneratorTests/InterfaceTests.cs @@ -123,4 +123,22 @@ public Task NonRefitMethodShouldRaiseDiagnostic() void NonRefitMethod(); """); } + + [Fact] + public Task InterfaceWithGenericConstraint() + { + return Fixture.VerifyForDeclaration( + """ + public interface IGeneratedInterface + where T1 : class + where T2 : unmanaged + where T3 : struct + where T4 : notnull + where T5 : class, IDisposable, new() + { + [Get("/users")] + Task Get(); + } + """); + } } diff --git a/Refit.GeneratorTests/ReturnTypeTests.cs b/Refit.GeneratorTests/ReturnTypeTests.cs index 099a888dd..da21788cf 100644 --- a/Refit.GeneratorTests/ReturnTypeTests.cs +++ b/Refit.GeneratorTests/ReturnTypeTests.cs @@ -21,4 +21,34 @@ public Task VoidTaskShouldWork() Task Post(); """); } + + [Fact] + public Task GenericConstraintReturnTask() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get() where T : class, IDisposable, new(); + """); + } + + [Fact] + public Task GenericUnmanagedConstraintReturnTask() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get() where T : unmanaged; + """); + } + + [Fact] + public Task GenericStructConstraintReturnTask() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get() where T : struct + """); + } } diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceWithGenericConstraint#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceWithGenericConstraint#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..752d5520e --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceWithGenericConstraint#IGeneratedInterface.g.verified.cs @@ -0,0 +1,58 @@ +//HintName: IGeneratedInterface.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 IGeneratedInterface + : global::IGeneratedInterface + where T1 : class + where T2 : unmanaged + where T3 : struct + where T4 : notnull + where T5 : class, global::System.IDisposable, new() + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public IGeneratedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + + /// + async global::System.Threading.Tasks.Task global::IGeneratedInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericConstraintReturnTask#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericConstraintReturnTask#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..4ea45b517 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericConstraintReturnTask#IGeneratedClient.g.verified.cs @@ -0,0 +1,55 @@ +//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 T : 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(T) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + where T : class + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericStructConstraintReturnTask#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericStructConstraintReturnTask#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..ac36d633b --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericStructConstraintReturnTask#IGeneratedClient.g.verified.cs @@ -0,0 +1,55 @@ +//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 T : struct + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + where T : struct + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericUnmanagedConstraintReturnTask#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericUnmanagedConstraintReturnTask#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..57ce44ea6 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericUnmanagedConstraintReturnTask#IGeneratedClient.g.verified.cs @@ -0,0 +1,54 @@ +//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 T : unmanaged + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty(), new global::System.Type[] { typeof(T) } ); + + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + } + } +} + +#pragma warning restore