Skip to content

Commit 33e57b8

Browse files
Merge pull request #444 from nclient/main
[Release] 0.13.0
2 parents 1351991 + 06b81d3 commit 33e57b8

File tree

253 files changed

+4681
-2397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+4681
-2397
lines changed

.github/actions/release-info/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ runs:
2424
steps:
2525
- id: version-prefix-generator
2626
env:
27-
default-version-prefix: 0.12.2
27+
default-version-prefix: 0.13.0
2828
run: |
2929
if [[ "${{ inputs.version-prefix || '' }}" != "" ]]; then
3030
echo "::set-output name=version-prefix::${{ inputs.version-prefix }}"

.github/workflows/sonarcloud-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
/d:sonar.cs.nunit.reportsPaths="**/TestResults/TestResult-*.xml" `
5959
/d:sonar.cs.opencover.reportsPaths="**/TestResults/coverage.*.opencover.xml" `
6060
/d:sonar.coverage.exclusions=benchmark/**,sandbox/**,tests/**,**/AspNetRouting/**,**/Castle/**,**/AspNetBinding/**,**/AspNetCore/** `
61-
/d:sonar.cpd.exclusions=**/AspNetRouting/**,**/Castle/**,**/AspNetBinding/**,**/AspNetCore/**
61+
/d:sonar.cpd.exclusions=benchmark/**,**/AspNetRouting/**,**/Castle/**,**/AspNetBinding/**,**/AspNetCore/**
6262
- name: Build solution
6363
shell: powershell
6464
run: dotnet build ${{ env.solution }} --configuration Release

NClient.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03 tools", "03 tools", "{7B
123123
EndProject
124124
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NClient.DotNetTool.Tests", "tests\NClient.Tools\NClient.DotNetTool.Tests\NClient.DotNetTool.Tests.csproj", "{4EA0CDB4-8C81-4F10-BDC9-4DF8AE638D25}"
125125
EndProject
126+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NClient.Providers.Serialization.SystemTextJson.Tests", "tests\NClient.Providers\NClient.Providers.Serialization.SystemTextJson.Tests\NClient.Providers.Serialization.SystemTextJson.Tests.csproj", "{FEFE8BA5-1FFF-43F2-A09F-C0F3194413E9}"
127+
EndProject
126128
Global
127129
GlobalSection(SolutionConfigurationPlatforms) = preSolution
128130
Debug|Any CPU = Debug|Any CPU
@@ -361,6 +363,11 @@ Global
361363
{4EA0CDB4-8C81-4F10-BDC9-4DF8AE638D25}.Release|Any CPU.ActiveCfg = Release|Any CPU
362364
{4EA0CDB4-8C81-4F10-BDC9-4DF8AE638D25}.Release|Any CPU.Build.0 = Release|Any CPU
363365
{4EA0CDB4-8C81-4F10-BDC9-4DF8AE638D25}.TestRelease|Any CPU.ActiveCfg = Release|Any CPU
366+
{FEFE8BA5-1FFF-43F2-A09F-C0F3194413E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
367+
{FEFE8BA5-1FFF-43F2-A09F-C0F3194413E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
368+
{FEFE8BA5-1FFF-43F2-A09F-C0F3194413E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
369+
{FEFE8BA5-1FFF-43F2-A09F-C0F3194413E9}.Release|Any CPU.Build.0 = Release|Any CPU
370+
{FEFE8BA5-1FFF-43F2-A09F-C0F3194413E9}.TestRelease|Any CPU.ActiveCfg = Release|Any CPU
364371
EndGlobalSection
365372
GlobalSection(SolutionProperties) = preSolution
366373
HideSolutionNode = FALSE
@@ -412,6 +419,7 @@ Global
412419
{97E9E39C-F507-4387-8420-A31E7204D9DE} = {FD8C88D4-E6FF-4A83-8898-62E390AEF8F5}
413420
{7BA62D11-E7B6-4879-903E-AC718C79DA96} = {F3AF19D7-1D80-4449-98CC-96BC13FF8103}
414421
{4EA0CDB4-8C81-4F10-BDC9-4DF8AE638D25} = {7BA62D11-E7B6-4879-903E-AC718C79DA96}
422+
{FEFE8BA5-1FFF-43F2-A09F-C0F3194413E9} = {B1BCB5AE-6A5E-49F7-A00A-6B2931DF628C}
415423
EndGlobalSection
416424
GlobalSection(ExtensibilityGlobals) = postSolution
417425
SolutionGuid = {244A4C58-8FA7-496C-ABCF-72F333149A20}

Tests.slnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"tests\\NClient.Providers\\NClient.Providers.Mapping.HttpResponses.Tests\\NClient.Providers.Mapping.HttpResponses.Tests.csproj",
1010
"tests\\NClient.Providers\\NClient.Providers.Mapping.LanguageExt.Tests\\NClient.Providers.Mapping.LanguageExt.Tests.csproj",
1111
"tests\\NClient.Providers\\NClient.Providers.Transport.SystemNetHttp.Tests\\NClient.Providers.Transport.SystemNetHttp.Tests.csproj",
12+
"tests\\NClient.Providers\\NClient.Providers.Serialization.SystemTextJson.Tests\\NClient.Providers.Serialization.SystemTextJson.Tests.csproj",
1213
"tests\\NClient.Providers\\NClient.Providers.Serialization.SystemXml.Tests\\NClient.Providers.Serialization.SystemXml.Tests.csproj",
1314
"tests\\NClient.Providers\\NClient.Providers.Serialization.ProtobufNet.Tests\\NClient.Providers.Serialization.ProtobufNet.Tests.csproj",
1415
"tests\\NClient.Providers\\NClient.Providers.Serialization.MessagePack.Tests\\NClient.Providers.Serialization.MessagePack.Tests.csproj",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Net.Http;
2+
using Flurl.Http.Configuration;
3+
using RichardSzalay.MockHttp;
4+
5+
namespace NClient.Benchmark.Client.Clients.Flurl
6+
{
7+
public class FlurlHttpClientFactory : DefaultHttpClientFactory
8+
{
9+
private readonly MockHttpMessageHandler _mockHttpMessageHandler;
10+
11+
public FlurlHttpClientFactory(MockHttpMessageHandler mockHttpMessageHandler)
12+
{
13+
_mockHttpMessageHandler = mockHttpMessageHandler;
14+
}
15+
16+
public override HttpMessageHandler CreateMessageHandler()
17+
{
18+
return _mockHttpMessageHandler;
19+
}
20+
}
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.IO;
2+
using System.Text.Json;
3+
using Flurl.Http.Configuration;
4+
5+
namespace NClient.Benchmark.Client.Clients.Flurl
6+
{
7+
public class FlurlSystemJsonSerializer : ISerializer
8+
{
9+
private readonly JsonSerializerOptions? _options;
10+
11+
public FlurlSystemJsonSerializer(JsonSerializerOptions? options = null)
12+
{
13+
_options = options;
14+
}
15+
16+
public T Deserialize<T>(string s)
17+
{
18+
return JsonSerializer.Deserialize<T>(s, _options)!;
19+
}
20+
21+
public T Deserialize<T>(Stream stream)
22+
{
23+
using var reader = new StreamReader(stream);
24+
return Deserialize<T>(reader.ReadToEnd());
25+
}
26+
27+
public string Serialize(object obj)
28+
{
29+
return JsonSerializer.Serialize(obj, _options);
30+
}
31+
}
32+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Text.Json;
2+
using Flurl.Http;
3+
using NClient.Benchmark.Client.Helpers;
4+
using NClient.Benchmark.Client.HttpMock;
5+
6+
namespace NClient.Benchmark.Client.Clients.Flurl
7+
{
8+
public class TestFlurlClient
9+
{
10+
private readonly IFlurlClient _flurlClient;
11+
12+
public TestFlurlClient(JsonSerializerOptions jsonSerializerOptions)
13+
{
14+
_flurlClient = new FlurlClient(MockDtoHttpMessageHandlerBuilder.Host).Configure(settings =>
15+
{
16+
settings.HttpClientFactory = new FlurlHttpClientFactory(MockDtoHttpMessageHandlerBuilder.Build(DtoProvider.Get()));
17+
settings.JsonSerializer = new FlurlSystemJsonSerializer(jsonSerializerOptions);
18+
});
19+
}
20+
21+
public TestFlurlClient()
22+
{
23+
_flurlClient = new FlurlClient(MockIdHttpMessageHandlerBuilder.Host).Configure(settings =>
24+
{
25+
settings.HttpClientFactory = new FlurlHttpClientFactory(MockIdHttpMessageHandlerBuilder
26+
.Build(paramName: "id", IdProvider.Get()));
27+
settings.JsonSerializer = new FlurlSystemJsonSerializer(new JsonSerializerOptions());
28+
});
29+
}
30+
31+
public void Send<T>(T data)
32+
{
33+
var response = _flurlClient.Request(MockDtoHttpMessageHandlerBuilder.Path)
34+
.PostJsonAsync(data).GetAwaiter().GetResult();
35+
response.GetJsonAsync<T>().GetAwaiter().GetResult();
36+
}
37+
38+
public void SendWithoutBody<T>(T data) where T : struct
39+
{
40+
var response = _flurlClient.Request(MockIdHttpMessageHandlerBuilder.Path)
41+
.SetQueryParam("id", data.ToString())
42+
.GetAsync().GetAwaiter().GetResult();
43+
response.GetJsonAsync<T>().GetAwaiter().GetResult();
44+
}
45+
}
46+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Net.Http.Json;
4+
using System.Text;
5+
using System.Text.Json;
6+
using NClient.Benchmark.Client.Helpers;
7+
using NClient.Benchmark.Client.HttpMock;
8+
9+
namespace NClient.Benchmark.Client.Clients.HttpClient
10+
{
11+
public class TestHttpClient
12+
{
13+
private readonly JsonSerializerOptions? _jsonSerializerOptions;
14+
private readonly System.Net.Http.HttpClient _httpClient;
15+
16+
public TestHttpClient(JsonSerializerOptions jsonSerializerOptions)
17+
{
18+
_jsonSerializerOptions = jsonSerializerOptions;
19+
20+
_httpClient = new System.Net.Http.HttpClient(MockDtoHttpMessageHandlerBuilder.Build(DtoProvider.Get()))
21+
{
22+
BaseAddress = new Uri(MockDtoHttpMessageHandlerBuilder.Host)
23+
};
24+
}
25+
26+
public TestHttpClient()
27+
{
28+
_httpClient = new System.Net.Http.HttpClient(MockIdHttpMessageHandlerBuilder
29+
.Build(paramName: "id", IdProvider.Get()))
30+
{
31+
BaseAddress = new Uri(MockIdHttpMessageHandlerBuilder.Host)
32+
};
33+
}
34+
35+
public void Send<T>(T data)
36+
{
37+
var json = JsonSerializer.Serialize(data, _jsonSerializerOptions);
38+
var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
39+
var result = _httpClient
40+
.PostAsync(MockDtoHttpMessageHandlerBuilder.Path, httpContent)
41+
.GetAwaiter()
42+
.GetResult();
43+
result.EnsureSuccessStatusCode();
44+
JsonSerializer.DeserializeAsync<T>(result.Content.ReadAsStream(), _jsonSerializerOptions);
45+
}
46+
47+
public void SendWithoutBody<T>(T data) where T : struct
48+
{
49+
var result = _httpClient
50+
.GetAsync(MockIdHttpMessageHandlerBuilder.Path + $"?{"id"}={data.ToString()}")
51+
.GetAwaiter()
52+
.GetResult();
53+
result.EnsureSuccessStatusCode();
54+
result.Content.ReadFromJsonAsync(typeof(T)).GetAwaiter().GetResult();
55+
}
56+
}
57+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Threading;
4+
using NClient.Benchmark.Client.Helpers;
5+
using NClient.Benchmark.Client.HttpMock;
6+
7+
namespace NClient.Benchmark.Client.Clients.NClient
8+
{
9+
public class TestNClient<TClient> where TClient : class
10+
{
11+
private readonly TClient _nclient;
12+
13+
public TestNClient(JsonSerializerOptions jsonSerializerOptions)
14+
{
15+
_nclient = NClientGallery.Clients.GetCustom().For<TClient>(MockDtoHttpMessageHandlerBuilder.Host)
16+
.UsingRestApi()
17+
.UsingSystemNetHttpTransport(new System.Net.Http.HttpClient(MockDtoHttpMessageHandlerBuilder.Build(DtoProvider.Get()))
18+
{
19+
Timeout = Timeout.InfiniteTimeSpan
20+
})
21+
.UsingSystemTextJsonSerialization(jsonSerializerOptions)
22+
.WithResponseToHttpResponseMapping()
23+
.Build();
24+
}
25+
26+
public TestNClient()
27+
{
28+
_nclient = NClientGallery.Clients.GetCustom().For<TClient>(MockIdHttpMessageHandlerBuilder.Host)
29+
.UsingRestApi()
30+
.UsingSystemNetHttpTransport(new System.Net.Http.HttpClient(MockIdHttpMessageHandlerBuilder
31+
.Build(paramName: "id", IdProvider.Get()))
32+
{
33+
Timeout = Timeout.InfiniteTimeSpan
34+
})
35+
.UsingSystemTextJsonSerialization(new JsonSerializerOptions())
36+
.WithResponseToHttpResponseMapping()
37+
.Build();
38+
}
39+
40+
public void Send(Action<TClient> action)
41+
{
42+
action(_nclient);
43+
}
44+
}
45+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Text.Json;
3+
using NClient.Benchmark.Client.Helpers;
4+
using NClient.Benchmark.Client.HttpMock;
5+
using Refit;
6+
7+
namespace NClient.Benchmark.Client.Clients.Refit
8+
{
9+
public class TestRefitClient<TClient> where TClient : class
10+
{
11+
private readonly TClient _refitClient;
12+
13+
public TestRefitClient(JsonSerializerOptions jsonSerializerOptions)
14+
{
15+
_refitClient = RestService.For<TClient>(MockDtoHttpMessageHandlerBuilder.Host, new RefitSettings
16+
{
17+
ContentSerializer = new SystemTextJsonContentSerializer(jsonSerializerOptions),
18+
HttpMessageHandlerFactory = () => MockDtoHttpMessageHandlerBuilder.Build(DtoProvider.Get())
19+
});
20+
}
21+
22+
public TestRefitClient()
23+
{
24+
_refitClient = RestService.For<TClient>(MockIdHttpMessageHandlerBuilder.Host, new RefitSettings
25+
{
26+
ContentSerializer = new SystemTextJsonContentSerializer(new JsonSerializerOptions()),
27+
HttpMessageHandlerFactory = () => MockIdHttpMessageHandlerBuilder
28+
.Build(paramName: "id", IdProvider.Get())
29+
});
30+
}
31+
32+
public void Send(Action<TClient> action)
33+
{
34+
action(_refitClient);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)