too much for one commit

This commit is contained in:
Nils Blomgren
2026-05-13 14:01:32 +02:00
parent a96dd33039
commit 328d494530
394 changed files with 98104 additions and 78 deletions

View File

@@ -0,0 +1,115 @@
using EntKube.Identity.Domain;
using FluentAssertions;
namespace EntKube.Identity.Tests.Domain;
public class EnvironmentTests
{
[Fact]
public void Create_WithValidInputs_CreatesActiveEnvironment()
{
// Arrange — A tenant admin creates a new environment (e.g. "dev")
// for their organization. The environment starts in an Active state
// and is ready to have clusters assigned to it.
Guid tenantId = Guid.NewGuid();
// Act
TenantEnvironment env = TenantEnvironment.Create(tenantId, "Development", "dev");
// Assert — The environment should be active and linked to its tenant.
env.Id.Should().NotBe(Guid.Empty);
env.TenantId.Should().Be(tenantId);
env.Name.Should().Be("Development");
env.Slug.Should().Be("dev");
env.Status.Should().Be(EnvironmentStatus.Active);
env.CreatedAt.Should().BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(5));
}
[Fact]
public void Create_NormalizesSlugToLowerCase()
{
// Arrange & Act — Slugs should always be lowercase for consistent lookups.
TenantEnvironment env = TenantEnvironment.Create(Guid.NewGuid(), "Production", "PROD");
// Assert
env.Slug.Should().Be("prod");
}
[Fact]
public void Create_WithEmptyName_ThrowsArgumentException()
{
// Arrange & Act
Action act = () => TenantEnvironment.Create(Guid.NewGuid(), "", "dev");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("name");
}
[Fact]
public void Create_WithEmptySlug_ThrowsArgumentException()
{
// Arrange & Act
Action act = () => TenantEnvironment.Create(Guid.NewGuid(), "Development", "");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("slug");
}
[Fact]
public void Create_WithEmptyTenantId_ThrowsArgumentException()
{
// Arrange & Act — Every environment must belong to a tenant.
Action act = () => TenantEnvironment.Create(Guid.Empty, "Development", "dev");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("tenantId");
}
[Fact]
public void Deactivate_SetsStatusToInactive()
{
// Arrange — An active environment that the admin wants to disable
// (e.g. decommissioning a staging environment).
TenantEnvironment env = TenantEnvironment.Create(Guid.NewGuid(), "Staging", "staging");
// Act
env.Deactivate();
// Assert
env.Status.Should().Be(EnvironmentStatus.Inactive);
}
[Fact]
public void Activate_SetsStatusToActive()
{
// Arrange — A previously deactivated environment being re-enabled.
TenantEnvironment env = TenantEnvironment.Create(Guid.NewGuid(), "Staging", "staging");
env.Deactivate();
// Act
env.Activate();
// Assert
env.Status.Should().Be(EnvironmentStatus.Active);
}
}