Skip to content

Commit

Permalink
feat: added non refit overrides base test
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Oct 20, 2024
1 parent 4a16d7f commit 2790f90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Refit.Tests/InheritedInterfacesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public interface IImplementTheInterfaceAndUseRefit : IAmInterfaceEWithNoRefit<in
[Get("/DoSomethingElse")]
public new Task DoSomethingElse();
}

public interface IImplementTheInterfaceAndDontUseRefit : IAmInterfaceD
{
#pragma warning disable CS0108 // Member hides inherited member; missing new keyword
Task<string> Test();
#pragma warning restore CS0108 // Member hides inherited member; missing new keyword
}

public interface IMyClient
{
[Get("/")]
Expand Down
28 changes: 28 additions & 0 deletions Refit.Tests/RestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,34 @@ await Assert.ThrowsAsync<NotImplementedException>(
mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public async Task InheritedInterfaceWithoutRefitMethodsOverrideBaseTest()
{
var mockHttp = new MockHttpMessageHandler();

var settings = new RefitSettings { HttpMessageHandlerFactory = () => mockHttp };

var fixture = RestService.For<IImplementTheInterfaceAndDontUseRefit>(
"https://httpbin.org",
settings
);

// inherited non refit method should throw NotImplementedException
await Assert.ThrowsAsync<NotImplementedException>(
() => fixture.Test()
);
mockHttp.VerifyNoOutstandingExpectation();

// base Refit method should respond
mockHttp
.Expect(HttpMethod.Get, "https://httpbin.org/get")
.WithQueryString("result", "Test")
.Respond("application/json", nameof(IAmInterfaceD.Test));

await ((IAmInterfaceD)fixture).Test();
mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public async Task DictionaryDynamicQueryParametersTest()
{
Expand Down

0 comments on commit 2790f90

Please sign in to comment.