Complete MVP implementation (Étape 1) covering: - Domain: primitives (Entity<TId>, ValueObject), 10 entities, 6 enums - EF Core: AppDbContext + Identity, 8 EntityTypeConfigurations, audit/soft-delete interceptors, initial migration - Application: service interfaces, DTOs, FluentValidation, ServiceResult pattern - Security: Identity + JWT + API Key multi-auth, role-based permissions, constant-time key validation - API: Auth/Sites/Agents controllers with explicit auth scheme policies - Workers: Hangfire PostgreSQL setup with schema isolation, HeartbeatMonitorJob - Agent: registration service + 30s heartbeat loop - Docker: multi-stage Dockerfiles for central + agent, docker-compose.yml - CI/CD: GitHub Actions pipeline with build+test and Docker build - Tests: 13 domain tests (Site, Agent, Camera entities) Architecture decisions per deliberation council: - API Key via AuthenticationHandler<T> (not middleware) - Explicit [Authorize(AuthenticationSchemes)] on all endpoints - Event/Recording/Person/Vehicle deferred from initial migration - Hangfire compatible with .NET 10 (v1.8.17)
79 lines
2.2 KiB
C#
79 lines
2.2 KiB
C#
using Heimdall.Domain.Entities;
|
|
using Heimdall.Domain.Primitives;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Domain.Tests.Entities;
|
|
|
|
public class SiteTests
|
|
{
|
|
[Fact]
|
|
public void Create_site_should_set_properties()
|
|
{
|
|
var site = new Site("Entrepôt A", "Paris", "Europe/Paris");
|
|
|
|
site.Id.ShouldNotBe(Guid.Empty);
|
|
site.Name.ShouldBe("Entrepôt A");
|
|
site.Address.ShouldBe("Paris");
|
|
site.Timezone.ShouldBe("Europe/Paris");
|
|
site.Enabled.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_site_should_default_timezone_to_UTC()
|
|
{
|
|
var site = new Site("Test Site");
|
|
|
|
site.Timezone.ShouldBe("UTC");
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_site_should_change_properties()
|
|
{
|
|
var site = new Site("Old Name", "Old Address", "UTC");
|
|
site.Update("New Name", "New Address", "Europe/London");
|
|
|
|
site.Name.ShouldBe("New Name");
|
|
site.Address.ShouldBe("New Address");
|
|
site.Timezone.ShouldBe("Europe/London");
|
|
}
|
|
|
|
[Fact]
|
|
public void Generate_registration_token_should_set_hash_and_expiry()
|
|
{
|
|
var site = new Site("Test Site");
|
|
var hash = "abc123hash";
|
|
var expiresAt = DateTime.UtcNow.AddDays(1);
|
|
|
|
site.GenerateRegistrationToken(hash, expiresAt);
|
|
|
|
site.RegistrationTokenHash.ShouldBe(hash);
|
|
site.TokenExpiresAt.ShouldBe(expiresAt);
|
|
}
|
|
|
|
[Fact]
|
|
public void Soft_delete_should_set_deleted_flag()
|
|
{
|
|
var site = new Site("Test Site");
|
|
|
|
site.SoftDelete();
|
|
|
|
site.IsDeleted.ShouldBeTrue();
|
|
site.DeletedAt.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Two_sites_with_same_id_should_be_equal()
|
|
{
|
|
// Use Entity<Guid> equality via reflection to set the same Id
|
|
var site1 = (Site)Activator.CreateInstance(typeof(Site), true)!;
|
|
var site2 = (Site)Activator.CreateInstance(typeof(Site), true)!;
|
|
|
|
var idField = typeof(Entity<Guid>)
|
|
.GetProperty("Id", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)!;
|
|
idField.SetValue(site1, Guid.Empty);
|
|
idField.SetValue(site2, Guid.Empty);
|
|
|
|
site1.Equals(site2).ShouldBeTrue();
|
|
}
|
|
}
|