Add tests for EndpointAuth API functionality
Added the `EndpointAuthApiTests` class to test the `EndpointAuth` API. Tests include: - Dependency injection resolution (`ReCClient_endpoint_auth_api_is_resolvable_through_dependency_injection`). - `CreateAsync` behavior with minimal payload. - `UpdateAsync` behavior with an unknown ID. - `DeleteAsync` behavior, ensuring payload is sent as a query string. Introduced necessary `using` directives and utilized the `CreateScopedClient` helper method for scoped client creation. Added exception handling to validate API method behavior and ensure proper assertions on exceptions.
This commit is contained in:
91
tests/ReC.Tests/Client/EndpointAuthApiTests.cs
Normal file
91
tests/ReC.Tests/Client/EndpointAuthApiTests.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
|
||||
using ReC.Application.EndpointAuth.Commands;
|
||||
using ReC.Client;
|
||||
|
||||
namespace ReC.Tests.Client;
|
||||
|
||||
[TestFixture]
|
||||
public class EndpointAuthApiTests : RecClientTestBase
|
||||
{
|
||||
[Test]
|
||||
public void ReCClient_endpoint_auth_api_is_resolvable_through_dependency_injection()
|
||||
{
|
||||
var (client, scope) = CreateScopedClient();
|
||||
using var _ = scope;
|
||||
|
||||
Assert.That(client, Is.Not.Null);
|
||||
Assert.That(client.EndpointAuth, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateAsync_with_minimal_payload_throws_or_completes()
|
||||
{
|
||||
var (client, scope) = CreateScopedClient();
|
||||
using var _ = scope;
|
||||
|
||||
var payload = new InsertEndpointAuthCommand
|
||||
{
|
||||
Active = true,
|
||||
Description = "integration-test-auth",
|
||||
TypeId = 1
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
client.EndpointAuth.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/EndpointAuth"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateAsync_with_unknown_id_throws_or_completes()
|
||||
{
|
||||
var (client, scope) = CreateScopedClient();
|
||||
using var _ = scope;
|
||||
|
||||
var payload = new UpdateEndpointAuthDto
|
||||
{
|
||||
Active = false,
|
||||
Description = "updated"
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
client.EndpointAuth.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 DeleteEndpointAuthCommand
|
||||
{
|
||||
Start = long.MaxValue - 1,
|
||||
End = long.MaxValue,
|
||||
Force = false
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
client.EndpointAuth.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="));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user