test(agent): add service tests for CameraStream, ConfigReceiver, FrameAnalyzer, SystemMetrics, DTOs
This commit is contained in:
1 parent
06247d4f5c
commit
262adc07cf
10 files changed
+769
No files matched your search
@@ -0,0 +1,58 @@
|
||||
using Heimdall.Agent.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
|
||||
namespace Heimdall.Agent.Tests;
|
||||
|
||||
public class ConfigReceiverServiceTests
|
||||
{
|
||||
private static ConfigReceiverService CreateService(AgentState? state = null)
|
||||
{
|
||||
state ??= new AgentState { AgentId = Guid.Empty };
|
||||
var options = Options.Create(new AgentOptions
|
||||
{
|
||||
CentralUrl = "http://localhost:5000",
|
||||
SiteToken = "test"
|
||||
});
|
||||
var logger = Substitute.For<ILogger<ConfigReceiverService>>();
|
||||
var httpFactory = Substitute.For<IHttpClientFactory>();
|
||||
return new ConfigReceiverService(state, options, logger, httpFactory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WithDependencies_DoesNotThrow()
|
||||
{
|
||||
var service = CreateService();
|
||||
service.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartStop_WhenNotRegistered_StopsGracefully()
|
||||
{
|
||||
var state = new AgentState { AgentId = Guid.Empty };
|
||||
var service = CreateService(state);
|
||||
|
||||
await service.StartAsync(CancellationToken.None);
|
||||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3));
|
||||
await service.StopAsync(cts.Token);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartStop_WhenRegistered_StopsGracefully()
|
||||
{
|
||||
var state = new AgentState { AgentId = Guid.NewGuid(), ApiKey = "test-key" };
|
||||
var service = CreateService(state);
|
||||
|
||||
await service.StartAsync(CancellationToken.None);
|
||||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
await service.StopAsync(cts.Token);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StopAsync_WithoutStart_DoesNotThrow()
|
||||
{
|
||||
var service = CreateService();
|
||||
await service.StopAsync(CancellationToken.None);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user