76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
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);
|
|
}
|
|
}
|