refactor(net): own complete live session lifecycle

This commit is contained in:
Erik 2026-07-21 12:20:55 +02:00
parent 23b43d1859
commit d9ccf8a6b9
5 changed files with 1618 additions and 91 deletions

View file

@ -0,0 +1,41 @@
using System.Net;
namespace AcDream.Core.Net.Tests;
public sealed class WorldSessionConstructionTests
{
[Fact]
public void InvalidEndpointIsRejectedBeforeTransportAllocation()
{
int allocationCount = 0;
IWorldSessionTransport Allocate(IPEndPoint _)
{
allocationCount++;
return new TestTransport();
}
Assert.Throws<ArgumentNullException>(
() => new WorldSession(null!, Allocate));
Assert.Throws<ArgumentOutOfRangeException>(
() => new WorldSession(
new IPEndPoint(IPAddress.Loopback, ushort.MaxValue),
Allocate));
Assert.Equal(0, allocationCount);
}
private sealed class TestTransport : IWorldSessionTransport
{
public void Send(ReadOnlySpan<byte> datagram) { }
public void Send(IPEndPoint remote, ReadOnlySpan<byte> datagram) { }
public byte[]? Receive(TimeSpan timeout, out IPEndPoint? from)
{
from = null;
return null;
}
public void Dispose() { }
}
}