From 0bc2a5573f08099195c8ab495cf8a226875c825b Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 7 Mar 2021 19:43:41 +0800 Subject: [PATCH] tests --- .../Editor/ClientSceneTests_ClearSpawners.cs | 8 ++--- .../Editor/ClientSceneTests_GetPrefab.cs | 10 +++--- .../Tests/Editor/ClientSceneTests_OnSpawn.cs | 12 +++---- ...ntSceneTests_PrepareToSpawnSceneObjects.cs | 10 +++--- .../ClientSceneTests_RegisterSpawnHandler.cs | 34 +++++++++---------- .../ClientSceneTests_UnregisterPrefab.cs | 10 +++--- ...ClientSceneTests_UnregisterSpawnHandler.cs | 6 ++-- .../Tests/Editor/NetworkBehaviourTests.cs | 2 +- Assets/Mirror/Tests/Editor/RemoteTestBase.cs | 2 +- 9 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_ClearSpawners.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_ClearSpawners.cs index 9c767edd3..3b20c177a 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_ClearSpawners.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_ClearSpawners.cs @@ -12,7 +12,7 @@ public void RemovesAllPrefabsFromDictionary() prefabs.Add(Guid.NewGuid(), null); prefabs.Add(Guid.NewGuid(), null); - ClientScene.ClearSpawners(); + NetworkClient.ClearSpawners(); Assert.IsEmpty(prefabs); } @@ -24,7 +24,7 @@ public void RemovesAllSpawnHandlersFromDictionary() spawnHandlers.Add(Guid.NewGuid(), null); spawnHandlers.Add(Guid.NewGuid(), null); - ClientScene.ClearSpawners(); + NetworkClient.ClearSpawners(); Assert.IsEmpty(spawnHandlers); } @@ -36,7 +36,7 @@ public void RemovesAllUnspawnHandlersFromDictionary() unspawnHandlers.Add(Guid.NewGuid(), null); unspawnHandlers.Add(Guid.NewGuid(), null); - ClientScene.ClearSpawners(); + NetworkClient.ClearSpawners(); Assert.IsEmpty(unspawnHandlers); } @@ -56,7 +56,7 @@ public void ClearsAllDictionary() unspawnHandlers.Add(Guid.NewGuid(), null); unspawnHandlers.Add(Guid.NewGuid(), null); - ClientScene.ClearSpawners(); + NetworkClient.ClearSpawners(); Assert.IsEmpty(prefabs); Assert.IsEmpty(spawnHandlers); diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_GetPrefab.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_GetPrefab.cs index 3434d99be..da1fb85ad 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_GetPrefab.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_GetPrefab.cs @@ -9,7 +9,7 @@ public class ClientSceneTests_GetPrefab : ClientSceneTestsBase [Test] public void ReturnsFalseForEmptyGuid() { - bool result = ClientScene.GetPrefab(new Guid(), out GameObject prefab); + bool result = NetworkClient.GetPrefab(new Guid(), out GameObject prefab); Assert.IsFalse(result); Assert.IsNull(prefab); @@ -19,7 +19,7 @@ public void ReturnsFalseForEmptyGuid() public void ReturnsFalseForPrefabNotFound() { Guid guid = Guid.NewGuid(); - bool result = ClientScene.GetPrefab(guid, out GameObject prefab); + bool result = NetworkClient.GetPrefab(guid, out GameObject prefab); Assert.IsFalse(result); Assert.IsNull(prefab); @@ -30,7 +30,7 @@ public void ReturnsFalseForPrefabIsNull() { Guid guid = Guid.NewGuid(); prefabs.Add(guid, null); - bool result = ClientScene.GetPrefab(guid, out GameObject prefab); + bool result = NetworkClient.GetPrefab(guid, out GameObject prefab); Assert.IsFalse(result); Assert.IsNull(prefab); @@ -40,7 +40,7 @@ public void ReturnsFalseForPrefabIsNull() public void ReturnsTrueWhenPrefabIsFound() { prefabs.Add(validPrefabGuid, validPrefab); - bool result = ClientScene.GetPrefab(validPrefabGuid, out GameObject prefab); + bool result = NetworkClient.GetPrefab(validPrefabGuid, out GameObject prefab); Assert.IsTrue(result); Assert.NotNull(prefab); @@ -50,7 +50,7 @@ public void ReturnsTrueWhenPrefabIsFound() public void HasOutPrefabWithCorrectGuid() { prefabs.Add(validPrefabGuid, validPrefab); - ClientScene.GetPrefab(validPrefabGuid, out GameObject prefab); + NetworkClient.GetPrefab(validPrefabGuid, out GameObject prefab); Assert.NotNull(prefab); diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs index 720d8d9a5..4c569574c 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs @@ -608,7 +608,7 @@ public void ApplyPayload_SendsDataToNetworkBehaviourDeserialize() [Test] public void ApplyPayload_LocalPlayerAddsIdentityToConnection() { - Debug.Assert(ClientScene.localPlayer == null, "LocalPlayer should be null before this test"); + Debug.Assert(NetworkClient.localPlayer == null, "LocalPlayer should be null before this test"); const uint netId = 1000; GameObject go = new GameObject(); @@ -631,19 +631,19 @@ public void ApplyPayload_LocalPlayerAddsIdentityToConnection() payload = default, }; - PropertyInfo readyConnProperty = typeof(ClientScene).GetProperty(nameof(ClientScene.readyConnection)); + PropertyInfo readyConnProperty = typeof(ClientScene).GetProperty(nameof(NetworkClient.readyConnection)); readyConnProperty.SetValue(null, new FakeNetworkConnection()); NetworkClient.ApplySpawnPayload(identity, msg); - Assert.That(ClientScene.localPlayer, Is.EqualTo(identity)); - Assert.That(ClientScene.readyConnection.identity, Is.EqualTo(identity)); + Assert.That(NetworkClient.localPlayer, Is.EqualTo(identity)); + Assert.That(NetworkClient.readyConnection.identity, Is.EqualTo(identity)); } [Test] public void ApplyPayload_LocalPlayerWarningWhenNoReadyConnection() { - Debug.Assert(ClientScene.localPlayer == null, "LocalPlayer should be null before this test"); + Debug.Assert(NetworkClient.localPlayer == null, "LocalPlayer should be null before this test"); const uint netId = 1000; GameObject go = new GameObject(); @@ -670,7 +670,7 @@ public void ApplyPayload_LocalPlayerWarningWhenNoReadyConnection() LogAssert.Expect(LogType.Warning, "No ready connection found for setting player controller during InternalAddPlayer"); NetworkClient.ApplySpawnPayload(identity, msg); - Assert.That(ClientScene.localPlayer, Is.EqualTo(identity)); + Assert.That(NetworkClient.localPlayer, Is.EqualTo(identity)); } [Flags] diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_PrepareToSpawnSceneObjects.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_PrepareToSpawnSceneObjects.cs index 4c87b229e..1815d6f85 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_PrepareToSpawnSceneObjects.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_PrepareToSpawnSceneObjects.cs @@ -31,7 +31,7 @@ public void AddsAllInactiveIdentitiesInSceneWithSceneIdToDictionary() obj3.gameObject.SetActive(false); obj4.gameObject.SetActive(false); - ClientScene.PrepareToSpawnSceneObjects(); + NetworkClient.PrepareToSpawnSceneObjects(); Assert.That(spawnableObjects, Has.Count.EqualTo(4)); @@ -54,7 +54,7 @@ public void DoesNotAddActiveObjectsToDictionary() inactive1.gameObject.SetActive(false); inactive2.gameObject.SetActive(false); - ClientScene.PrepareToSpawnSceneObjects(); + NetworkClient.PrepareToSpawnSceneObjects(); Assert.That(spawnableObjects, Has.Count.EqualTo(2)); @@ -78,7 +78,7 @@ public void DoesNotAddObjectsWithNoSceneId() hasId1.gameObject.SetActive(false); hasId2.gameObject.SetActive(false); - ClientScene.PrepareToSpawnSceneObjects(); + NetworkClient.PrepareToSpawnSceneObjects(); Assert.IsTrue(spawnableObjects.ContainsValue(hasId1)); Assert.IsTrue(spawnableObjects.ContainsValue(hasId2)); @@ -95,7 +95,7 @@ public void AddsIdentitiesToDictionaryUsingSceneId() obj1.gameObject.SetActive(false); obj2.gameObject.SetActive(false); - ClientScene.PrepareToSpawnSceneObjects(); + NetworkClient.PrepareToSpawnSceneObjects(); Assert.IsTrue(spawnableObjects.ContainsKey(20)); Assert.That(spawnableObjects[20], Is.EqualTo(obj1)); @@ -119,7 +119,7 @@ public void ClearsExistingItemsFromDictionary() NetworkIdentity obj2 = CreateSceneObject(63); obj2.gameObject.SetActive(false); - ClientScene.PrepareToSpawnSceneObjects(); + NetworkClient.PrepareToSpawnSceneObjects(); Assert.That(spawnableObjects, Has.Count.EqualTo(1)); Assert.IsFalse(spawnableObjects.ContainsValue(null)); diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_RegisterSpawnHandler.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_RegisterSpawnHandler.cs index 08fa786a4..9bddc0967 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_RegisterSpawnHandler.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_RegisterSpawnHandler.cs @@ -20,7 +20,7 @@ public void SpawnDelegate_AddsHandlerToSpawnHandlers() }); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); Assert.IsTrue(spawnHandlers.ContainsKey(guid)); @@ -46,7 +46,7 @@ public void SpawnDelegate_AddsHandlerToSpawnHandlersWithCorrectArguments() }); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); Assert.IsTrue(spawnHandlers.ContainsKey(guid)); @@ -63,7 +63,7 @@ public void SpawnDelegate_AddsHandlerToUnSpawnHandlers() SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); Assert.IsTrue(unspawnHandlers.ContainsKey(guid)); Assert.AreEqual(unspawnHandlers[guid], unspawnHandler); @@ -77,7 +77,7 @@ public void SpawnDelegate_ErrorWhenSpawnHandlerIsNull() UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } [Test] @@ -88,7 +88,7 @@ public void SpawnDelegate_ErrorWhenUnSpawnHandlerIsNull() UnSpawnDelegate unspawnHandler = null; LogAssert.Expect(LogType.Error, $"Can not Register null UnSpawnHandler for {guid}"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } [Test] @@ -99,7 +99,7 @@ public void SpawnDelegate_ErrorWhenAssetIdIsEmpty() UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); LogAssert.Expect(LogType.Error, "Can not Register SpawnHandler for empty Guid"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } [Test] @@ -109,13 +109,13 @@ public void SpawnDelegate_WarningWhenHandlerForGuidAlreadyExistsInHandlerDiction SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); SpawnDelegate spawnHandler2 = new SpawnDelegate((x, y) => new GameObject()); UnSpawnDelegate unspawnHandler2 = new UnSpawnDelegate(x => UnityEngine.Object.Destroy(x)); LogAssert.Expect(LogType.Warning, $"Replacing existing spawnHandlers for {guid}"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler2, unspawnHandler2); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler2, unspawnHandler2); } [Test] @@ -128,7 +128,7 @@ public void SpawnDelegate_ErrorWhenHandlerForGuidAlreadyExistsInPrefabDictionary UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); LogAssert.Expect(LogType.Error, $"assetId '{guid}' is already used by prefab '{validPrefab.name}'"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } @@ -139,7 +139,7 @@ public void SpawnHandlerDelegate_AddsHandlerToSpawnHandlers() SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); Assert.IsTrue(spawnHandlers.ContainsKey(guid)); Assert.AreEqual(spawnHandlers[guid], spawnHandler); @@ -152,7 +152,7 @@ public void SpawnHandlerDelegate_AddsHandlerToUnSpawnHandlers() SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); Assert.IsTrue(unspawnHandlers.ContainsKey(guid)); Assert.AreEqual(unspawnHandlers[guid], unspawnHandler); @@ -166,7 +166,7 @@ public void SpawnHandlerDelegate_ErrorWhenSpawnHandlerIsNull() UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } [Test] @@ -177,7 +177,7 @@ public void SpawnHandlerDelegate_ErrorWhenUnSpawnHandlerIsNull() UnSpawnDelegate unspawnHandler = null; LogAssert.Expect(LogType.Error, $"Can not Register null UnSpawnHandler for {guid}"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } [Test] @@ -188,7 +188,7 @@ public void SpawnHandlerDelegate_ErrorWhenAssetIdIsEmpty() UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); LogAssert.Expect(LogType.Error, "Can not Register SpawnHandler for empty Guid"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } [Test] @@ -198,13 +198,13 @@ public void SpawnHandlerDelegate_WarningWhenHandlerForGuidAlreadyExistsInHandler SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {}); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); SpawnHandlerDelegate spawnHandler2 = new SpawnHandlerDelegate(x => new GameObject()); UnSpawnDelegate unspawnHandler2 = new UnSpawnDelegate(x => UnityEngine.Object.Destroy(x)); LogAssert.Expect(LogType.Warning, $"Replacing existing spawnHandlers for {guid}"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler2, unspawnHandler2); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler2, unspawnHandler2); } [Test] @@ -217,7 +217,7 @@ public void SpawnHandlerDelegate_ErrorWhenHandlerForGuidAlreadyExistsInPrefabDic UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => UnityEngine.Object.Destroy(x)); LogAssert.Expect(LogType.Error, $"assetId '{guid}' is already used by prefab '{validPrefab.name}'"); - ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); + NetworkClient.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); } } diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterPrefab.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterPrefab.cs index 88a576d71..790282c30 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterPrefab.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterPrefab.cs @@ -11,7 +11,7 @@ public void RemovesPrefabFromDictionary() { prefabs.Add(validPrefabGuid, validPrefab); - ClientScene.UnregisterPrefab(validPrefab); + NetworkClient.UnregisterPrefab(validPrefab); Assert.IsFalse(prefabs.ContainsKey(validPrefabGuid)); } @@ -21,7 +21,7 @@ public void RemovesSpawnHandlerFromDictionary() { spawnHandlers.Add(validPrefabGuid, new SpawnHandlerDelegate(x => null)); - ClientScene.UnregisterPrefab(validPrefab); + NetworkClient.UnregisterPrefab(validPrefab); Assert.IsFalse(spawnHandlers.ContainsKey(validPrefabGuid)); } @@ -31,7 +31,7 @@ public void RemovesUnSpawnHandlerFromDictionary() { unspawnHandlers.Add(validPrefabGuid, new UnSpawnDelegate(x => {})); - ClientScene.UnregisterPrefab(validPrefab); + NetworkClient.UnregisterPrefab(validPrefab); Assert.IsFalse(unspawnHandlers.ContainsKey(validPrefabGuid)); } @@ -40,14 +40,14 @@ public void RemovesUnSpawnHandlerFromDictionary() public void ErrorWhenPrefabIsNull() { LogAssert.Expect(LogType.Error, "Could not unregister prefab because it was null"); - ClientScene.UnregisterPrefab(null); + NetworkClient.UnregisterPrefab(null); } [Test] public void ErrorWhenPrefabHasNoNetworkIdentity() { LogAssert.Expect(LogType.Error, $"Could not unregister '{invalidPrefab.name}' since it contains no NetworkIdentity component"); - ClientScene.UnregisterPrefab(invalidPrefab); + NetworkClient.UnregisterPrefab(invalidPrefab); } } diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterSpawnHandler.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterSpawnHandler.cs index a58ac5bb9..68353806c 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterSpawnHandler.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_UnregisterSpawnHandler.cs @@ -9,7 +9,7 @@ public void RemovesSpawnHandlersFromDictionary() { spawnHandlers.Add(validPrefabGuid, new SpawnHandlerDelegate(x => null)); - ClientScene.UnregisterSpawnHandler(validPrefabGuid); + NetworkClient.UnregisterSpawnHandler(validPrefabGuid); Assert.IsFalse(unspawnHandlers.ContainsKey(validPrefabGuid)); } @@ -19,7 +19,7 @@ public void RemovesUnSpawnHandlersFromDictionary() { unspawnHandlers.Add(validPrefabGuid, new UnSpawnDelegate(x => {})); - ClientScene.UnregisterSpawnHandler(validPrefabGuid); + NetworkClient.UnregisterSpawnHandler(validPrefabGuid); Assert.IsFalse(unspawnHandlers.ContainsKey(validPrefabGuid)); } @@ -29,7 +29,7 @@ public void DoesNotRemovePrefabDictionary() { prefabs.Add(validPrefabGuid, validPrefab); - ClientScene.UnregisterSpawnHandler(validPrefabGuid); + NetworkClient.UnregisterSpawnHandler(validPrefabGuid); // Should not be removed Assert.IsTrue(prefabs.ContainsKey(validPrefabGuid)); diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs index d8d3be3b5..7bdb2f722 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs @@ -367,7 +367,7 @@ public void SendCommandInternal() Assert.That(comp.called, Is.EqualTo(0)); // clientscene.readyconnection needs to be set for commands - ClientScene.Ready(connection.connectionToServer); + NetworkClient.Ready(connection.connectionToServer); // call command comp.CallSendCommandInternal(); diff --git a/Assets/Mirror/Tests/Editor/RemoteTestBase.cs b/Assets/Mirror/Tests/Editor/RemoteTestBase.cs index 57abbff9b..933bde29a 100644 --- a/Assets/Mirror/Tests/Editor/RemoteTestBase.cs +++ b/Assets/Mirror/Tests/Editor/RemoteTestBase.cs @@ -23,7 +23,7 @@ public void Setup() NetworkServer.localConnection.isAuthenticated = true; NetworkClient.connection.isAuthenticated = true; - ClientScene.Ready(NetworkClient.connection); + NetworkClient.Ready(NetworkClient.connection); } [TearDown]