Tests simplified

This commit is contained in:
vis2k 2021-08-11 14:14:57 +08:00
parent 2fff5ef02b
commit 52a560ca6d

View File

@ -36,25 +36,19 @@ public IEnumerator DestroyPlayerForConnectionTest()
[UnityTest] [UnityTest]
public IEnumerator RemovePlayerForConnectionTest() public IEnumerator RemovePlayerForConnectionTest()
{ {
GameObject player = new GameObject("testPlayer", typeof(NetworkIdentity)); // create spawned player
NetworkConnectionToClient conn = new NetworkConnectionToClient(1); CreateNetworkedAndSpawnPlayer(out GameObject player, out _, NetworkServer.localConnection);
NetworkServer.AddPlayerForConnection(conn, player); // remove player for connection, wait 1 frame to unspawn
NetworkServer.RemovePlayerForConnection(NetworkServer.localConnection, false);
// allow 1 frame to spawn object
yield return null;
NetworkServer.RemovePlayerForConnection(conn, false);
// allow 1 frame to unspawn object
yield return null; yield return null;
Assert.That(player, Is.Not.Null, "Player should be not be destroyed"); Assert.That(player, Is.Not.Null, "Player should be not be destroyed");
Assert.That(conn.identity == null, "identity should be null"); Assert.That(NetworkServer.localConnection.identity == null, "identity should be null");
// respawn player // respawn player
NetworkServer.AddPlayerForConnection(conn, player); NetworkServer.AddPlayerForConnection(NetworkServer.localConnection, player);
Assert.That(conn.identity != null, "identity should not be null"); Assert.That(NetworkServer.localConnection.identity != null, "identity should not be null");
} }
[UnityTest] [UnityTest]