using System.Net; using FinalFactory.Rendezvous.Server.Transport; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; namespace FinalFactory.Rendezvous.Tests.Server; public sealed class UdpMediatorServiceTests { [Fact] public async Task ServiceBindsAnEphemeralUdpPortAndStopsCleanly() { using CancellationTokenSource timeout = new(TimeSpan.FromSeconds(5)); UdpMediatorOptions options = new() { ListenAddress = IPAddress.Loopback.ToString(), Port = 0, }; using UdpMediatorService service = new( Options.Create(options), NullLogger.Instance); await service.StartAsync(timeout.Token); IPEndPoint? boundEndpoint = service.LocalEndpoint; Assert.NotNull(boundEndpoint); Assert.Equal(IPAddress.Loopback, boundEndpoint.Address); Assert.InRange(boundEndpoint.Port, 1, 65_535); await service.StopAsync(timeout.Token); Assert.Null(service.LocalEndpoint); } }