From 90f6488f0a6baa6f3efb454873022e2dba1db59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20P=C3=B3r?= Date: Wed, 28 Aug 2024 18:09:53 +0200 Subject: [PATCH] Adding some documentation --- .../HttpClientUITestContextExtensions.cs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs b/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs index 105e45d65..1512610b2 100644 --- a/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs @@ -19,10 +19,14 @@ namespace Lombiq.Tests.UI.Extensions; Justification = "Disposed by the HttpClient.")] public static class HttpClientUITestContextExtensions { + /// + /// Creates a new and authorizes it with a Bearer token that is created based on the provided + /// and . + /// public static async Task CreateAndAuthorizeClientAsync( this UITestContext context, - string clientId = null, - string clientSecret = null) + string clientId = "UITest", + string clientSecret = "Password") { var handler = new HttpClientHandler { @@ -35,8 +39,6 @@ public static async Task CreateAndAuthorizeClientAsync( BaseAddress = context.Scope.BaseUri, }; - clientId ??= "UITest"; - clientSecret ??= "Password"; using var requestBody = new FormUrlEncodedContent( [ new KeyValuePair("grant_type", "client_credentials"), @@ -59,13 +61,24 @@ public static async Task CreateAndAuthorizeClientAsync( return client; } - // add some documentation - public static async Task GetAndReadResponseContentAsync(this UITestContext context, HttpClient client, string requestUri) + /// + /// Issues a GET request to the given using the provided . + /// + /// The response's as a string. + public static async Task GetAndReadResponseContentAsync( + this UITestContext context, + HttpClient client, + string requestUri) { var response = await client.GetAsync(requestUri); return await response.Content.ReadAsStringAsync(); } + /// + /// Issues a POST request to the given using the provided and + /// . + /// + /// The response's as a string. public static async Task PostAndReadResponseContentAsync( this UITestContext context, HttpClient client, @@ -73,8 +86,8 @@ public static async Task PostAndReadResponseContentAsync( string json) { var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); - var newCustomer = await client.PostAsync(requestUri, stringContent); + var response = await client.PostAsync(requestUri, stringContent); - return await newCustomer.Content.ReadAsStringAsync(); + return await response.Content.ReadAsStringAsync(); } }