Skip to content

Commit cd4f0b9

Browse files
Add test for benchmarks
Add a unit test to help prevent the benchmarks get broken again in the future.
1 parent c5d8e47 commit cd4f0b9

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

tests/HttpClientInterception.Benchmarks/GitHubJsonSerializerContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JustEat.HttpClientInterception;
88

9-
[JsonSerializable(typeof(Organization))]
9+
[JsonSerializable(typeof(GitHubOrganization))]
1010
internal sealed partial class GitHubJsonSerializerContext : JsonSerializerContext
1111
{
1212
}

tests/HttpClientInterception.Benchmarks/Organization.cs renamed to tests/HttpClientInterception.Benchmarks/GitHubOrganization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace JustEat.HttpClientInterception;
77

8-
public sealed class Organization
8+
public sealed class GitHubOrganization
99
{
1010
[JsonPropertyName("login")]
1111
public string Login { get; set; }

tests/HttpClientInterception.Benchmarks/IGitHub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ namespace JustEat.HttpClientInterception;
99
internal interface IGitHub
1010
{
1111
[Get("/orgs/{organization}")]
12-
Task<Organization> GetOrganizationAsync(string organization);
12+
Task<GitHubOrganization> GetOrganizationAsync(string organization);
1313
}

tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,17 @@ public async Task<JsonDocument> GetJsonDocument()
8888
}
8989

9090
[Benchmark]
91-
public async Task<Organization> GetJsonObject()
92-
=> await _client.GetFromJsonAsync<Organization>("https://api.github.com/orgs/justeattakeaway");
91+
public async Task<GitHubOrganization> GetJsonObject()
92+
=> await _client.GetFromJsonAsync<GitHubOrganization>("https://api.github.com/orgs/justeattakeaway");
9393

9494
#if !NETFRAMEWORK
9595
[Benchmark]
96-
public async Task<Organization> GetJsonObjectSourceGenerator()
97-
=> await _client.GetFromJsonAsync("https://api.github.com/orgs/justeattakeaway", GitHubJsonSerializerContext.Default.Organization);
96+
public async Task<GitHubOrganization> GetJsonObjectSourceGenerator()
97+
=> await _client.GetFromJsonAsync("https://api.github.com/orgs/justeattakeaway", GitHubJsonSerializerContext.Default.GitHubOrganization);
9898
#endif
9999

100100
[Benchmark]
101-
public async Task<Organization> GetJsonObjectWithRefit()
101+
public async Task<GitHubOrganization> GetJsonObjectWithRefit()
102102
=> await _service.GetOrganizationAsync("justeattakeaway");
103103

104104
[Benchmark]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Just Eat, 2017. All rights reserved.
2+
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
3+
4+
namespace JustEat.HttpClientInterception;
5+
6+
public static class BenchmarkTests
7+
{
8+
[Fact]
9+
public static async Task Benchmarks_Do_Not_Throw_An_Exception()
10+
{
11+
// Arrange
12+
var target = new InterceptionBenchmarks();
13+
14+
// Act and Assert
15+
await Should.NotThrowAsync(target.GetBytes);
16+
await Should.NotThrowAsync(target.GetHtml);
17+
await Should.NotThrowAsync(target.GetJsonDocument);
18+
await Should.NotThrowAsync(target.GetJsonObject);
19+
await Should.NotThrowAsync(target.GetJsonObjectSourceGenerator);
20+
await Should.NotThrowAsync(target.GetJsonObjectWithRefit);
21+
await Should.NotThrowAsync(target.GetStream);
22+
}
23+
}

tests/HttpClientInterception.Tests/JustEat.HttpClientInterception.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</ItemGroup>
1515
<ItemGroup>
1616
<ProjectReference Include="..\..\src\HttpClientInterception\JustEat.HttpClientInterception.csproj" />
17+
<ProjectReference Include="..\HttpClientInterception.Benchmarks\JustEat.HttpClientInterception.Benchmarks.csproj" />
1718
</ItemGroup>
1819
<ItemGroup>
1920
<PackageReference Include="MarkdownSnippets.MsBuild" />

0 commit comments

Comments
 (0)