Files
Entkube/tests/EntKube.Identity.Tests/Features/GetTenantsHandlerTests.cs
2026-05-13 14:01:32 +02:00

51 lines
1.3 KiB
C#

using EntKube.Identity.Domain;
using EntKube.Identity.Features.GetTenants;
using EntKube.Identity.Infrastructure;
using FluentAssertions;
namespace EntKube.Identity.Tests.Features;
public class GetTenantsHandlerTests
{
private readonly InMemoryTenantRepository repository;
public GetTenantsHandlerTests()
{
repository = new InMemoryTenantRepository();
}
[Fact]
public async Task GetAllAsync_WithTenants_ReturnsList()
{
// Arrange — Two tenants exist in the repository.
Tenant tenant1 = Tenant.Create("Acme Corp", "acme", Guid.NewGuid());
Tenant tenant2 = Tenant.Create("Globex", "globex", Guid.NewGuid());
await repository.AddAsync(tenant1);
await repository.AddAsync(tenant2);
// Act — Retrieve all tenants via the repository (endpoint uses it directly).
IReadOnlyList<Tenant> tenants = await repository.GetAllAsync();
// Assert
tenants.Should().HaveCount(2);
tenants.Should().Contain(t => t.Name == "Acme Corp");
tenants.Should().Contain(t => t.Name == "Globex");
}
[Fact]
public async Task GetAllAsync_Empty_ReturnsEmptyList()
{
// Act
IReadOnlyList<Tenant> tenants = await repository.GetAllAsync();
// Assert
tenants.Should().BeEmpty();
}
}