74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
using ColaFlow.Modules.Identity.Domain.Aggregates.Tenants;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
|
|
namespace ColaFlow.Modules.Identity.Domain.Tests.ValueObjects;
|
|
|
|
public sealed class TenantSlugTests
|
|
{
|
|
[Theory]
|
|
[InlineData("acme")]
|
|
[InlineData("beta-corp")]
|
|
[InlineData("test-123")]
|
|
[InlineData("abc")]
|
|
public void Create_ShouldSucceed_ForValidSlug(string slug)
|
|
{
|
|
// Act
|
|
var tenantSlug = TenantSlug.Create(slug);
|
|
|
|
// Assert
|
|
tenantSlug.Value.Should().Be(slug);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
[InlineData("ab")] // Too short
|
|
[InlineData("www")] // Reserved
|
|
[InlineData("api")] // Reserved
|
|
[InlineData("admin")] // Reserved
|
|
[InlineData("acme_corp")] // Underscore
|
|
[InlineData("acme corp")] // Space
|
|
[InlineData("-acme")] // Starts with hyphen
|
|
[InlineData("acme-")] // Ends with hyphen
|
|
[InlineData("acme--corp")] // Double hyphen
|
|
public void Create_ShouldThrow_ForInvalidSlug(string slug)
|
|
{
|
|
// Act & Assert
|
|
var act = () => TenantSlug.Create(slug);
|
|
act.Should().Throw<ArgumentException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_ShouldConvertToLowerCase()
|
|
{
|
|
// Act
|
|
var tenantSlug = TenantSlug.Create("AcmeCorp");
|
|
|
|
// Assert
|
|
tenantSlug.Value.Should().Be("acmecorp");
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_ShouldTrimWhitespace()
|
|
{
|
|
// Act
|
|
var tenantSlug = TenantSlug.Create(" acme ");
|
|
|
|
// Assert
|
|
tenantSlug.Value.Should().Be("acme");
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_ShouldThrow_ForTooLongSlug()
|
|
{
|
|
// Arrange
|
|
var longSlug = new string('a', 51);
|
|
|
|
// Act & Assert
|
|
var act = () => TenantSlug.Create(longSlug);
|
|
act.Should().Throw<ArgumentException>()
|
|
.WithMessage("*cannot exceed 50 characters*");
|
|
}
|
|
}
|