NetworkServerTest: SetLocalConnection split into two tests

This commit is contained in:
vis2k 2021-06-15 13:27:48 +08:00
parent 37c972658e
commit 64e8697031

View File

@ -192,7 +192,6 @@ public void ConnectDuplicateConnectionIds()
{ {
// listen // listen
NetworkServer.Listen(2); NetworkServer.Listen(2);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
// connect first // connect first
transport.OnServerConnected.Invoke(42); transport.OnServerConnected.Invoke(42);
@ -215,12 +214,22 @@ public void SetLocalConnection()
LocalConnectionToClient localConnection = new LocalConnectionToClient(); LocalConnectionToClient localConnection = new LocalConnectionToClient();
NetworkServer.SetLocalConnection(localConnection); NetworkServer.SetLocalConnection(localConnection);
Assert.That(NetworkServer.localConnection, Is.EqualTo(localConnection)); Assert.That(NetworkServer.localConnection, Is.EqualTo(localConnection));
}
[Test]
public void SetLocalConnection_PreventsOverwrite()
{
// listen
NetworkServer.Listen(1);
// set local connection
LocalConnectionToClient localConnection = new LocalConnectionToClient();
NetworkServer.SetLocalConnection(localConnection);
// try to overwrite it, which should not work // try to overwrite it, which should not work
// (it will show an error message, which is expected) // (it will show an error message, which is expected)
LogAssert.ignoreFailingMessages = true; LogAssert.ignoreFailingMessages = true;
LocalConnectionToClient overwrite = new LocalConnectionToClient(); NetworkServer.SetLocalConnection(new LocalConnectionToClient());
NetworkServer.SetLocalConnection(overwrite);
Assert.That(NetworkServer.localConnection, Is.EqualTo(localConnection)); Assert.That(NetworkServer.localConnection, Is.EqualTo(localConnection));
LogAssert.ignoreFailingMessages = false; LogAssert.ignoreFailingMessages = false;
} }