Add Endpoints API integration tests
Added a new test class `EndpointsApiTests` to validate the `Endpoints` API functionality in the `ReC.Client`. Tests include: - Dependency injection resolution for the `Endpoints` API. - Behavior of `CreateAsync` with minimal payload. - Behavior of `UpdateAsync` with an unknown ID. - Validation of `DeleteAsync` sending payload as query string. Introduced necessary `using` directives and utilized the `CreateScopedClient` helper method for resource management.
This commit is contained in:
91
tests/ReC.Tests/Client/EndpointsApiTests.cs
Normal file
91
tests/ReC.Tests/Client/EndpointsApiTests.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
|
||||||
|
using ReC.Application.Endpoints.Commands;
|
||||||
|
using ReC.Client;
|
||||||
|
|
||||||
|
namespace ReC.Tests.Client;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class EndpointsApiTests : RecClientTestBase
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void ReCClient_endpoints_api_is_resolvable_through_dependency_injection()
|
||||||
|
{
|
||||||
|
var (client, scope) = CreateScopedClient();
|
||||||
|
using var _ = scope;
|
||||||
|
|
||||||
|
Assert.That(client, Is.Not.Null);
|
||||||
|
Assert.That(client.Endpoints, Is.Not.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CreateAsync_with_minimal_payload_throws_or_completes()
|
||||||
|
{
|
||||||
|
var (client, scope) = CreateScopedClient();
|
||||||
|
using var _ = scope;
|
||||||
|
|
||||||
|
var payload = new InsertEndpointCommand
|
||||||
|
{
|
||||||
|
Active = true,
|
||||||
|
Description = "integration-test-endpoint",
|
||||||
|
Uri = "https://localhost/test"
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.Endpoints.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/Endpoints"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UpdateAsync_with_unknown_id_throws_or_completes()
|
||||||
|
{
|
||||||
|
var (client, scope) = CreateScopedClient();
|
||||||
|
using var _ = scope;
|
||||||
|
|
||||||
|
var payload = new UpdateEndpointDto
|
||||||
|
{
|
||||||
|
Active = false,
|
||||||
|
Description = "updated"
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.Endpoints.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 DeleteEndpointCommand
|
||||||
|
{
|
||||||
|
Start = long.MaxValue - 1,
|
||||||
|
End = long.MaxValue,
|
||||||
|
Force = false
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.Endpoints.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