Files
Heimdall/tests/Heimdall.Infrastructure.Tests/StreamTesterServiceTests.cs
T
Arnaud Dartois 2152fca3c6 feat(discovery): implement camera detection and dedup pipeline
Manual camera configuration does not scale beyond a few devices.
Automated discovery is needed to support deployments with 50+
cameras across heterogeneous protocols (ONVIF, mDNS, HTTP, ARP).

Phase 1 introduces 5 network probe services, a stream tester, an
orchestrating discovery service with IP+MAC deduplication, 11 REST
endpoints, a pre-verification endpoint, 57 tests, and DI registration.
2026-07-19 12:00:16 +00:00

77 lines
2.7 KiB
C#

using Heimdall.Infrastructure.Services.Discovery;
using Microsoft.Extensions.Logging;
using NSubstitute;
using Shouldly;
namespace Heimdall.Infrastructure.Tests;
/// <summary>
/// Unit tests for StreamTesterService.
/// Tests focus on session management and lifecycle.
/// Network-dependent tests (RTSP/HTTP connects) belong in integration tests.
/// </summary>
public class StreamTesterServiceTests
{
private readonly IHttpClientFactory _httpClientFactory = Substitute.For<IHttpClientFactory>();
private readonly ILogger<StreamTesterService> _logger = Substitute.For<ILogger<StreamTesterService>>();
[Fact]
public async Task CreateSession_ReturnsValidSession()
{
var service = new StreamTesterService(_httpClientFactory, _logger);
var request = new Application.DTOs.StreamTestRequest("test", ["rtsp://192.168.1.100:554/stream1"]);
var session = await service.CreateSessionAsync(request);
session.ShouldNotBeNull();
session.SessionId.ShouldNotBe(Guid.Empty);
session.Status.ShouldBe("running");
session.Total.ShouldBe(1);
}
[Fact]
public async Task CreateAndCancelSession_ReturnsCancelled()
{
var service = new StreamTesterService(_httpClientFactory, _logger);
var request = new Application.DTOs.StreamTestRequest("test", ["rtsp://192.168.1.100:554/stream1"]);
var session = await service.CreateSessionAsync(request);
await service.CancelSessionAsync(session.SessionId);
var cancelled = await service.GetSessionAsync(session.SessionId);
cancelled.ShouldNotBeNull();
cancelled.Status.ShouldBe("cancelled");
}
[Fact]
public async Task GetSession_NotFound_ReturnsNull()
{
var service = new StreamTesterService(_httpClientFactory, _logger);
var result = await service.GetSessionAsync(Guid.NewGuid());
result.ShouldBeNull();
}
[Fact]
public async Task CancelSession_UnknownId_DoesNotThrow()
{
var service = new StreamTesterService(_httpClientFactory, _logger);
await service.CancelSessionAsync(Guid.NewGuid());
}
[Fact]
public async Task CreateSession_MultipleUrls_CreatesCorrectCount()
{
var service = new StreamTesterService(_httpClientFactory, _logger);
var urls = new[]
{
"rtsp://192.168.1.100:554/stream1",
"rtsp://192.168.1.101:554/stream1",
"http://192.168.1.102:80/mjpeg",
};
var request = new Application.DTOs.StreamTestRequest("test", urls);
var session = await service.CreateSessionAsync(request);
session.Total.ShouldBe(3);
session.Status.ShouldBe("running");
}
}