From 624bc17c1e136a0f92a4cfa08fe6acf818cac92f Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Mon, 16 Sep 2024 22:27:08 +0100 Subject: [PATCH 1/2] chore: rename tests add derived interface test --- Refit.GeneratorTests/InterfaceTests.cs | 19 ++++++- ...efitBaseTest#IBaseInterface.g.verified.cs} | 10 ++-- ...itBaseTest#IDerivedInterface.g.verified.cs | 51 +++++++++++++++++++ ...aseTest#IGeneratedInterface.g.verified.cs} | 0 ...efitBaseTest#IBaseInterface.g.verified.cs} | 0 ...aseTest#IGeneratedInterface.g.verified.cs} | 0 6 files changed, 73 insertions(+), 7 deletions(-) rename Refit.GeneratorTests/_snapshots/{GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs => InterfaceTests.InterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs} (86%) create mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IDerivedInterface.g.verified.cs rename Refit.GeneratorTests/_snapshots/{InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs => InterfaceTests.RefitInterfaceDerivedFromBaseTest#IGeneratedInterface.g.verified.cs} (100%) rename Refit.GeneratorTests/_snapshots/{InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs => InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs} (100%) rename Refit.GeneratorTests/_snapshots/{InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs => InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IGeneratedInterface.g.verified.cs} (100%) diff --git a/Refit.GeneratorTests/InterfaceTests.cs b/Refit.GeneratorTests/InterfaceTests.cs index 937d7d970..bff848c1e 100644 --- a/Refit.GeneratorTests/InterfaceTests.cs +++ b/Refit.GeneratorTests/InterfaceTests.cs @@ -19,7 +19,7 @@ public interface IContainedInterface } [Fact] - public Task DerivedRefitInterfaceTest() + public Task RefitInterfaceDerivedFromRefitBaseTest() { return Fixture.VerifyForType( """ @@ -38,7 +38,7 @@ public interface IBaseInterface } [Fact] - public Task DerivedNonRefitInterfaceTest() + public Task RefitInterfaceDerivedFromBaseTest() { return Fixture.VerifyForType( """ @@ -55,6 +55,21 @@ public interface IBaseInterface """); } + [Fact] + public Task InterfaceDerivedFromRefitBaseTest() + { + return Fixture.VerifyForType( + """ + public interface IBaseInterface + { + [Get("/users")] + Task Get(); + } + + public interface IDerivedInterface : IBaseInterface { } + """); + } + [Fact] public Task NestedNamespaceTest() { diff --git a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs similarity index 86% rename from Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs rename to Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs index 19a9fc649..6dabbc696 100644 --- a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: IGeneratedClient.g.cs +//HintName: IBaseInterface.g.cs #nullable disable #pragma warning disable namespace Refit.Implementation @@ -13,8 +13,8 @@ partial class Generated [global::RefitInternalGenerated.PreserveAttribute] [global::System.Reflection.Obfuscation(Exclude=true)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - partial class RefitGeneratorTestIGeneratedClient - : global::RefitGeneratorTest.IGeneratedClient + partial class RefitGeneratorTestIBaseInterface + : global::RefitGeneratorTest.IBaseInterface { /// @@ -22,7 +22,7 @@ partial class RefitGeneratorTestIGeneratedClient readonly global::Refit.IRequestBuilder requestBuilder; /// - public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + public RefitGeneratorTestIBaseInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) { Client = client; this.requestBuilder = requestBuilder; @@ -46,7 +46,7 @@ public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient cli } /// - async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.Get() { var ______arguments = global::System.Array.Empty(); var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IDerivedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IDerivedInterface.g.verified.cs new file mode 100644 index 000000000..432e52dce --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.InterfaceDerivedFromRefitBaseTest#IDerivedInterface.g.verified.cs @@ -0,0 +1,51 @@ +//HintName: IDerivedInterface.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 RefitGeneratorTestIDerivedInterface + : global::RefitGeneratorTest.IDerivedInterface + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIDerivedInterface(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IBaseInterface.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromBaseTest#IGeneratedInterface.g.verified.cs similarity index 100% rename from Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#IGeneratedInterface.g.verified.cs rename to Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromBaseTest#IGeneratedInterface.g.verified.cs diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs similarity index 100% rename from Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IBaseInterface.g.verified.cs rename to Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IBaseInterface.g.verified.cs diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IGeneratedInterface.g.verified.cs similarity index 100% rename from Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#IGeneratedInterface.g.verified.cs rename to Refit.GeneratorTests/_snapshots/InterfaceTests.RefitInterfaceDerivedFromRefitBaseTest#IGeneratedInterface.g.verified.cs From 318f48552bd937171b94aeaf63c693fe92ddf7a3 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Mon, 16 Sep 2024 22:33:11 +0100 Subject: [PATCH 2/2] chore: added comment --- Refit.GeneratorTests/InterfaceTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Refit.GeneratorTests/InterfaceTests.cs b/Refit.GeneratorTests/InterfaceTests.cs index bff848c1e..0345fe080 100644 --- a/Refit.GeneratorTests/InterfaceTests.cs +++ b/Refit.GeneratorTests/InterfaceTests.cs @@ -40,6 +40,7 @@ public interface IBaseInterface [Fact] public Task RefitInterfaceDerivedFromBaseTest() { + // this currently generates invalid code see issue #1801 for more information return Fixture.VerifyForType( """ public interface IGeneratedInterface : IBaseInterface