63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using Heimdall.Sites.Domain;
|
|
using Shouldly;
|
|
using Xunit;
|
|
|
|
namespace Heimdall.Migration.Domain.Tests;
|
|
|
|
public sealed class SiteTests
|
|
{
|
|
[Fact]
|
|
public void Create_ValidInput_PreservesIdentityAndNormalizesName()
|
|
{
|
|
Guid id = Guid.NewGuid();
|
|
Guid tenant = Guid.NewGuid();
|
|
Site site = Site.Create(id, tenant, " Entrée ", "UTC");
|
|
site.Id.ShouldBe(id);
|
|
site.TenantId.ShouldBe(tenant);
|
|
site.Name.ShouldBe("Entrée");
|
|
site.TimeZoneId.ShouldBe("UTC");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void Create_MissingIdentity_RejectsSite(bool missingSite)
|
|
{
|
|
Should.Throw<SitesDomainException>(() =>
|
|
Site.Create(missingSite ? Guid.Empty : Guid.NewGuid(), missingSite ? Guid.NewGuid() : Guid.Empty, "Site", "UTC"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void Create_EmptyName_RejectsSite(string name)
|
|
{
|
|
Should.Throw<SitesDomainException>(() => Site.Create(Guid.NewGuid(), Guid.NewGuid(), name, "UTC"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_InvalidTimeZone_PreservesPreviousState()
|
|
{
|
|
Site site = Site.Create(Guid.NewGuid(), Guid.NewGuid(), "Avant", "UTC");
|
|
Should.Throw<SitesDomainException>(() => site.Update("Après", "invalid/timezone"));
|
|
site.Name.ShouldBe("Avant");
|
|
site.TimeZoneId.ShouldBe("UTC");
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_LongName_PreservesPreviousState()
|
|
{
|
|
Site site = Site.Create(Guid.NewGuid(), Guid.NewGuid(), "Avant", "UTC");
|
|
Should.Throw<SitesDomainException>(() => site.Update(new string('x', 201), "UTC"));
|
|
site.Name.ShouldBe("Avant");
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_ValidInput_ChangesConfiguration()
|
|
{
|
|
Site site = Site.Create(Guid.NewGuid(), Guid.NewGuid(), "Avant", "UTC");
|
|
site.Update(" Après ", "UTC");
|
|
site.Name.ShouldBe("Après");
|
|
}
|
|
}
|