Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 6 SDK update #1214

Merged
merged 4 commits into from
Aug 5, 2021
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/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-->
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
2 changes: 1 addition & 1 deletion Refit.Tests/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public RefitTestsTestNestedINestedGitHubApi(global::System.Net.Http.HttpClient c
},
}.RunAsync();
}


[Fact]
public async Task GenerateInterfaceStubsWithoutNamespaceSmokeTest()
Expand Down
3 changes: 2 additions & 1 deletion Refit.Tests/Refit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
Expand Down
67 changes: 67 additions & 0 deletions Refit.Tests/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Threading;
using System.Threading.Tasks;

using Microsoft.AspNetCore.WebUtilities;

using Xunit;

namespace Refit.Tests
Expand All @@ -26,6 +28,12 @@ public interface IRestMethodInfoTests
[Get("/foo/bar/{id}")]
Task<string> FetchSomeStuff(int id);

[Get("/foo/bar/{id}?param1={id}&param2={id}")]
Task<string> FetchSomeStuffWithTheSameId(int id);

[Get("/foo/bar?param=first {id} and second {id}")]
Task<string> FetchSomeStuffWithTheIdInAParameterMultipleTimes(int id);

[Get("/foo/bar/{**path}/{id}")]
Task<string> FetchSomeStuffWithRoundTrippingParam(string path, int id);

Expand Down Expand Up @@ -503,6 +511,29 @@ public void ParameterMappingSmokeTest()
Assert.Empty(fixture.QueryParameterMap);
Assert.Null(fixture.BodyParameterInfo);
}

[Fact]
public void ParameterMappingWithTheSameIdInAFewPlaces()
{
var input = typeof(IRestMethodInfoTests);
var fixture = new RestMethodInfo(input, input.GetMethods().First(x => x.Name == nameof(IRestMethodInfoTests.FetchSomeStuffWithTheSameId)));
Assert.Equal("id", fixture.ParameterMap[0].Name);
Assert.Equal(ParameterType.Normal, fixture.ParameterMap[0].Type);
Assert.Empty(fixture.QueryParameterMap);
Assert.Null(fixture.BodyParameterInfo);
}

[Fact]
public void ParameterMappingWithTheSameIdInTheQueryParameter()
{
var input = typeof(IRestMethodInfoTests);
var fixture = new RestMethodInfo(input, input.GetMethods().First(x => x.Name == nameof(IRestMethodInfoTests.FetchSomeStuffWithTheIdInAParameterMultipleTimes)));
Assert.Equal("id", fixture.ParameterMap[0].Name);
Assert.Equal(ParameterType.Normal, fixture.ParameterMap[0].Type);
Assert.Empty(fixture.QueryParameterMap);
Assert.Null(fixture.BodyParameterInfo);
}


[Fact]
public void ParameterMappingWithRoundTrippingSmokeTest()
Expand Down Expand Up @@ -1150,6 +1181,12 @@ public interface IDummyHttpApi
[Headers("Api-Version: ")]
Task<string> FetchSomeStuffWithEmptyHardcodedHeader(int id);

[Get("/foo/bar/{id}?param1={id}&param2={id}")]
Task<string> FetchSomeStuffWithTheSameId(int id);

[Get("/foo/bar?param=first {id} and second {id}")]
Task<string> FetchSomeStuffWithTheIdInAParameterMultipleTimes(int id);

[Post("/foo/bar/{id}")]
[Headers("Content-Type: literally/anything")]
Task<string> PostSomeStuffWithHardCodedContentTypeHeader(int id, [Body] string content);
Expand Down Expand Up @@ -2336,6 +2373,36 @@ public void DefaultCollectionFormatCanBeOverridenByQueryAttribute()
Assert.Equal("/query?numbers=1%2C2%2C3", output.RequestUri.PathAndQuery);
}

[Fact]
public void RequestWithParameterInMultiplePlaces()
{
var fixture = new RequestBuilderImplementation<IDummyHttpApi>();

var factory = fixture.BuildRequestFactoryForMethod(nameof(IDummyHttpApi.FetchSomeStuffWithTheSameId));
var output = factory(new object[] { "theId" });

var uri = new Uri(new Uri("http://api"), output.RequestUri);

var builder = new UriBuilder(uri);
var qs = QueryHelpers.ParseQuery(uri.Query);
Assert.Equal("/foo/bar/theId", builder.Path);
Assert.Equal("theId", qs["param1"]);
Assert.Equal("theId", qs["param2"]);
}

[Fact]
public void RequestWithParameterInAQueryParameterMultipleTimes()
{
var fixture = new RequestBuilderImplementation<IDummyHttpApi>();

var factory = fixture.BuildRequestFactoryForMethod(nameof(IDummyHttpApi.FetchSomeStuffWithTheIdInAParameterMultipleTimes));
var output = factory(new object[] { "theId" });

var uri = new Uri(new Uri("http://api"), output.RequestUri);
Assert.Equal("/foo/bar?param=first%20theId%20and%20second%20theId", uri.PathAndQuery);
}


[Theory]
[InlineData("QueryWithArrayFormattedAsMulti", "/query?numbers=1&numbers=2&numbers=3")]
[InlineData("QueryWithArrayFormattedAsCsv", "/query?numbers=1%2C2%2C3")]
Expand Down
9 changes: 8 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ stages:
- task: UseDotNet@2
displayName: Use .NET Core 5.x SDK
inputs:
version: 5.0.x
version: 6.x
performMultiLevelLookup: true
includePreviewVersions: true

- task: UseDotNet@2
displayName: Use .NET Core 5.x Runtime
inputs:
version: 5.0.x
packageType: runtime
performMultiLevelLookup: true

- task: DotNetCoreCLI@2
inputs:
command: custom
Expand Down