using Heimdall.Infrastructure.Services.Discovery; using Microsoft.Extensions.Logging; using NSubstitute; using Shouldly; namespace Heimdall.Infrastructure.Tests; /// /// Tests for PortScanService. /// Real port scans require network access; these tests verify the /// service structure, configuration, and error handling. /// public class PortScanServiceTests { private readonly ILogger _logger = Substitute.For>(); [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(async () => await service.ScanAsync("192.168.1.1", cts.Token)); } }