Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Refit.Tests/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void GenerateTemplateInfoForInterfaceListSmokeTest()
.ToList();

var result = fixture.GenerateTemplateInfoForInterfaceList(input);
Assert.Equal(10, result.ClassList.Count);
Assert.Equal(11, result.ClassList.Count);
}

[Fact]
Expand Down
32 changes: 32 additions & 0 deletions Refit.Tests/RefitStubs.Net46.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,38 @@ public virtual Task<ApiResponse<Stream>> GetRemoteFileWithMetadata(string filena
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[Preserve]
[global::System.Reflection.Obfuscation(Exclude=true)]
partial class AutoGeneratedITrimTrailingForwardSlashApi : ITrimTrailingForwardSlashApi
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly IRequestBuilder requestBuilder;

/// <inheritdoc />
public AutoGeneratedITrimTrailingForwardSlashApi(HttpClient client, IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}

/// <inheritdoc />
public virtual Task Get()
{
var arguments = new object[] { };
var func = requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { });
return (Task)func(Client, arguments);
}
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;
Expand Down
32 changes: 32 additions & 0 deletions Refit.Tests/RefitStubs.NetCore2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,38 @@ public virtual Task<ApiResponse<Stream>> GetRemoteFileWithMetadata(string filena
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[Preserve]
[global::System.Reflection.Obfuscation(Exclude=true)]
partial class AutoGeneratedITrimTrailingForwardSlashApi : ITrimTrailingForwardSlashApi
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly IRequestBuilder requestBuilder;

/// <inheritdoc />
public AutoGeneratedITrimTrailingForwardSlashApi(HttpClient client, IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}

/// <inheritdoc />
public virtual Task Get()
{
var arguments = new object[] { };
var func = requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { });
return (Task)func(Client, arguments);
}
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;
Expand Down
19 changes: 19 additions & 0 deletions Refit.Tests/RestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ public interface IBodylessApi
Task Head();
}

public interface ITrimTrailingForwardSlashApi
{
HttpClient Client { get; }

[Get("/someendpoint")]
Task Get();
}

public class HttpBinGet
{
public Dictionary<string, object> Args { get; set; }
Expand Down Expand Up @@ -1187,5 +1195,16 @@ public async Task CanSerializeContentAsXml()

mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public void ShouldTrimTrailingForwardSlashFromBaseUrl()
{
var expectedBaseAddress = "http://example.com/api";
var inputBaseAddress = "http://example.com/api/";

var fixture = RestService.For<ITrimTrailingForwardSlashApi>(inputBaseAddress);

Assert.Equal(fixture.Client.BaseAddress.AbsoluteUri, expectedBaseAddress);
}
}
}
2 changes: 1 addition & 1 deletion Refit/RestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static T For<T>(string hostUrl, RefitSettings settings)
}
}

var client = new HttpClient(innerHandler ?? new HttpClientHandler()) { BaseAddress = new Uri(hostUrl) };
var client = new HttpClient(innerHandler ?? new HttpClientHandler()) { BaseAddress = new Uri(hostUrl?.TrimEnd('/')) };
return For<T>(client, settings);
}

Expand Down