From d34af1ac860e6535450ce85d19b6fe82295ae690 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 20 May 2026 13:18:13 +0200 Subject: [PATCH] Refactor tests to use async/await and improve naming Updated all test methods to use asynchronous programming with `async` and `await`, replacing synchronous calls with `.GetAwaiter().GetResult()`. This improves readability and aligns with modern C# practices. Renamed test methods to reflect their asynchronous nature and better describe their behavior. Updated exception handling to validate HTTP methods and request URIs while maintaining original assertions. Applied changes consistently across multiple test classes, including `CommonApiTests`, `EndpointAuthApiTests`, `EndpointParamsApiTests`, `EndpointsApiTests`, `ProfileApiTests`, `RecActionApiTests`, and `ResultApiTests`. --- tests/ReC.Tests/Client/CommonApiTests.cs | 8 ++++---- tests/ReC.Tests/Client/EndpointAuthApiTests.cs | 4 ++-- tests/ReC.Tests/Client/EndpointParamsApiTests.cs | 4 ++-- tests/ReC.Tests/Client/EndpointsApiTests.cs | 4 ++-- tests/ReC.Tests/Client/ProfileApiTests.cs | 8 ++++---- tests/ReC.Tests/Client/RecActionApiTests.cs | 4 ++-- tests/ReC.Tests/Client/ResultApiTests.cs | 8 ++++---- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/ReC.Tests/Client/CommonApiTests.cs b/tests/ReC.Tests/Client/CommonApiTests.cs index 794d42e..26e2624 100644 --- a/tests/ReC.Tests/Client/CommonApiTests.cs +++ b/tests/ReC.Tests/Client/CommonApiTests.cs @@ -51,7 +51,7 @@ public class CommonApiTests : RecClientTestBase } [Test] - public void UpdateAsync_with_body_payload_throws_or_completes() + public async Task UpdateAsync_with_body_payload_throws_or_completes() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -64,7 +64,7 @@ public class CommonApiTests : RecClientTestBase try { - client.Common.UpdateAsync(payload).GetAwaiter().GetResult(); + await client.Common.UpdateAsync(payload); Assert.Pass("Update completed."); } catch (ReCApiException ex) @@ -75,7 +75,7 @@ public class CommonApiTests : RecClientTestBase } [Test] - public void DeleteAsync_sends_payload_as_query_string() + public async Task DeleteAsync_sends_payload_as_query_string() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -90,7 +90,7 @@ public class CommonApiTests : RecClientTestBase try { - client.Common.DeleteAsync(payload).GetAwaiter().GetResult(); + await client.Common.DeleteAsync(payload); } catch (ReCApiException ex) { diff --git a/tests/ReC.Tests/Client/EndpointAuthApiTests.cs b/tests/ReC.Tests/Client/EndpointAuthApiTests.cs index 98bf082..f5a77bd 100644 --- a/tests/ReC.Tests/Client/EndpointAuthApiTests.cs +++ b/tests/ReC.Tests/Client/EndpointAuthApiTests.cs @@ -66,7 +66,7 @@ public class EndpointAuthApiTests : RecClientTestBase } [Test] - public void DeleteAsync_sends_payload_as_query_string() + public async Task DeleteAsync_sends_payload_as_query_string() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -80,7 +80,7 @@ public class EndpointAuthApiTests : RecClientTestBase try { - client.EndpointAuth.DeleteAsync(payload).GetAwaiter().GetResult(); + await client.EndpointAuth.DeleteAsync(payload); } catch (ReCApiException ex) { diff --git a/tests/ReC.Tests/Client/EndpointParamsApiTests.cs b/tests/ReC.Tests/Client/EndpointParamsApiTests.cs index 08ff6b8..3a0c55f 100644 --- a/tests/ReC.Tests/Client/EndpointParamsApiTests.cs +++ b/tests/ReC.Tests/Client/EndpointParamsApiTests.cs @@ -69,7 +69,7 @@ public class EndpointParamsApiTests : RecClientTestBase } [Test] - public void DeleteAsync_sends_payload_as_query_string() + public async Task DeleteAsync_sends_payload_as_query_string() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -83,7 +83,7 @@ public class EndpointParamsApiTests : RecClientTestBase try { - client.EndpointParams.DeleteAsync(payload).GetAwaiter().GetResult(); + await client.EndpointParams.DeleteAsync(payload); } catch (ReCApiException ex) { diff --git a/tests/ReC.Tests/Client/EndpointsApiTests.cs b/tests/ReC.Tests/Client/EndpointsApiTests.cs index 4f3c536..f549c3e 100644 --- a/tests/ReC.Tests/Client/EndpointsApiTests.cs +++ b/tests/ReC.Tests/Client/EndpointsApiTests.cs @@ -66,7 +66,7 @@ public class EndpointsApiTests : RecClientTestBase } [Test] - public void DeleteAsync_sends_payload_as_query_string() + public async Task DeleteAsync_sends_payload_as_query_string() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -80,7 +80,7 @@ public class EndpointsApiTests : RecClientTestBase try { - client.Endpoints.DeleteAsync(payload).GetAwaiter().GetResult(); + await client.Endpoints.DeleteAsync(payload); } catch (ReCApiException ex) { diff --git a/tests/ReC.Tests/Client/ProfileApiTests.cs b/tests/ReC.Tests/Client/ProfileApiTests.cs index 442795f..30a8e60 100644 --- a/tests/ReC.Tests/Client/ProfileApiTests.cs +++ b/tests/ReC.Tests/Client/ProfileApiTests.cs @@ -69,7 +69,7 @@ public class ProfileApiTests : RecClientTestBase } [Test] - public void UpdateAsync_with_unknown_id_throws_or_completes() + public async Task UpdateAsync_with_unknown_id_throws_or_completes() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -82,7 +82,7 @@ public class ProfileApiTests : RecClientTestBase try { - client.Profiles.UpdateAsync(long.MaxValue, payload).GetAwaiter().GetResult(); + await client.Profiles.UpdateAsync(long.MaxValue, payload); Assert.Pass("Update completed."); } catch (ReCApiException ex) @@ -93,7 +93,7 @@ public class ProfileApiTests : RecClientTestBase } [Test] - public void DeleteAsync_sends_payload_as_query_string() + public async Task DeleteAsync_sends_payload_as_query_string() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -107,7 +107,7 @@ public class ProfileApiTests : RecClientTestBase try { - client.Profiles.DeleteAsync(payload).GetAwaiter().GetResult(); + await client.Profiles.DeleteAsync(payload); } catch (ReCApiException ex) { diff --git a/tests/ReC.Tests/Client/RecActionApiTests.cs b/tests/ReC.Tests/Client/RecActionApiTests.cs index 4ab41e2..4bb05ce 100644 --- a/tests/ReC.Tests/Client/RecActionApiTests.cs +++ b/tests/ReC.Tests/Client/RecActionApiTests.cs @@ -158,7 +158,7 @@ public class RecActionApiTests : RecClientTestBase } [Test] - public void DeleteAsync_sends_payload_as_query_string_not_body() + public async Task DeleteAsync_sends_payload_as_query_string_not_body() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -172,7 +172,7 @@ public class RecActionApiTests : RecClientTestBase try { - client.RecActions.DeleteAsync(payload).GetAwaiter().GetResult(); + await client.RecActions.DeleteAsync(payload); } catch (ReCApiException ex) { diff --git a/tests/ReC.Tests/Client/ResultApiTests.cs b/tests/ReC.Tests/Client/ResultApiTests.cs index d58d9a6..a0ad676 100644 --- a/tests/ReC.Tests/Client/ResultApiTests.cs +++ b/tests/ReC.Tests/Client/ResultApiTests.cs @@ -57,7 +57,7 @@ public class ResultApiTests : RecClientTestBase } [Test] - public void CreateAsync_with_invalid_action_reference_throws_or_completes() + public async Task CreateAsync_with_invalid_action_reference_throws_or_completes() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -73,7 +73,7 @@ public class ResultApiTests : RecClientTestBase try { - client.Results.CreateAsync(payload).GetAwaiter().GetResult(); + await client.Results.CreateAsync(payload); Assert.Pass("Create completed."); } catch (ReCApiException ex) @@ -84,7 +84,7 @@ public class ResultApiTests : RecClientTestBase } [Test] - public void UpdateAsync_with_unknown_id_throws_or_completes() + public async Task UpdateAsync_with_unknown_id_throws_or_completes() { var (client, scope) = CreateScopedClient(); using var _ = scope; @@ -96,7 +96,7 @@ public class ResultApiTests : RecClientTestBase try { - client.Results.UpdateAsync(long.MaxValue, payload).GetAwaiter().GetResult(); + await client.Results.UpdateAsync(long.MaxValue, payload); Assert.Pass("Update completed."); } catch (ReCApiException ex)