Files

112 lines
2.9 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 siteId = Guid.NewGuid();
var agent = new Agent(siteId, "Agent-1", "host-1", "1.0.0");
agent.Id.ShouldNotBe(Guid.Empty);
agent.SiteId.ShouldBe(siteId);
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_apikey_and_set_online()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.Register("hash123", "pref");
agent.ApiKeyHash.ShouldBe("hash123");
agent.ApiKeyPrefix.ShouldBe("pref");
agent.Status.ShouldBe(AgentStatus.Online);
agent.LastHeartbeat.ShouldNotBeNull();
}
[Fact]
public void UpdateHeartbeat_should_set_online()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.Register("hash", "pref");
agent.UpdateHeartbeat();
agent.Status.ShouldBe(AgentStatus.Online);
agent.LastHeartbeat.ShouldNotBeNull();
}
[Fact]
public void UpdateHeartbeat_with_ip_should_update()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.Register("hash", "pref");
agent.UpdateHeartbeat("1.2.3.4");
agent.PublicIp.ShouldBe("1.2.3.4");
}
[Fact]
public void MarkOffline_should_set_status()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.Register("hash", "pref");
agent.MarkOffline();
agent.Status.ShouldBe(AgentStatus.Offline);
}
[Fact]
public void MarkError_should_set_status()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.MarkError();
agent.Status.ShouldBe(AgentStatus.Error);
}
[Fact]
public void UpdateCapabilities_should_update_all_fields()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.UpdateCapabilities(true, 8, 16384, GpuAcceleration.NvidiaCuda);
agent.HasGpu.ShouldBeTrue();
agent.CpuCores.ShouldBe(8);
agent.MemoryMb.ShouldBe(16384);
agent.GpuType.ShouldBe(GpuAcceleration.NvidiaCuda);
}
[Fact]
public void SoftDelete_should_set_deleted_flag()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.SoftDelete();
agent.IsDeleted.ShouldBeTrue();
agent.DeletedAt.ShouldNotBeNull();
}
[Fact]
public void Cameras_collection_should_be_empty_by_default()
{
var agent = new Agent(Guid.NewGuid(), "Agent-1", "host-1", "1.0.0");
agent.Cameras.ShouldBeEmpty();
}
}