Skip to content

Commit

Permalink
Add test for benchmarks
Browse files Browse the repository at this point in the history
Add a unit test to help prevent the benchmarks get broken again in the future.
  • Loading branch information
martincostello committed Feb 6, 2024
1 parent c5d8e47 commit cd4f0b9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JustEat.HttpClientInterception;

[JsonSerializable(typeof(Organization))]
[JsonSerializable(typeof(GitHubOrganization))]
internal sealed partial class GitHubJsonSerializerContext : JsonSerializerContext
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace JustEat.HttpClientInterception;

public sealed class Organization
public sealed class GitHubOrganization
{
[JsonPropertyName("login")]
public string Login { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion tests/HttpClientInterception.Benchmarks/IGitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace JustEat.HttpClientInterception;
internal interface IGitHub
{
[Get("/orgs/{organization}")]
Task<Organization> GetOrganizationAsync(string organization);
Task<GitHubOrganization> GetOrganizationAsync(string organization);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ public async Task<JsonDocument> GetJsonDocument()
}

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

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

[Benchmark]
public async Task<Organization> GetJsonObjectWithRefit()
public async Task<GitHubOrganization> GetJsonObjectWithRefit()
=> await _service.GetOrganizationAsync("justeattakeaway");

[Benchmark]
Expand Down
23 changes: 23 additions & 0 deletions tests/HttpClientInterception.Tests/BenchmarkTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Just Eat, 2017. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

namespace JustEat.HttpClientInterception;

public static class BenchmarkTests
{
[Fact]
public static async Task Benchmarks_Do_Not_Throw_An_Exception()
{
// Arrange
var target = new InterceptionBenchmarks();

// Act and Assert
await Should.NotThrowAsync(target.GetBytes);
await Should.NotThrowAsync(target.GetHtml);
await Should.NotThrowAsync(target.GetJsonDocument);
await Should.NotThrowAsync(target.GetJsonObject);
await Should.NotThrowAsync(target.GetJsonObjectSourceGenerator);
await Should.NotThrowAsync(target.GetJsonObjectWithRefit);
await Should.NotThrowAsync(target.GetStream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\HttpClientInterception\JustEat.HttpClientInterception.csproj" />
<ProjectReference Include="..\HttpClientInterception.Benchmarks\JustEat.HttpClientInterception.Benchmarks.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MarkdownSnippets.MsBuild" />
Expand Down

0 comments on commit cd4f0b9

Please sign in to comment.