-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthyReplay.cs
More file actions
62 lines (52 loc) · 1.57 KB
/
Copy pathHealthyReplay.cs
File metadata and controls
62 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env dotnet
#:include ../src/Fidelity/Replay.cs
#:package Refit@8.0.0
using Refit;
using System.Text.Json;
using System.Text.Json.Serialization;
var replay = new ReplayHttpMessageHandler(ReplayFixture.Read("fixtures/healthy.json"));
using var httpClient = new HttpClient(replay)
{
BaseAddress = new Uri("https://fidelity.invalid/")
};
var client = RestService.For<IHealthyApi>(httpClient, new RefitSettings
{
ContentSerializer = new SystemTextJsonContentSerializer(new JsonSerializerOptions
{
TypeInfoResolver = HealthyJsonContext.Default
})
});
var exitCode = await Fidelity.RunAsync(
"healthy replay",
replay,
() => client.GetHealthAsync(),
expectations =>
{
expectations.Equal("result.status", "ok", response => response.Result?.Status);
expectations.Equal("result.message", "replay-is-real", response => response.Result?.Message);
expectations.Equal("result.count", 3, response => response.Result?.Count);
});
return exitCode;
public interface IHealthyApi
{
[Get("/health")]
Task<HealthyResponse> GetHealthAsync();
}
public sealed class HealthyResponse
{
[JsonPropertyName("result")]
public HealthyResult? Result { get; set; }
}
public sealed class HealthyResult
{
[JsonPropertyName("status")]
public string? Status { get; set; }
[JsonPropertyName("message")]
public string? Message { get; set; }
[JsonPropertyName("count")]
public int Count { get; set; }
}
[JsonSerializable(typeof(HealthyResponse))]
internal partial class HealthyJsonContext : JsonSerializerContext
{
}