feat(migration): bootstrap Sites and Cameras domain for Heimdall MVP
This commit is contained in:
1 parent
525283c099
commit
ec59ee3208
17 files changed
+499
No files matched your search
@@ -0,0 +1,22 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{json,xml,props,csproj,slnx}]
|
||||
indent_size = 2
|
||||
|
||||
[*.cs]
|
||||
csharp_style_namespace_declarations = file_scoped:warning
|
||||
csharp_style_var_for_built_in_types = false:suggestion
|
||||
csharp_style_var_when_type_is_apparent = false:suggestion
|
||||
csharp_style_var_elsewhere = false:suggestion
|
||||
|
||||
[tests/**/*.cs]
|
||||
# AGENTS.md impose Methode_Condition_ResultatAttendu pour les tests.
|
||||
dotnet_diagnostic.CA1707.severity = none
|
||||
@@ -0,0 +1,9 @@
|
||||
# Changelog de la migration
|
||||
|
||||
## 2026-10-14 — incrément 01
|
||||
|
||||
Ajout du socle Domain Sites/Cameras du pilote, isolé de l'héritage : identités immuables, noms bornés, fuseau validé, flux RTSP/RTSPS sans credentials intégrés et désactivation non destructive. Validation atomique en mémoire ; référence site/secret sans dépendance inter-plugin. SDK 10.0.301, Central Package Management et analyseurs actifs.
|
||||
|
||||
Validation de `Heimdall.Migration.slnx` avec le SDK Windows existant : restore réussi, build strict réussi (0 avertissement, 0 erreur), 26 tests réussis. Format `--verify-no-changes` réussi. Domaine sans E/S : aucun test PostgreSQL, API/UI, inférence ou caméra réelle exécuté. H0/H1 et le MVP pilote ne sont pas terminés ; dépendances et restrictions décrites dans README.md.
|
||||
|
||||
Aucune modification du patrimoine, du transport historique, d'Android ou des configurations du produit legacy ; aucun déploiement ni publication.
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<AnalysisMode>Recommended</AnalysisMode>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageVersion Include="Shouldly" Version="4.3.0" />
|
||||
<PackageVersion Include="xunit.v3" Version="3.2.2" />
|
||||
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
<Solution>
|
||||
<Folder Name="/src/">
|
||||
<Project Path="src/Heimdall.Sites.Domain/Heimdall.Sites.Domain.csproj" />
|
||||
<Project Path="src/Heimdall.Cameras.Domain/Heimdall.Cameras.Domain.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/tests/">
|
||||
<Project Path="tests/Heimdall.Migration.Domain.Tests/Heimdall.Migration.Domain.Tests.csproj" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
@@ -0,0 +1,44 @@
|
||||
# Migration Heimdall — incrément 01
|
||||
|
||||
Premier socle métier du [MVP pilote](../../Specification/projects/heimdall/implementation/mvp-surveillance.md), préparatoire à H0/H1. Installation neuve isolée ; aucune bascule du patrimoine ni modification du Central historique.
|
||||
|
||||
## Code livré
|
||||
|
||||
- `Heimdall.Sites.Domain` : identité site/tenant immuable, nom et fuseau reconnus, mise à jour atomique en mémoire.
|
||||
- `Heimdall.Cameras.Domain` : référence site/tenant immuable, nom, URI RTSP/RTSPS et référence opaque de credential ; désactivation idempotente. Pas de référence de projet vers Sites.
|
||||
- Tests de comportement et d'architecture : Domain BCL seul, propriétés protégées, validation et conservation de l'état après erreur.
|
||||
|
||||
La solution `Heimdall.Migration.slnx` sépare la cible des dépendances héritées. Elle ne crée pas un autre Host ni un produit déployable. Ses propriétés et versions sont locales ; les configurations historiques restent intactes. Les couches Application/Infrastructure et les packages Business seront ajoutés avec leurs comportements réels, sans projets vides ni SDK simulé.
|
||||
|
||||
## Limites du premier contrat
|
||||
|
||||
Noms bornés à 200 caractères ; fuseau borné à 100 caractères et reconnu par `TimeZoneInfo` ; URI bornée à 2048 caractères, sans userinfo, query ni fragment pour éviter les credentials intégrés. Les caméras nécessitant des paramètres de query ne sont pas prises en charge par cet incrément ; leur représentation doit être définie avec Secrets et la politique réseau avant H1. Les URI peuvent rester sensibles : ne pas les journaliser.
|
||||
|
||||
Le Domain ne prouve ni l'existence du tenant/site/secret ni l'autorisation. Ces contrôles appartiendront au service applicatif, via les contrats plateforme et Sites. Aucun accès réseau ni contrôle SSRF effectué ici. Les identifiants sont fournis par l'appelant ; l'idempotence persistante reste à réaliser. Pas de version de concurrence EF fictive. L'archivage du site attend la vérification propriétaire des références actives ; aucune suppression locale ajoutée.
|
||||
|
||||
## Suite du chemin critique
|
||||
|
||||
1. YH0 : qualifier les packages de composition/runtime, provenance et compatibilité, et les samples indépendantes sur le Host commun. Les descriptors existants ne constituent pas encore une provenance de package validée.
|
||||
2. YH1 : évaluateur EF Core, repositories/Unit of Work, contextes propriétaires Npgsql et tests PostgreSQL réels.
|
||||
3. YH2 : tenant validé, ressources et permissions, identité humaine, auth locale et Secrets. Ces capacités ne sont pas disponibles dans le code Yggdrasil inspecté le 14 octobre 2026.
|
||||
4. H0/H1 : packages Business versionnés, Application Definition/profil, services Sites/Cameras directs et Specifications, puis CRUD autorisé et UI du Host commun.
|
||||
5. H2 et suivants : identité machine, affectations/epochs, capture/spool et événement durable, modèle CPU qualifié, alertes, PWA, conservation et restauration.
|
||||
|
||||
Aucun H0/H1 ni MVP complet annoncé terminé. Pas de retrait RabbitMQ/MassTransit ou Android : la parité, le drainage et le rollback restent des conditions de H7.
|
||||
|
||||
## Dépendances de test
|
||||
|
||||
Versions alignées sur les produits voisins, vérifiées sur NuGet : [xUnit v3 3.2.2](https://www.nuget.org/packages/xunit.v3/3.2.2) et [runner 3.1.4](https://www.nuget.org/packages/xunit.runner.visualstudio/3.1.4) (Apache-2.0), [Shouldly 4.3.0](https://www.nuget.org/packages/Shouldly/4.3.0) (BSD-3-Clause), [Test SDK 17.14.1](https://www.nuget.org/packages/Microsoft.NET.Test.Sdk/17.14.1) (MIT). Uniquement pour les tests, versions centralisées ; aucun package runtime ajouté au Domain.
|
||||
|
||||
## Validation
|
||||
|
||||
Depuis ce dossier avec SDK 10.0.301 :
|
||||
|
||||
```bash
|
||||
dotnet restore Heimdall.Migration.slnx
|
||||
dotnet build Heimdall.Migration.slnx --no-restore -warnaserror
|
||||
dotnet test Heimdall.Migration.slnx --no-build
|
||||
dotnet format Heimdall.Migration.slnx --verify-no-changes
|
||||
```
|
||||
|
||||
Sous WSL, le SDK Windows existant est invoqué via `/mnt/c/Program Files/dotnet/dotnet.exe` avec exécution autorisée hors sandbox ; aucune installation ni configuration globale. Résultats consignés dans [CHANGELOG.md](CHANGELOG.md). La solution historique n'est pas modifiée et ses suites ne sont pas une validation de ce socle. Aucune preuve PostgreSQL, HTTP/UI ou caméra réelle dans cet incrément sans persistance/transport.
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "10.0.301",
|
||||
"rollForward": "latestPatch",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
namespace Heimdall.Cameras.Domain;
|
||||
|
||||
/// <summary>Inventaire RTSP ; ne capture pas et ne possède ni site ni secret.</summary>
|
||||
public sealed class Camera
|
||||
{
|
||||
private Camera(Guid id, Guid tenantId, Guid siteId, string name, Uri streamUri, Guid? credentialReference)
|
||||
{
|
||||
Id = id;
|
||||
TenantId = tenantId;
|
||||
SiteId = siteId;
|
||||
Name = name;
|
||||
StreamUri = streamUri;
|
||||
CredentialReference = credentialReference;
|
||||
}
|
||||
|
||||
/// <summary>Identité stable de la caméra.</summary>
|
||||
public Guid Id { get; }
|
||||
|
||||
/// <summary>Tenant propriétaire immuable.</summary>
|
||||
public Guid TenantId { get; }
|
||||
|
||||
/// <summary>Référence au site ; son existence et ses droits sont vérifiés par le service.</summary>
|
||||
public Guid SiteId { get; }
|
||||
|
||||
/// <summary>Nom normalisé.</summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>Flux sans credentials intégrés ; ne doit pas être journalisé.</summary>
|
||||
public Uri StreamUri { get; private set; }
|
||||
|
||||
/// <summary>Référence opaque au secret externe, jamais sa valeur.</summary>
|
||||
public Guid? CredentialReference { get; private set; }
|
||||
|
||||
/// <summary>Indique si le flux peut être affecté.</summary>
|
||||
public bool IsEnabled { get; private set; } = true;
|
||||
|
||||
/// <summary>Déclare une caméra ; ne réalise aucun accès réseau.</summary>
|
||||
public static Camera Register(Guid id, Guid tenantId, Guid siteId, string name, string streamUri, Guid? credentialReference = null)
|
||||
{
|
||||
if (id == Guid.Empty || tenantId == Guid.Empty || siteId == Guid.Empty)
|
||||
{
|
||||
throw new CamerasDomainException("Les identifiants caméra, tenant et site sont obligatoires.");
|
||||
}
|
||||
|
||||
return new Camera(id, tenantId, siteId, ValidateName(name), ValidateStreamUri(streamUri), ValidateCredentialReference(credentialReference));
|
||||
}
|
||||
|
||||
/// <summary>Remplace la configuration uniquement après validation de tous les champs.</summary>
|
||||
public void Update(string name, string streamUri, Guid? credentialReference)
|
||||
{
|
||||
string validatedName = ValidateName(name);
|
||||
Uri validatedUri = ValidateStreamUri(streamUri);
|
||||
Guid? validatedReference = ValidateCredentialReference(credentialReference);
|
||||
Name = validatedName;
|
||||
StreamUri = validatedUri;
|
||||
CredentialReference = validatedReference;
|
||||
}
|
||||
|
||||
/// <summary>Désactive sans supprimer la configuration ni les références.</summary>
|
||||
public void Disable() => IsEnabled = false;
|
||||
|
||||
private static string ValidateName(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name) || name.Trim().Length > 200)
|
||||
{
|
||||
throw new CamerasDomainException("Le nom de la caméra doit contenir entre 1 et 200 caractères.");
|
||||
}
|
||||
|
||||
return name.Trim();
|
||||
}
|
||||
|
||||
private static Uri ValidateStreamUri(string streamUri)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(streamUri) || streamUri.Length > 2048 ||
|
||||
!Uri.TryCreate(streamUri, UriKind.Absolute, out Uri? uri) ||
|
||||
(uri.Scheme != "rtsp" && uri.Scheme != "rtsps") || string.IsNullOrEmpty(uri.Host) ||
|
||||
!string.IsNullOrEmpty(uri.UserInfo) || !string.IsNullOrEmpty(uri.Query) || !string.IsNullOrEmpty(uri.Fragment))
|
||||
{
|
||||
throw new CamerasDomainException("Le flux doit être une URI RTSP absolue sans credentials, query ni fragment.");
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
private static Guid? ValidateCredentialReference(Guid? credentialReference)
|
||||
{
|
||||
if (credentialReference == Guid.Empty)
|
||||
{
|
||||
throw new CamerasDomainException("La référence de secret ne peut pas être vide.");
|
||||
}
|
||||
|
||||
return credentialReference;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace Heimdall.Cameras.Domain;
|
||||
|
||||
/// <summary>Violation d'un invariant du propriétaire Cameras.</summary>
|
||||
public sealed class CamerasDomainException(string message) : Exception(message);
|
||||
@@ -0,0 +1 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" />
|
||||
@@ -0,0 +1 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" />
|
||||
@@ -0,0 +1,76 @@
|
||||
namespace Heimdall.Sites.Domain;
|
||||
|
||||
/// <summary>Site de surveillance ; le tenant est fourni par la plateforme.</summary>
|
||||
public sealed class Site
|
||||
{
|
||||
private Site(Guid id, Guid tenantId, string name, string timeZoneId)
|
||||
{
|
||||
Id = id;
|
||||
TenantId = tenantId;
|
||||
Name = name;
|
||||
TimeZoneId = timeZoneId;
|
||||
}
|
||||
|
||||
/// <summary>Identité stable du site.</summary>
|
||||
public Guid Id { get; }
|
||||
|
||||
/// <summary>Propriétaire tenant immuable, sans preuve d'autorisation implicite.</summary>
|
||||
public Guid TenantId { get; }
|
||||
|
||||
/// <summary>Nom normalisé du site.</summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>Fuseau reconnu sur l'environnement d'exécution.</summary>
|
||||
public string TimeZoneId { get; private set; }
|
||||
|
||||
/// <summary>Construit un site après validation complète.</summary>
|
||||
public static Site Create(Guid id, Guid tenantId, string name, string timeZoneId)
|
||||
{
|
||||
if (id == Guid.Empty || tenantId == Guid.Empty)
|
||||
{
|
||||
throw new SitesDomainException("Les identifiants du site et du tenant sont obligatoires.");
|
||||
}
|
||||
|
||||
return new Site(id, tenantId, ValidateName(name), ValidateTimeZone(timeZoneId));
|
||||
}
|
||||
|
||||
/// <summary>Valide tous les champs avant de modifier le site.</summary>
|
||||
public void Update(string name, string timeZoneId)
|
||||
{
|
||||
string validatedName = ValidateName(name);
|
||||
string validatedTimeZone = ValidateTimeZone(timeZoneId);
|
||||
Name = validatedName;
|
||||
TimeZoneId = validatedTimeZone;
|
||||
}
|
||||
|
||||
private static string ValidateName(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name) || name.Trim().Length > 200)
|
||||
{
|
||||
throw new SitesDomainException("Le nom du site doit contenir entre 1 et 200 caractères.");
|
||||
}
|
||||
|
||||
return name.Trim();
|
||||
}
|
||||
|
||||
private static string ValidateTimeZone(string timeZoneId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(timeZoneId) || timeZoneId.Length > 100)
|
||||
{
|
||||
throw new SitesDomainException("Le fuseau est obligatoire et limité à 100 caractères.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return TimeZoneInfo.FindSystemTimeZoneById(timeZoneId.Trim()).Id;
|
||||
}
|
||||
catch (TimeZoneNotFoundException)
|
||||
{
|
||||
throw new SitesDomainException("Le fuseau est inconnu.");
|
||||
}
|
||||
catch (InvalidTimeZoneException)
|
||||
{
|
||||
throw new SitesDomainException("Le fuseau est invalide.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace Heimdall.Sites.Domain;
|
||||
|
||||
/// <summary>Violation d'un invariant du propriétaire Sites.</summary>
|
||||
public sealed class SitesDomainException(string message) : Exception(message);
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Reflection;
|
||||
using Heimdall.Cameras.Domain;
|
||||
using Heimdall.Sites.Domain;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Heimdall.Migration.Domain.Tests;
|
||||
|
||||
public sealed class ArchitectureTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(typeof(Site))]
|
||||
[InlineData(typeof(Camera))]
|
||||
public void Domain_AssemblyReferences_UsesOnlyBcl(Type aggregate)
|
||||
{
|
||||
foreach (AssemblyName reference in aggregate.Assembly.GetReferencedAssemblies())
|
||||
{
|
||||
reference.Name.ShouldNotBeNull();
|
||||
(reference.Name == "System" || reference.Name.StartsWith("System.", StringComparison.Ordinal)).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(Site))]
|
||||
[InlineData(typeof(Camera))]
|
||||
public void Domain_PublicProperties_CannotBeAssignedExternally(Type aggregate)
|
||||
{
|
||||
foreach (PropertyInfo property in aggregate.GetProperties())
|
||||
{
|
||||
(property.SetMethod is null || !property.SetMethod.IsPublic).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using Heimdall.Cameras.Domain;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Heimdall.Migration.Domain.Tests;
|
||||
|
||||
public sealed class CameraTests
|
||||
{
|
||||
[Fact]
|
||||
public void Register_ValidInput_PreservesReferences()
|
||||
{
|
||||
Guid id = Guid.NewGuid();
|
||||
Guid tenant = Guid.NewGuid();
|
||||
Guid site = Guid.NewGuid();
|
||||
Guid secret = Guid.NewGuid();
|
||||
Camera camera = Camera.Register(id, tenant, site, " Entrée ", "rtsp://camera.example/stream", secret);
|
||||
camera.Id.ShouldBe(id);
|
||||
camera.TenantId.ShouldBe(tenant);
|
||||
camera.SiteId.ShouldBe(site);
|
||||
camera.Name.ShouldBe("Entrée");
|
||||
camera.CredentialReference.ShouldBe(secret);
|
||||
camera.IsEnabled.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("https://camera.example/stream")]
|
||||
[InlineData("rtsp://user:password@camera.example/stream")]
|
||||
[InlineData("rtsp://camera.example/stream?token=sensitive")]
|
||||
[InlineData("rtsp://camera.example/stream#sensitive")]
|
||||
[InlineData("relative/stream")]
|
||||
[InlineData("")]
|
||||
public void Register_InvalidStream_RejectsWithoutEchoingInput(string stream)
|
||||
{
|
||||
CamerasDomainException error = Should.Throw<CamerasDomainException>(() =>
|
||||
Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Camera", stream));
|
||||
error.Message.ShouldNotContain("sensitive");
|
||||
error.Message.ShouldNotContain("password");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void Register_MissingIdentity_RejectsCamera(int missing)
|
||||
{
|
||||
Should.Throw<CamerasDomainException>(() => Camera.Register(
|
||||
missing == 0 ? Guid.Empty : Guid.NewGuid(),
|
||||
missing == 1 ? Guid.Empty : Guid.NewGuid(),
|
||||
missing == 2 ? Guid.Empty : Guid.NewGuid(), "Camera", "rtsp://camera.example/stream"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_InvalidSecretReference_PreservesAllConfiguration()
|
||||
{
|
||||
Guid secret = Guid.NewGuid();
|
||||
Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Avant", "rtsp://camera.example/old", secret);
|
||||
Should.Throw<CamerasDomainException>(() => camera.Update("Après", "rtsps://camera.example/new", Guid.Empty));
|
||||
camera.Name.ShouldBe("Avant");
|
||||
camera.StreamUri.AbsoluteUri.ShouldBe("rtsp://camera.example/old");
|
||||
camera.CredentialReference.ShouldBe(secret);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_InvalidStream_PreservesPreviousState()
|
||||
{
|
||||
Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Avant", "rtsp://camera.example/old");
|
||||
Should.Throw<CamerasDomainException>(() => camera.Update("Après", "relative", null));
|
||||
camera.Name.ShouldBe("Avant");
|
||||
camera.StreamUri.AbsoluteUri.ShouldBe("rtsp://camera.example/old");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_ValidConfiguration_RemovesSecretReferenceWithoutEnabling()
|
||||
{
|
||||
Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Avant", "rtsp://camera.example/old", Guid.NewGuid());
|
||||
camera.Disable();
|
||||
camera.Update(" Après ", "rtsps://camera.example/new", null);
|
||||
camera.Name.ShouldBe("Après");
|
||||
camera.StreamUri.Scheme.ShouldBe("rtsps");
|
||||
camera.CredentialReference.ShouldBeNull();
|
||||
camera.IsEnabled.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Disable_RepeatedCall_PreservesConfiguration()
|
||||
{
|
||||
Camera camera = Camera.Register(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "Camera", "rtsp://camera.example/stream");
|
||||
camera.Disable();
|
||||
camera.Disable();
|
||||
camera.IsEnabled.ShouldBeFalse();
|
||||
camera.Name.ShouldBe("Camera");
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Shouldly" />
|
||||
<PackageReference Include="xunit.v3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<ProjectReference Include="../../src/Heimdall.Sites.Domain/Heimdall.Sites.Domain.csproj" />
|
||||
<ProjectReference Include="../../src/Heimdall.Cameras.Domain/Heimdall.Cameras.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,62 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user