From ff2a519e95ccee757f9f1e8977812796fd8a68d1 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 20 May 2026 13:13:39 +0200 Subject: [PATCH] Add EndpointParams API tests for ReC.Client library Added `EndpointParamsApiTests` to validate the `EndpointParams` API functionality. Introduced tests for dependency injection resolution, `CreateAsync`, `UpdateAsync`, and `DeleteAsync` methods to ensure proper behavior, including exception handling and HTTP method verification. Utilized scoped clients for resource management and introduced payload DTOs for API operations. --- .../Client/EndpointParamsApiTests.cs | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/ReC.Tests/Client/EndpointParamsApiTests.cs diff --git a/tests/ReC.Tests/Client/EndpointParamsApiTests.cs b/tests/ReC.Tests/Client/EndpointParamsApiTests.cs new file mode 100644 index 0000000..08ff6b8 --- /dev/null +++ b/tests/ReC.Tests/Client/EndpointParamsApiTests.cs @@ -0,0 +1,94 @@ +using ReC.Application.Common.Procedures.UpdateProcedure.Dto; +using ReC.Application.EndpointParams.Commands; +using ReC.Client; + +namespace ReC.Tests.Client; + +[TestFixture] +public class EndpointParamsApiTests : RecClientTestBase +{ + [Test] + public void ReCClient_endpoint_params_api_is_resolvable_through_dependency_injection() + { + var (client, scope) = CreateScopedClient(); + using var _ = scope; + + Assert.That(client, Is.Not.Null); + Assert.That(client.EndpointParams, Is.Not.Null); + } + + [Test] + public void CreateAsync_with_minimal_payload_throws_or_completes() + { + var (client, scope) = CreateScopedClient(); + using var _ = scope; + + var payload = new InsertEndpointParamsCommand + { + Active = true, + Description = "integration-test-params", + GroupId = 1, + Sequence = 1, + Key = "k", + Value = "v" + }; + + try + { + client.EndpointParams.CreateAsync(payload).GetAwaiter().GetResult(); + Assert.Pass("Create completed."); + } + catch (ReCApiException ex) + { + Assert.That(ex.Method, Is.EqualTo("POST")); + Assert.That(ex.RequestUri!.AbsolutePath, Does.EndWith("api/EndpointParams")); + } + } + + [Test] + public void UpdateAsync_with_unknown_id_throws_or_completes() + { + var (client, scope) = CreateScopedClient(); + using var _ = scope; + + var payload = new UpdateEndpointParamsDto + { + Active = false, + Description = "updated" + }; + + try + { + client.EndpointParams.UpdateAsync(long.MaxValue, payload).GetAwaiter().GetResult(); + Assert.Pass("Update completed."); + } + catch (ReCApiException ex) + { + Assert.That(ex.Method, Is.EqualTo("PUT")); + } + } + + [Test] + public void DeleteAsync_sends_payload_as_query_string() + { + var (client, scope) = CreateScopedClient(); + using var _ = scope; + + var payload = new DeleteEndpointParamsCommand + { + Start = long.MaxValue - 1, + End = long.MaxValue, + Force = false + }; + + try + { + client.EndpointParams.DeleteAsync(payload).GetAwaiter().GetResult(); + } + catch (ReCApiException ex) + { + Assert.That(ex.Method, Is.EqualTo("DELETE")); + Assert.That(ex.RequestUri!.Query, Does.Contain("Start=").And.Contains("End=").And.Contains("Force=")); + } + } +}