From 52248fef92343105bc2a5598f3cccc21df442166 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Tue, 1 Oct 2024 23:58:00 +0100 Subject: [PATCH] feat: add `IDisposable` test --- Refit.GeneratorTests/InterfaceTests.cs | 13 ++++ ...ableTest#IGeneratedInterface.g.verified.cs | 59 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DisposableTest#IGeneratedInterface.g.verified.cs diff --git a/Refit.GeneratorTests/InterfaceTests.cs b/Refit.GeneratorTests/InterfaceTests.cs index 0345fe080..c4181eb67 100644 --- a/Refit.GeneratorTests/InterfaceTests.cs +++ b/Refit.GeneratorTests/InterfaceTests.cs @@ -98,4 +98,17 @@ public interface IGeneratedInterface } """); } + + [Fact] + public Task DisposableTest() + { + return Fixture.VerifyForDeclaration( + """ + public interface IGeneratedInterface : IDisposable + { + [Get("/users")] + Task Get(); + } + """); + } } diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DisposableTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DisposableTest#IGeneratedInterface.g.verified.cs new file mode 100644 index 000000000..c43c3fd75 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.DisposableTest#IGeneratedInterface.g.verified.cs @@ -0,0 +1,59 @@ +//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 + + { + /// + 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); + } + + /// + void global::System.IDisposable.Dispose() + { + Client?.Dispose(); + } + } + } +} + +#pragma warning restore