diff --git a/InterfaceStubGenerator.Core/InterfaceStubGenerator.cs b/InterfaceStubGenerator.Core/InterfaceStubGenerator.cs index 8165b8f16..328021c6d 100644 --- a/InterfaceStubGenerator.Core/InterfaceStubGenerator.cs +++ b/InterfaceStubGenerator.Core/InterfaceStubGenerator.cs @@ -53,6 +53,7 @@ public void GenerateInterfaceStubs(GeneratorExecutionContext context) namespace {refitInternalNamespace} {{ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] [AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate)] sealed class PreserveAttribute : Attribute {{ @@ -165,6 +166,7 @@ namespace {ns} [global::System.Diagnostics.DebuggerNonUserCode] [{preserveAttributeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}] [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] partial class AutoGenerated{classDeclaration} : {interfaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}{GenerateConstraints(interfaceSymbol)} diff --git a/Refit.Tests/AuthenticatedClientHandlerTests.cs b/Refit.Tests/AuthenticatedClientHandlerTests.cs index d771592fb..9a4df23d2 100644 --- a/Refit.Tests/AuthenticatedClientHandlerTests.cs +++ b/Refit.Tests/AuthenticatedClientHandlerTests.cs @@ -26,6 +26,18 @@ public interface IMyAuthenticatedService Task GetAuthenticatedWithTokenInMethod([Authorize("Bearer")] string token); } + public interface IInheritedAuthenticatedServiceWithHeaders : IAuthenticatedServiceWithHeaders + { + [Get("/get-inherited-thing")] + Task GetInheritedThing(); + } + + [Headers("Authorization: Bearer")] + public interface IAuthenticatedServiceWithHeaders + { + [Get("/get-base-thing")] + Task GetThingFromBase(); + } [Fact] public void DefaultHandlerIsHttpClientHandler() @@ -146,5 +158,51 @@ public async void AuthenticatedHandlerWithTokenInParameterUsesAuth() Assert.Equal("Ok", result); } + + [Fact] + public async void AuthentictedMethodFromBaseClassWithHeadersAttributeUsesAuth() + { + var handler = new MockHttpMessageHandler(); + var settings = new RefitSettings() + { + AuthorizationHeaderValueGetter = () => Task.FromResult("tokenValue"), + HttpMessageHandlerFactory = () => handler + }; + + handler.Expect(HttpMethod.Get, "http://api/get-base-thing") + .WithHeaders("Authorization", "Bearer tokenValue") + .Respond("text/plain", "Ok"); + + var fixture = RestService.For("http://api", settings); + + var result = await fixture.GetThingFromBase(); + + handler.VerifyNoOutstandingExpectation(); + + Assert.Equal("Ok", result); + } + + [Fact] + public async void AuthentictedMethodFromInheritedClassWithHeadersAttributeUsesAuth() + { + var handler = new MockHttpMessageHandler(); + var settings = new RefitSettings() + { + AuthorizationHeaderValueGetter = () => Task.FromResult("tokenValue"), + HttpMessageHandlerFactory = () => handler + }; + + handler.Expect(HttpMethod.Get, "http://api/get-inherited-thing") + .WithHeaders("Authorization", "Bearer tokenValue") + .Respond("text/plain", "Ok"); + + var fixture = RestService.For("http://api", settings); + + var result = await fixture.GetInheritedThing(); + + handler.VerifyNoOutstandingExpectation(); + + Assert.Equal("Ok", result); + } } }