Tests: guarantee OnStopLocalPlayer is called when using RemovePlayerForConnection. for #3106

This commit is contained in:
vis2k 2022-03-09 16:02:24 +08:00
parent 5846045122
commit 35ec47d213

View File

@ -1315,5 +1315,26 @@ public void SyncObjectChanges_DontGrowWithoutObservers()
// changes should be empty since we have no observers
Assert.That(comp.list.GetChangeCount(), Is.EqualTo(0));
}
[Test]
public void RemovePlayerForConnection_CallsOnStopLocalPlayer()
{
NetworkServer.Listen(1);
ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// spawn owned object
CreateNetworkedAndSpawnPlayer(
out _, out NetworkIdentity serverIdentity, out StopLocalPlayerCalledNetworkBehaviour serverComp,
out _, out NetworkIdentity clientIdentity, out StopLocalPlayerCalledNetworkBehaviour clientComp,
connectionToClient);
Assert.That(clientComp.called, Is.EqualTo(0));
// set it to not be owned by this connection anymore
NetworkServer.RemovePlayerForConnection(connectionToClient, false);
ProcessMessages();
// should call OnStopLocalPlayer on client
Assert.That(clientComp.called, Is.EqualTo(1));
}
}
}