|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Net; |
| 5 | +using System.Net.Http; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +using RichardSzalay.MockHttp; |
| 10 | + |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace Refit.Tests |
| 14 | +{ |
| 15 | + public interface IHaveDims |
| 16 | + { |
| 17 | + [Get("")] |
| 18 | + internal Task<string> GetInternal(); |
| 19 | + |
| 20 | + // DIMs require C# 8.0 which requires .NET Core 3.x or .NET Standard 2.1 |
| 21 | +#if NETCOREAPP3_1_OR_GREATER |
| 22 | + private Task<string> GetPrivate() |
| 23 | + { |
| 24 | + return GetInternal(); |
| 25 | + } |
| 26 | + |
| 27 | + Task<string> GetDim() |
| 28 | + { |
| 29 | + return GetPrivate(); |
| 30 | + } |
| 31 | + |
| 32 | + static string GetStatic() |
| 33 | + { |
| 34 | + return nameof(IHaveDims); |
| 35 | + } |
| 36 | +#endif |
| 37 | + } |
| 38 | + |
| 39 | + // DIMs require C# 8.0 which requires .NET Core 3.x or .NET Standard 2.1 |
| 40 | +#if NETCOREAPP3_1_OR_GREATER |
| 41 | + public class DefaultInterfaceMethodTests |
| 42 | + { |
| 43 | + [Fact] |
| 44 | + public async Task InternalInterfaceMemberTest() |
| 45 | + { |
| 46 | + var mockHttp = new MockHttpMessageHandler(); |
| 47 | + |
| 48 | + var settings = new RefitSettings |
| 49 | + { |
| 50 | + HttpMessageHandlerFactory = () => mockHttp |
| 51 | + }; |
| 52 | + |
| 53 | + mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/") |
| 54 | + .Respond(HttpStatusCode.OK, "text/html", "OK"); |
| 55 | + |
| 56 | + var fixture = RestService.For<IHaveDims>("https://httpbin.org/", settings); |
| 57 | + var plainText = await fixture.GetInternal(); |
| 58 | + |
| 59 | + Assert.True(!string.IsNullOrWhiteSpace(plainText)); |
| 60 | + } |
| 61 | + |
| 62 | + [Fact] |
| 63 | + public async Task DimTest() |
| 64 | + { |
| 65 | + var mockHttp = new MockHttpMessageHandler(); |
| 66 | + |
| 67 | + var settings = new RefitSettings |
| 68 | + { |
| 69 | + HttpMessageHandlerFactory = () => mockHttp |
| 70 | + }; |
| 71 | + |
| 72 | + mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/") |
| 73 | + .Respond(HttpStatusCode.OK, "text/html", "OK"); |
| 74 | + |
| 75 | + var fixture = RestService.For<IHaveDims>("https://httpbin.org/", settings); |
| 76 | + var plainText = await fixture.GetDim(); |
| 77 | + |
| 78 | + Assert.True(!string.IsNullOrWhiteSpace(plainText)); |
| 79 | + } |
| 80 | + |
| 81 | + [Fact] |
| 82 | + public async Task InternalDimTest() |
| 83 | + { |
| 84 | + var mockHttp = new MockHttpMessageHandler(); |
| 85 | + |
| 86 | + var settings = new RefitSettings |
| 87 | + { |
| 88 | + HttpMessageHandlerFactory = () => mockHttp |
| 89 | + }; |
| 90 | + |
| 91 | + mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/") |
| 92 | + .Respond(HttpStatusCode.OK, "text/html", "OK"); |
| 93 | + |
| 94 | + var fixture = RestService.For<IHaveDims>("https://httpbin.org/", settings); |
| 95 | + var plainText = await fixture.GetInternal(); |
| 96 | + |
| 97 | + Assert.True(!string.IsNullOrWhiteSpace(plainText)); |
| 98 | + } |
| 99 | + |
| 100 | + [Fact] |
| 101 | + public void StaticInterfaceMethodTest() |
| 102 | + { |
| 103 | + var plainText = IHaveDims.GetStatic(); |
| 104 | + |
| 105 | + Assert.True(!string.IsNullOrWhiteSpace(plainText)); |
| 106 | + } |
| 107 | + } |
| 108 | +#endif |
| 109 | +} |
0 commit comments