Skip to content

Commit

Permalink
Additional documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 18, 2023
1 parent dd15a1c commit 07f58f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Testing/Testing/TestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace GenHTTP.Testing
public static class TestExtensions
{

/// <summary>
/// Reads the response body as a string.
/// </summary>
/// <param name="response">The response to read</param>
/// <returns>The content of the HTTP response</returns>
public static async ValueTask<string> GetContent(this HttpResponseMessage response) => await response.Content.ReadAsStringAsync();

public static string? GetHeader(this HttpResponseMessage response, string key)
Expand Down
15 changes: 15 additions & 0 deletions Testing/Testing/TestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,25 @@ public HttpRequestMessage GetRequest(string? path = null, HttpMethod? method = n
return new HttpRequestMessage(method ?? HttpMethod.Get, GetUrl(path));
}

/// <summary>
/// Runs a GET request against the given path.
/// </summary>
/// <param name="path">The path to be fetched</param>
/// <param name="client">The configured HTTP client to be used or null, if the default client should be used</param>
/// <returns>The response returned by the server</returns>
public async Task<HttpResponseMessage> GetResponseAsync(string? path = null, HttpClient? client = null)
{
var actualClient = client ?? _DefaultClient;

return await actualClient.GetAsync(GetUrl(path));
}

/// <summary>
/// Executes the given request against the test server.
/// </summary>
/// <param name="message">The request to be executed</param>
/// <param name="client">The configured HTTP client to be used or null, if the default client should be used</param>
/// <returns>The response returned by the server</returns>
public async Task<HttpResponseMessage> GetResponseAsync(HttpRequestMessage message, HttpClient? client = null)
{
var actualClient = client ?? _DefaultClient;
Expand Down Expand Up @@ -197,6 +209,9 @@ protected virtual void Dispose(bool disposing)
}
}

/// <summary>
/// Stops the test host and releases all resources.
/// </summary>
public void Dispose()
{
Dispose(true);
Expand Down

0 comments on commit 07f58f5

Please sign in to comment.