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

117 lines
3.1 KiB
C#

using EntKube.Identity.Domain;
using FluentAssertions;
namespace EntKube.Identity.Tests.Domain;
public class CustomerTests
{
[Fact]
public void Create_WithValidInputs_CreatesActiveCustomer()
{
// Arrange — A tenant admin onboards a new customer (team/organization)
// within their tenant. In the terraform reference, these are the "tenants"
// like capioDA, capioonline, volvat — each representing a team that gets
// its own namespaces, quotas, and app deployments per environment.
Guid tenantId = Guid.NewGuid();
// Act
Customer customer = Customer.Create(tenantId, "Capio Data Analytics", "capioda");
// Assert — The customer should be active and linked to its tenant.
customer.Id.Should().NotBe(Guid.Empty);
customer.TenantId.Should().Be(tenantId);
customer.Name.Should().Be("Capio Data Analytics");
customer.Slug.Should().Be("capioda");
customer.Status.Should().Be(CustomerStatus.Active);
customer.CreatedAt.Should().BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(5));
}
[Fact]
public void Create_NormalizesSlugToLowerCase()
{
// Arrange & Act — Slugs should be lowercase for consistent lookups.
Customer customer = Customer.Create(Guid.NewGuid(), "Volvat", "VOLVAT");
// Assert
customer.Slug.Should().Be("volvat");
}
[Fact]
public void Create_WithEmptyName_ThrowsArgumentException()
{
// Arrange & Act
Action act = () => Customer.Create(Guid.NewGuid(), "", "slug");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("name");
}
[Fact]
public void Create_WithEmptySlug_ThrowsArgumentException()
{
// Arrange & Act
Action act = () => Customer.Create(Guid.NewGuid(), "Some Customer", "");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("slug");
}
[Fact]
public void Create_WithEmptyTenantId_ThrowsArgumentException()
{
// Arrange & Act — Every customer must belong to a tenant.
Action act = () => Customer.Create(Guid.Empty, "Some Customer", "slug");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("tenantId");
}
[Fact]
public void Suspend_SetsStatusToSuspended()
{
// Arrange — An active customer that the admin wants to temporarily disable
// (e.g. during a billing dispute or compliance review).
Customer customer = Customer.Create(Guid.NewGuid(), "Volvat", "volvat");
// Act
customer.Suspend();
// Assert
customer.Status.Should().Be(CustomerStatus.Suspended);
}
[Fact]
public void Activate_SetsStatusToActive()
{
// Arrange — A previously suspended customer being re-enabled.
Customer customer = Customer.Create(Guid.NewGuid(), "Volvat", "volvat");
customer.Suspend();
// Act
customer.Activate();
// Assert
customer.Status.Should().Be(CustomerStatus.Active);
}
}