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)
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using Heimdall.Domain.Entities;
|
|
using Heimdall.Domain.Enums;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Domain.Tests.Entities;
|
|
|
|
public class AgentTests
|
|
{
|
|
[Fact]
|
|
public void Create_agent_should_set_properties()
|
|
{
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
agent.Id.ShouldNotBe(Guid.Empty);
|
|
agent.Name.ShouldBe("Agent-1");
|
|
agent.Hostname.ShouldBe("host-1");
|
|
agent.Version.ShouldBe("1.0.0");
|
|
agent.Status.ShouldBe(AgentStatus.Offline);
|
|
}
|
|
|
|
[Fact]
|
|
public void Register_should_set_online_status()
|
|
{
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
|
|
agent.Register("apikeyhash123", "prefix12");
|
|
|
|
agent.Status.ShouldBe(AgentStatus.Online);
|
|
agent.ApiKeyHash.ShouldBe("apikeyhash123");
|
|
agent.ApiKeyPrefix.ShouldBe("prefix12");
|
|
agent.LastHeartbeat.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_heartbeat_should_update_timestamp()
|
|
{
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
agent.Register("hash", "prefix");
|
|
|
|
var before = agent.LastHeartbeat!.Value;
|
|
Thread.Sleep(10);
|
|
|
|
agent.UpdateHeartbeat("1.2.3.4");
|
|
|
|
(agent.LastHeartbeat!.Value > before).ShouldBeTrue();
|
|
agent.PublicIp.ShouldBe("1.2.3.4");
|
|
}
|
|
|
|
[Fact]
|
|
public void Mark_offline_should_set_status()
|
|
{
|
|
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
|
|
agent.Register("hash", "prefix");
|
|
|
|
agent.MarkOffline();
|
|
|
|
agent.Status.ShouldBe(AgentStatus.Offline);
|
|
}
|
|
}
|