Files
ReC/tests/ReC.Tests/Client/CommonApiTests.cs
TekH b9dfc15ae2 Add CommonApiTests for ReCClient functionality
Introduced the `CommonApiTests` class to validate the behavior of the `ReCClient`'s `Common` API.

- Added `using` directives for namespaces related to procedures and commands to support the new tests.
- Verified dependency injection resolution for `ReCClient` and its `Common` API.
- Added tests for `CreateAsync`, `UpdateAsync`, and `DeleteAsync` methods to ensure proper handling of payloads and expected behavior:
  - `CreateAsync_with_invalid_action_payload_throws_or_completes`: Tests invalid payload handling for `CreateAsync`.
  - `UpdateAsync_with_body_payload_throws_or_completes`: Tests payload handling for `UpdateAsync`.
  - `DeleteAsync_sends_payload_as_query_string`: Verifies query string construction for `DeleteAsync`.
2026-05-20 13:13:04 +02:00

102 lines
2.8 KiB
C#

using ReC.Application.Common.Procedures;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.RecActions.Commands;
using ReC.Client;
namespace ReC.Tests.Client;
[TestFixture]
public class CommonApiTests : RecClientTestBase
{
[Test]
public void ReCClient_common_api_is_resolvable_through_dependency_injection()
{
var (client, scope) = CreateScopedClient();
using var _ = scope;
Assert.That(client, Is.Not.Null);
Assert.That(client.Common, Is.Not.Null);
}
[Test]
public void CreateAsync_with_invalid_action_payload_throws_or_completes()
{
var (client, scope) = CreateScopedClient();
using var _ = scope;
var payload = new InsertObjectProcedure
{
Entity = EntityType.Action,
Action = new InsertActionCommand
{
ProfileId = long.MaxValue,
EndpointId = long.MaxValue,
Active = true,
Sequence = 1
}
};
try
{
client.Common.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/Common"));
}
}
[Test]
public void UpdateAsync_with_body_payload_throws_or_completes()
{
var (client, scope) = CreateScopedClient();
using var _ = scope;
var payload = new UpdateObjectProcedure
{
Entity = EntityType.Action,
Id = long.MaxValue,
};
try
{
client.Common.UpdateAsync(payload).GetAwaiter().GetResult();
Assert.Pass("Update completed.");
}
catch (ReCApiException ex)
{
Assert.That(ex.Method, Is.EqualTo("PUT"));
Assert.That(ex.RequestUri!.AbsolutePath, Does.EndWith("api/Common"));
}
}
[Test]
public void DeleteAsync_sends_payload_as_query_string()
{
var (client, scope) = CreateScopedClient();
using var _ = scope;
var payload = new DeleteObjectProcedure
{
Entity = EntityType.Action,
Start = long.MaxValue - 1,
End = long.MaxValue,
Force = false
};
try
{
client.Common.DeleteAsync(payload).GetAwaiter().GetResult();
}
catch (ReCApiException ex)
{
Assert.That(ex.Method, Is.EqualTo("DELETE"));
Assert.That(ex.RequestUri!.Query, Does.Contain("Entity=").And.Contains("Start=").And.Contains("End=").And.Contains("Force="));
}
}
}