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.
95 lines
2.5 KiB
C#
95 lines
2.5 KiB
C#
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="));
|
|
}
|
|
}
|
|
}
|