diff --git a/Refit.GeneratorTests/InterfaceTests.cs b/Refit.GeneratorTests/InterfaceTests.cs index c4181eb67..2cdf1deea 100644 --- a/Refit.GeneratorTests/InterfaceTests.cs +++ b/Refit.GeneratorTests/InterfaceTests.cs @@ -111,4 +111,16 @@ public interface IGeneratedInterface : IDisposable } """); } + + [Fact] + public Task NonRefitMethodShouldRaiseDiagnostic() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get(); + + void NonRefitMethod(); + """); + } } diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NonRefitMethodShouldRaiseDiagnostic#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NonRefitMethodShouldRaiseDiagnostic#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..1b01c0762 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NonRefitMethodShouldRaiseDiagnostic#IGeneratedClient.g.verified.cs @@ -0,0 +1,59 @@ +//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() + { + 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::RefitGeneratorTest.IGeneratedClient.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::RefitGeneratorTest.IGeneratedClient.NonRefitMethod() + { + 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/InterfaceTests.NonRefitMethodShouldRaiseDiagnostic.verified.txt b/Refit.GeneratorTests/_snapshots/InterfaceTests.NonRefitMethodShouldRaiseDiagnostic.verified.txt new file mode 100644 index 000000000..9bc7316a4 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/InterfaceTests.NonRefitMethodShouldRaiseDiagnostic.verified.txt @@ -0,0 +1,14 @@ +{ + Diagnostics: [ + { + Id: RF001, + Title: Refit types must have Refit HTTP method attributes, + Severity: Warning, + WarningLevel: 1, + Location: : (16,5)-(16,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