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,75 @@
|
||||
using Heimdall.Agent.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
|
||||
namespace Heimdall.Agent.Tests;
|
||||
|
||||
public class FrameAnalyzerServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenModelNotFound_DoesNotThrow()
|
||||
{
|
||||
using var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
service.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnalyzeFrameAsync_WhenPassthrough_ReturnsNull()
|
||||
{
|
||||
using var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
var result = await service.AnalyzeFrameAsync([1, 2, 3]);
|
||||
result.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnalyzeFrame_WhenPassthrough_ReturnsNull()
|
||||
{
|
||||
using var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
var result = service.AnalyzeFrame([1, 2, 3]);
|
||||
result.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnalyzeFrameAsync_EmptyArray_ReturnsNull()
|
||||
{
|
||||
using var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
var result = await service.AnalyzeFrameAsync([]);
|
||||
result.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnalyzeFrameAsync_LargeBuffer_ReturnsNull()
|
||||
{
|
||||
using var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
var result = await service.AnalyzeFrameAsync(new byte[1024 * 1024]);
|
||||
result.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dispose_MultipleTimes_DoesNotThrow()
|
||||
{
|
||||
var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
service.Dispose();
|
||||
service.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnalyzeFrameAsync_AfterDispose_ReturnsNull()
|
||||
{
|
||||
var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
service.Dispose();
|
||||
var result = await service.AnalyzeFrameAsync([1, 2, 3]);
|
||||
result.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnalyzeFrameAsync_ConcurrentCalls_DoNotThrow()
|
||||
{
|
||||
using var service = new FrameAnalyzerService(Substitute.For<ILogger<FrameAnalyzerService>>());
|
||||
var tasks = Enumerable.Range(0, 10)
|
||||
.Select(_ => service.AnalyzeFrameAsync([1, 2, 3]))
|
||||
.ToArray();
|
||||
var results = await Task.WhenAll(tasks);
|
||||
results.ShouldAllBe(r => r == null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user