59 lines
1.6 KiB
C#
59 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);
|
||
|
|
}
|
||
|
|
}
|