Files
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

46 lines
1.4 KiB
C#

using Heimdall.Infrastructure.Services.Discovery;
using Microsoft.Extensions.Logging;
using NSubstitute;
using Shouldly;
namespace Heimdall.Infrastructure.Tests;
/// <summary>
/// Tests for PortScanService.
/// Real port scans require network access; these tests verify the
/// service structure, configuration, and error handling.
/// </summary>
public class PortScanServiceTests
{
private readonly ILogger<PortScanService> _logger = Substitute.For<ILogger<PortScanService>>();
[Fact]
public async Task ScanAsync_InvalidIp_ReturnsEmpty()
{
var service = new PortScanService(_logger);
// Use an IP in the TEST-NET range (RFC 5737) that should not respond
var result = await service.ScanAsync("192.0.2.1");
result.ShouldBeEmpty();
}
[Fact]
public async Task ScanAsync_NonExistentHost_ReturnsEmpty()
{
// 10.255.255.1 is in a reserved range, unlikely to respond
var service = new PortScanService(_logger);
var result = await service.ScanAsync("10.255.255.1");
result.ShouldBeEmpty();
}
[Fact]
public async Task ScanAsync_WithCancellation_Throws()
{
var service = new PortScanService(_logger);
using var cts = new CancellationTokenSource();
cts.Cancel();
await Should.ThrowAsync<OperationCanceledException>(async () =>
await service.ScanAsync("192.168.1.1", cts.Token));
}
}