acdream/tests/AcDream.Core.Net.Tests/WorldSessionConstructionTests.cs

41 lines
1.1 KiB
C#

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() { }
}
}