Skip to content

Commit

Permalink
Added unit test for brotli
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Mar 19, 2022
1 parent a7f49da commit 6a7c371
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions RuriLib.Http.Tests/RLHttpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task SendAsync_Get_Headers()
message.Headers.Add("User-Agent", userAgent);

var response = await RequestAsync(message);
var userAgentActual = await GetJsonStringValueAsync(response, "user-agent");
var userAgentActual = await GetJsonValueAsync<string>(response, "user-agent");

Assert.NotEmpty(userAgentActual);
Assert.Equal(userAgent, userAgentActual);
Expand Down Expand Up @@ -207,6 +207,21 @@ public async Task SendAsync_Get_ExplicitHostHeader()
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
public async Task SendAsync_Brotli_Decompress()
{
var message = new HttpRequest
{
Method = HttpMethod.Get,
Uri = new Uri("https://nghttp2.org/httpbin/brotli")
};

var response = await RequestAsync(message);
var actual = await GetJsonValueAsync<bool>(response, "brotli");

Assert.True(actual);
}

private static async Task<HttpResponse> RequestAsync(HttpRequest request)
{
var settings = new ProxySettings();
Expand All @@ -216,16 +231,16 @@ private static async Task<HttpResponse> RequestAsync(HttpRequest request)
return await client.SendAsync(request);
}

private static async Task<string> GetJsonStringValueAsync(HttpResponse response, string valueName)
private static async Task<T> GetJsonValueAsync<T>(HttpResponse response, string valueName)
{
var source = await response.Content.ReadAsStringAsync();
var obj = JObject.Parse(source);

var result = obj.TryGetValue(valueName, out var token);

return result
? token.Value<string>()
: string.Empty;
? token.Value<T>()
: default;
}

private static async Task<Dictionary<string, string>> GetJsonDictionaryValueAsync(HttpResponse response, string valueName)
Expand Down

0 comments on commit 6a7c371

Please sign in to comment.