Moving Client scene tests to their own class per method (#1843)

* fixing comments

* adding extra lines

* moving tests to their own class per method
This commit is contained in:
James Frowen 2020-05-04 10:33:32 +01:00 committed by GitHub
parent ca6fd99242
commit c9db7e3754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,27 +8,27 @@
namespace Mirror.Tests namespace Mirror.Tests
{ {
[TestFixture] [TestFixture]
public class ClientSceneTests public abstract class BaseClientSceneTests
{ {
const string NewAssetIdIgnoreMessage = "Ignoring this test till we know how to fix it, see https://github.com/vis2k/Mirror/issues/1831"; protected const string NewAssetIdIgnoreMessage = "Ignoring this test till we know how to fix it, see https://github.com/vis2k/Mirror/issues/1831";
// use guid to find asset so that the path does not matter // use guid to find asset so that the path does not matter
const string ValidPrefabAssetGuid = "33169286da0313d45ab5bfccc6cf3775"; protected const string ValidPrefabAssetGuid = "33169286da0313d45ab5bfccc6cf3775";
const string PrefabWithChildrenAssetGuid = "a78e009e3f2dee44e8859516974ede43"; protected const string PrefabWithChildrenAssetGuid = "a78e009e3f2dee44e8859516974ede43";
const string InvalidPrefabAssetGuid = "78f0a3f755d35324e959f3ecdd993fb0"; protected const string InvalidPrefabAssetGuid = "78f0a3f755d35324e959f3ecdd993fb0";
// random guid, not used anywhere // random guid, not used anywhere
const string AnotherGuidString = "5794128cdfda04542985151f82990d05"; protected const string AnotherGuidString = "5794128cdfda04542985151f82990d05";
GameObject validPrefab; protected GameObject validPrefab;
NetworkIdentity validPrefabNetId; protected NetworkIdentity validPrefabNetId;
GameObject prefabWithChildren; protected GameObject prefabWithChildren;
GameObject invalidPrefab; protected GameObject invalidPrefab;
Guid validPrefabGuid; protected Guid validPrefabGuid;
Guid anotherGuid; protected Guid anotherGuid;
Dictionary<Guid, GameObject> prefabs => ClientScene.prefabs; protected Dictionary<Guid, GameObject> prefabs => ClientScene.prefabs;
Dictionary<Guid, SpawnHandlerDelegate> spawnHandlers => ClientScene.spawnHandlers; protected Dictionary<Guid, SpawnHandlerDelegate> spawnHandlers => ClientScene.spawnHandlers;
Dictionary<Guid, UnSpawnDelegate> unspawnHandlers => ClientScene.unspawnHandlers; protected Dictionary<Guid, UnSpawnDelegate> unspawnHandlers => ClientScene.unspawnHandlers;
static GameObject LoadPrefab(string guid) static GameObject LoadPrefab(string guid)
{ {
@ -61,10 +61,11 @@ public void OneTimeTearDown()
prefabWithChildren = null; prefabWithChildren = null;
invalidPrefab = null; invalidPrefab = null;
} }
}
public class ClientSceneTests_GetPrefab : BaseClientSceneTests
{
[Test] [Test]
public void GetPrefab_ReturnsFalseForEmptyGuid() public void ReturnsFalseForEmptyGuid()
{ {
bool result = ClientScene.GetPrefab(new Guid(), out GameObject prefab); bool result = ClientScene.GetPrefab(new Guid(), out GameObject prefab);
@ -73,7 +74,7 @@ public void GetPrefab_ReturnsFalseForEmptyGuid()
} }
[Test] [Test]
public void GetPrefab_ReturnsFalseForPrefabNotFound() public void ReturnsFalseForPrefabNotFound()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
bool result = ClientScene.GetPrefab(guid, out GameObject prefab); bool result = ClientScene.GetPrefab(guid, out GameObject prefab);
@ -83,7 +84,7 @@ public void GetPrefab_ReturnsFalseForPrefabNotFound()
} }
[Test] [Test]
public void GetPrefab_ReturnsFalseForPrefabIsNull() public void ReturnsFalseForPrefabIsNull()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
prefabs.Add(guid, null); prefabs.Add(guid, null);
@ -94,7 +95,7 @@ public void GetPrefab_ReturnsFalseForPrefabIsNull()
} }
[Test] [Test]
public void GetPrefab_ReturnsTrueWhenPrefabIsFound() public void ReturnsTrueWhenPrefabIsFound()
{ {
prefabs.Add(validPrefabGuid, validPrefab); prefabs.Add(validPrefabGuid, validPrefab);
bool result = ClientScene.GetPrefab(validPrefabGuid, out GameObject prefab); bool result = ClientScene.GetPrefab(validPrefabGuid, out GameObject prefab);
@ -104,7 +105,7 @@ public void GetPrefab_ReturnsTrueWhenPrefabIsFound()
} }
[Test] [Test]
public void GetPrefab_HasOutPrefabWithCorrectGuid() public void HasOutPrefabWithCorrectGuid()
{ {
prefabs.Add(validPrefabGuid, validPrefab); prefabs.Add(validPrefabGuid, validPrefab);
ClientScene.GetPrefab(validPrefabGuid, out GameObject prefab); ClientScene.GetPrefab(validPrefabGuid, out GameObject prefab);
@ -115,8 +116,9 @@ public void GetPrefab_HasOutPrefabWithCorrectGuid()
NetworkIdentity networkID = prefab.GetComponent<NetworkIdentity>(); NetworkIdentity networkID = prefab.GetComponent<NetworkIdentity>();
Assert.AreEqual(networkID.assetId, validPrefabGuid); Assert.AreEqual(networkID.assetId, validPrefabGuid);
} }
}
public class ClientSceneTests_RegisterPrefab : BaseClientSceneTests
{
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab, false)] [TestCase(RegisterPrefabOverload.Prefab, false)]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId, true)] [TestCase(RegisterPrefabOverload.Prefab_NewAssetId, true)]
@ -139,7 +141,7 @@ public void CheckOverloadWithAssetId(RegisterPrefabOverload overload, bool expec
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, true)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, true)]
public void CheckOverloadWithHandler(RegisterPrefabOverload overload, bool expected) public void CheckOverloadWithHandler(RegisterPrefabOverload overload, bool expected)
{ {
// test to make sure OverloadWithAssetId correctly works with flags // test to make sure OverloadWithHandler correctly works with flags
Assert.That(OverloadWithHandler(overload), Is.EqualTo(expected)); Assert.That(OverloadWithHandler(overload), Is.EqualTo(expected));
} }
@ -203,6 +205,7 @@ void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload)
break; break;
} }
} }
void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, Guid guid) void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, Guid guid)
{ {
SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null);
@ -231,6 +234,7 @@ void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, Guid
break; break;
} }
} }
void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, SpawnDelegate spawnHandler) void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, SpawnDelegate spawnHandler)
{ {
UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => { }); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => { });
@ -255,6 +259,7 @@ void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, Spaw
break; break;
} }
} }
void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, SpawnHandlerDelegate spawnHandlerDelegate) void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, SpawnHandlerDelegate spawnHandlerDelegate)
{ {
UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => { }); UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => { });
@ -272,13 +277,14 @@ void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, Spaw
case RegisterPrefabOverload.Prefab_NewAssetId: case RegisterPrefabOverload.Prefab_NewAssetId:
case RegisterPrefabOverload.Prefab_SpawnDelegate: case RegisterPrefabOverload.Prefab_SpawnDelegate:
case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId: case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId:
Debug.LogError("Overload did not have SpawnDelegate parameter"); Debug.LogError("Overload did not have SpawnHandlerDelegate parameter");
break; break;
default: default:
Debug.LogError("Overload not found"); Debug.LogError("Overload not found");
break; break;
} }
} }
void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, UnSpawnDelegate unspawnHandler) void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, UnSpawnDelegate unspawnHandler)
{ {
SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null);
@ -324,7 +330,7 @@ static void CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab)] [TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_Prefab_AddsPrefabToDictionary(RegisterPrefabOverload overload) public void Prefab_AddsPrefabToDictionary(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
@ -338,7 +344,7 @@ public void RegisterPrefab_Prefab_AddsPrefabToDictionary(RegisterPrefabOverload
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_NewGuid_ChangePrefabsAssetId(RegisterPrefabOverload overload) public void NewGuid_ChangePrefabsAssetId(RegisterPrefabOverload overload)
{ {
Guid guid = anotherGuid; Guid guid = anotherGuid;
CallRegisterPrefab(validPrefab, overload); CallRegisterPrefab(validPrefab, overload);
@ -358,7 +364,7 @@ public void RegisterPrefab_NewGuid_ChangePrefabsAssetId(RegisterPrefabOverload o
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void RegisterPrefab_ErrorForNullPrefab(RegisterPrefabOverload overload) public void ErrorForNullPrefab(RegisterPrefabOverload overload)
{ {
string msg = OverloadWithHandler(overload) string msg = OverloadWithHandler(overload)
? "Could not register handler for prefab because the prefab was null" ? "Could not register handler for prefab because the prefab was null"
@ -375,7 +381,7 @@ public void RegisterPrefab_ErrorForNullPrefab(RegisterPrefabOverload overload)
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void RegisterPrefab_ErrorForPrefabWithoutNetworkIdentity(RegisterPrefabOverload overload) public void ErrorForPrefabWithoutNetworkIdentity(RegisterPrefabOverload overload)
{ {
string msg = OverloadWithHandler(overload) string msg = OverloadWithHandler(overload)
? $"Could not register handler for '{invalidPrefab.name}' since it contains no NetworkIdentity component" ? $"Could not register handler for '{invalidPrefab.name}' since it contains no NetworkIdentity component"
@ -389,7 +395,7 @@ public void RegisterPrefab_ErrorForPrefabWithoutNetworkIdentity(RegisterPrefabOv
[TestCase(RegisterPrefabOverload.Prefab)] [TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void RegisterPrefab_ErrorForEmptyGuid(RegisterPrefabOverload overload) public void ErrorForEmptyGuid(RegisterPrefabOverload overload)
{ {
// setup // setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity); CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
@ -408,7 +414,7 @@ public void RegisterPrefab_ErrorForEmptyGuid(RegisterPrefabOverload overload)
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
public void RegisterPrefab_PrefabNewGuid_AddsRuntimeObjectToDictionary(RegisterPrefabOverload overload) public void PrefabNewGuid_AddsRuntimeObjectToDictionary(RegisterPrefabOverload overload)
{ {
// setup // setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity); CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
@ -428,7 +434,7 @@ public void RegisterPrefab_PrefabNewGuid_AddsRuntimeObjectToDictionary(RegisterP
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void RegisterPrefab_Handler_AddsSpawnHandlerToDictionaryForRuntimeObject(RegisterPrefabOverload overload) public void Handler_AddsSpawnHandlerToDictionaryForRuntimeObject(RegisterPrefabOverload overload)
{ {
// setup // setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity); CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
@ -445,7 +451,7 @@ public void RegisterPrefab_Handler_AddsSpawnHandlerToDictionaryForRuntimeObject(
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void RegisterPrefab_Handler_AddsUnSpawnHandlerToDictionaryForRuntimeObject(RegisterPrefabOverload overload) public void Handler_AddsUnSpawnHandlerToDictionaryForRuntimeObject(RegisterPrefabOverload overload)
{ {
// setup // setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity); CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
@ -463,7 +469,7 @@ public void RegisterPrefab_Handler_AddsUnSpawnHandlerToDictionaryForRuntimeObjec
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void RegisterPrefab_NewGuid_ErrorForEmptyGuid(RegisterPrefabOverload overload) public void NewGuid_ErrorForEmptyGuid(RegisterPrefabOverload overload)
{ {
string msg = OverloadWithHandler(overload) string msg = OverloadWithHandler(overload)
? $"Could not register handler for '{validPrefab.name}' with new assetId because the new assetId was empty" ? $"Could not register handler for '{validPrefab.name}' with new assetId because the new assetId was empty"
@ -479,7 +485,7 @@ public void RegisterPrefab_NewGuid_ErrorForEmptyGuid(RegisterPrefabOverload over
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void RegisterPrefab_ErrorIfPrefabHadSceneId(RegisterPrefabOverload overload) public void ErrorIfPrefabHadSceneId(RegisterPrefabOverload overload)
{ {
GameObject clone = GameObject.Instantiate(validPrefab); GameObject clone = GameObject.Instantiate(validPrefab);
NetworkIdentity netId = clone.GetComponent<NetworkIdentity>(); NetworkIdentity netId = clone.GetComponent<NetworkIdentity>();
@ -499,7 +505,7 @@ public void RegisterPrefab_ErrorIfPrefabHadSceneId(RegisterPrefabOverload overlo
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void RegisterPrefab_WarningForNetworkIdentityInChildren(RegisterPrefabOverload overload) public void WarningForNetworkIdentityInChildren(RegisterPrefabOverload overload)
{ {
LogAssert.Expect(LogType.Warning, $"Prefab '{prefabWithChildren.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object."); LogAssert.Expect(LogType.Warning, $"Prefab '{prefabWithChildren.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
CallRegisterPrefab(prefabWithChildren, overload); CallRegisterPrefab(prefabWithChildren, overload);
@ -509,7 +515,7 @@ public void RegisterPrefab_WarningForNetworkIdentityInChildren(RegisterPrefabOve
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab)] [TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_Prefab_WarningForAssetIdAlreadyExistingInPrefabsDictionary(RegisterPrefabOverload overload) public void Prefab_WarningForAssetIdAlreadyExistingInPrefabsDictionary(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
@ -524,7 +530,7 @@ public void RegisterPrefab_Prefab_WarningForAssetIdAlreadyExistingInPrefabsDicti
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_Handler_ErrorForAssetIdAlreadyExistingInPrefabsDictionary(RegisterPrefabOverload overload) public void Handler_ErrorForAssetIdAlreadyExistingInPrefabsDictionary(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
@ -541,7 +547,7 @@ public void RegisterPrefab_Handler_ErrorForAssetIdAlreadyExistingInPrefabsDictio
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_WarningForAssetIdAlreadyExistingInHandlersDictionary(RegisterPrefabOverload overload) public void WarningForAssetIdAlreadyExistingInHandlersDictionary(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
@ -560,7 +566,7 @@ public void RegisterPrefab_WarningForAssetIdAlreadyExistingInHandlersDictionary(
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_SpawnDelegate_AddsHandlerToSpawnHandlers(RegisterPrefabOverload overload) public void SpawnDelegate_AddsHandlerToSpawnHandlers(RegisterPrefabOverload overload)
{ {
int handlerCalled = 0; int handlerCalled = 0;
@ -585,7 +591,7 @@ public void RegisterPrefab_SpawnDelegate_AddsHandlerToSpawnHandlers(RegisterPref
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_SpawnDelegate_AddsHandlerToSpawnHandlersWithCorrectArguments(RegisterPrefabOverload overload) public void SpawnDelegate_AddsHandlerToSpawnHandlersWithCorrectArguments(RegisterPrefabOverload overload)
{ {
int handlerCalled = 0; int handlerCalled = 0;
Vector3 somePosition = new Vector3(10, 20, 3); Vector3 somePosition = new Vector3(10, 20, 3);
@ -612,7 +618,7 @@ public void RegisterPrefab_SpawnDelegate_AddsHandlerToSpawnHandlersWithCorrectAr
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
public void RegisterPrefab_SpawnDelegate_ErrorWhenSpawnHandlerIsNull(RegisterPrefabOverload overload) public void SpawnDelegate_ErrorWhenSpawnHandlerIsNull(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}"); LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}");
@ -622,7 +628,7 @@ public void RegisterPrefab_SpawnDelegate_ErrorWhenSpawnHandlerIsNull(RegisterPre
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_SpawnHandleDelegate_AddsHandlerToSpawnHandlers(RegisterPrefabOverload overload) public void SpawnHandleDelegate_AddsHandlerToSpawnHandlers(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
@ -637,7 +643,7 @@ public void RegisterPrefab_SpawnHandleDelegate_AddsHandlerToSpawnHandlers(Regist
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_SpawnHandleDelegate_ErrorWhenSpawnHandlerIsNull(RegisterPrefabOverload overload) public void SpawnHandleDelegate_ErrorWhenSpawnHandlerIsNull(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}"); LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}");
@ -649,16 +655,18 @@ public void RegisterPrefab_SpawnHandleDelegate_ErrorWhenSpawnHandlerIsNull(Regis
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, IgnoreReason = NewAssetIdIgnoreMessage)]
public void RegisterPrefab_Handler_ErrorWhenUnSpawnHandlerIsNull(RegisterPrefabOverload overload) public void Handler_ErrorWhenUnSpawnHandlerIsNull(RegisterPrefabOverload overload)
{ {
Guid guid = GuidForOverload(overload); Guid guid = GuidForOverload(overload);
LogAssert.Expect(LogType.Error, $"Can not Register null UnSpawnHandler for {guid}"); LogAssert.Expect(LogType.Error, $"Can not Register null UnSpawnHandler for {guid}");
CallRegisterPrefab(validPrefab, overload, unspawnHandler: null); CallRegisterPrefab(validPrefab, overload, unspawnHandler: null);
} }
}
public class ClientSceneTests_UnregisterPrefab : BaseClientSceneTests
{
[Test] [Test]
public void UnregisterPrefab_RemovesPrefabFromDictionary() public void RemovesPrefabFromDictionary()
{ {
prefabs.Add(validPrefabGuid, validPrefab); prefabs.Add(validPrefabGuid, validPrefab);
@ -668,7 +676,7 @@ public void UnregisterPrefab_RemovesPrefabFromDictionary()
} }
[Test] [Test]
public void UnregisterPrefab_RemovesSpawnHandlerFromDictionary() public void RemovesSpawnHandlerFromDictionary()
{ {
spawnHandlers.Add(validPrefabGuid, new SpawnHandlerDelegate(x => null)); spawnHandlers.Add(validPrefabGuid, new SpawnHandlerDelegate(x => null));
@ -678,7 +686,7 @@ public void UnregisterPrefab_RemovesSpawnHandlerFromDictionary()
} }
[Test] [Test]
public void UnregisterPrefab_RemovesUnSpawnHandlerFromDictionary() public void RemovesUnSpawnHandlerFromDictionary()
{ {
unspawnHandlers.Add(validPrefabGuid, new UnSpawnDelegate(x => { })); unspawnHandlers.Add(validPrefabGuid, new UnSpawnDelegate(x => { }));
@ -688,22 +696,24 @@ public void UnregisterPrefab_RemovesUnSpawnHandlerFromDictionary()
} }
[Test] [Test]
public void UnregisterPrefab_ErrorWhenPrefabIsNull() public void ErrorWhenPrefabIsNull()
{ {
LogAssert.Expect(LogType.Error, "Could not unregister prefab because it was null"); LogAssert.Expect(LogType.Error, "Could not unregister prefab because it was null");
ClientScene.UnregisterPrefab(null); ClientScene.UnregisterPrefab(null);
} }
[Test] [Test]
public void UnregisterPrefab_ErrorWhenPrefabHasNoNetworkIdentity() public void ErrorWhenPrefabHasNoNetworkIdentity()
{ {
LogAssert.Expect(LogType.Error, $"Could not unregister '{invalidPrefab.name}' since it contains no NetworkIdentity component"); LogAssert.Expect(LogType.Error, $"Could not unregister '{invalidPrefab.name}' since it contains no NetworkIdentity component");
ClientScene.UnregisterPrefab(invalidPrefab); ClientScene.UnregisterPrefab(invalidPrefab);
} }
}
public class ClientSceneTests_RegisterSpawnHandler : BaseClientSceneTests
{
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_AddsHandlerToSpawnHandlers() public void SpawnDelegate_AddsHandlerToSpawnHandlers()
{ {
int handlerCalled = 0; int handlerCalled = 0;
@ -726,7 +736,7 @@ public void RegisterSpawnHandler_SpawnDelegate_AddsHandlerToSpawnHandlers()
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_AddsHandlerToSpawnHandlersWithCorrectArguments() public void SpawnDelegate_AddsHandlerToSpawnHandlersWithCorrectArguments()
{ {
int handlerCalled = 0; int handlerCalled = 0;
Vector3 somePosition = new Vector3(10, 20, 3); Vector3 somePosition = new Vector3(10, 20, 3);
@ -752,7 +762,7 @@ public void RegisterSpawnHandler_SpawnDelegate_AddsHandlerToSpawnHandlersWithCor
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_AddsHandlerToUnSpawnHandlers() public void SpawnDelegate_AddsHandlerToUnSpawnHandlers()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null);
@ -765,7 +775,7 @@ public void RegisterSpawnHandler_SpawnDelegate_AddsHandlerToUnSpawnHandlers()
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenSpawnHandlerIsNull() public void SpawnDelegate_ErrorWhenSpawnHandlerIsNull()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnDelegate spawnHandler = null; SpawnDelegate spawnHandler = null;
@ -776,7 +786,7 @@ public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenSpawnHandlerIsNull()
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenUnSpawnHandlerIsNull() public void SpawnDelegate_ErrorWhenUnSpawnHandlerIsNull()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null);
@ -787,7 +797,7 @@ public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenUnSpawnHandlerIsNull()
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenAssetIdIsEmpty() public void SpawnDelegate_ErrorWhenAssetIdIsEmpty()
{ {
Guid guid = new Guid(); Guid guid = new Guid();
SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null);
@ -798,7 +808,7 @@ public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenAssetIdIsEmpty()
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_WarningWhenHandlerForGuidAlreadyExistsInHandlerDictionary() public void SpawnDelegate_WarningWhenHandlerForGuidAlreadyExistsInHandlerDictionary()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null); SpawnDelegate spawnHandler = new SpawnDelegate((x, y) => null);
@ -814,7 +824,7 @@ public void RegisterSpawnHandler_SpawnDelegate_WarningWhenHandlerForGuidAlreadyE
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenHandlerForGuidAlreadyExistsInPrefabDictionary() public void SpawnDelegate_ErrorWhenHandlerForGuidAlreadyExistsInPrefabDictionary()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
prefabs.Add(guid, validPrefab); prefabs.Add(guid, validPrefab);
@ -828,7 +838,7 @@ public void RegisterSpawnHandler_SpawnDelegate_ErrorWhenHandlerForGuidAlreadyExi
[Test] [Test]
public void RegisterSpawnHandler_SpawnHandlerDelegate_AddsHandlerToSpawnHandlers() public void SpawnHandlerDelegate_AddsHandlerToSpawnHandlers()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null);
@ -841,7 +851,7 @@ public void RegisterSpawnHandler_SpawnHandlerDelegate_AddsHandlerToSpawnHandlers
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnHandlerDelegate_AddsHandlerToUnSpawnHandlers() public void SpawnHandlerDelegate_AddsHandlerToUnSpawnHandlers()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null);
@ -854,7 +864,7 @@ public void RegisterSpawnHandler_SpawnHandlerDelegate_AddsHandlerToUnSpawnHandle
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenSpawnHandlerIsNull() public void SpawnHandlerDelegate_ErrorWhenSpawnHandlerIsNull()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnHandlerDelegate spawnHandler = null; SpawnHandlerDelegate spawnHandler = null;
@ -865,7 +875,7 @@ public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenSpawnHandlerIsNul
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenUnSpawnHandlerIsNull() public void SpawnHandlerDelegate_ErrorWhenUnSpawnHandlerIsNull()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null);
@ -876,7 +886,7 @@ public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenUnSpawnHandlerIsN
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenAssetIdIsEmpty() public void SpawnHandlerDelegate_ErrorWhenAssetIdIsEmpty()
{ {
Guid guid = new Guid(); Guid guid = new Guid();
SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null);
@ -887,7 +897,7 @@ public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenAssetIdIsEmpty()
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnHandlerDelegate_WarningWhenHandlerForGuidAlreadyExistsInHandlerDictionary() public void SpawnHandlerDelegate_WarningWhenHandlerForGuidAlreadyExistsInHandlerDictionary()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null); SpawnHandlerDelegate spawnHandler = new SpawnHandlerDelegate(x => null);
@ -903,7 +913,7 @@ public void RegisterSpawnHandler_SpawnHandlerDelegate_WarningWhenHandlerForGuidA
} }
[Test] [Test]
public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenHandlerForGuidAlreadyExistsInPrefabDictionary() public void SpawnHandlerDelegate_ErrorWhenHandlerForGuidAlreadyExistsInPrefabDictionary()
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();
prefabs.Add(guid, validPrefab); prefabs.Add(guid, validPrefab);
@ -915,9 +925,11 @@ public void RegisterSpawnHandler_SpawnHandlerDelegate_ErrorWhenHandlerForGuidAlr
ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler); ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler);
} }
}
public class ClientSceneTests_UnregisterSpawnHandler : BaseClientSceneTests
{
[Test] [Test]
public void UnregisterSpawnHandler_RemovesSpawnHandlersFromDictionary() public void RemovesSpawnHandlersFromDictionary()
{ {
spawnHandlers.Add(validPrefabGuid, new SpawnHandlerDelegate(x => null)); spawnHandlers.Add(validPrefabGuid, new SpawnHandlerDelegate(x => null));
@ -927,7 +939,7 @@ public void UnregisterSpawnHandler_RemovesSpawnHandlersFromDictionary()
} }
[Test] [Test]
public void UnregisterSpawnHandler_RemovesUnSpawnHandlersFromDictionary() public void RemovesUnSpawnHandlersFromDictionary()
{ {
unspawnHandlers.Add(validPrefabGuid, new UnSpawnDelegate(x => { })); unspawnHandlers.Add(validPrefabGuid, new UnSpawnDelegate(x => { }));
@ -937,7 +949,7 @@ public void UnregisterSpawnHandler_RemovesUnSpawnHandlersFromDictionary()
} }
[Test] [Test]
public void UnregisterSpawnHandler_DoesNotRemovePrefabDictionary() public void DoesNotRemovePrefabDictionary()
{ {
prefabs.Add(validPrefabGuid, validPrefab); prefabs.Add(validPrefabGuid, validPrefab);
@ -947,9 +959,11 @@ public void UnregisterSpawnHandler_DoesNotRemovePrefabDictionary()
Assert.IsTrue(prefabs.ContainsKey(validPrefabGuid)); Assert.IsTrue(prefabs.ContainsKey(validPrefabGuid));
} }
}
public class ClientSceneTests_ClearSpawners : BaseClientSceneTests
{
[Test] [Test]
public void ClearSpawners_RemovesAllPrefabsFromDictionary() public void RemovesAllPrefabsFromDictionary()
{ {
prefabs.Add(Guid.NewGuid(), null); prefabs.Add(Guid.NewGuid(), null);
prefabs.Add(Guid.NewGuid(), null); prefabs.Add(Guid.NewGuid(), null);
@ -961,7 +975,7 @@ public void ClearSpawners_RemovesAllPrefabsFromDictionary()
} }
[Test] [Test]
public void ClearSpawners_RemovesAllSpawnHandlersFromDictionary() public void RemovesAllSpawnHandlersFromDictionary()
{ {
spawnHandlers.Add(Guid.NewGuid(), null); spawnHandlers.Add(Guid.NewGuid(), null);
spawnHandlers.Add(Guid.NewGuid(), null); spawnHandlers.Add(Guid.NewGuid(), null);
@ -973,7 +987,7 @@ public void ClearSpawners_RemovesAllSpawnHandlersFromDictionary()
} }
[Test] [Test]
public void ClearSpawners_RemovesAllUnspawnHandlersFromDictionary() public void RemovesAllUnspawnHandlersFromDictionary()
{ {
unspawnHandlers.Add(Guid.NewGuid(), null); unspawnHandlers.Add(Guid.NewGuid(), null);
unspawnHandlers.Add(Guid.NewGuid(), null); unspawnHandlers.Add(Guid.NewGuid(), null);
@ -985,7 +999,7 @@ public void ClearSpawners_RemovesAllUnspawnHandlersFromDictionary()
} }
[Test] [Test]
public void ClearSpawners_ClearsAllDictionary() public void ClearsAllDictionary()
{ {
prefabs.Add(Guid.NewGuid(), null); prefabs.Add(Guid.NewGuid(), null);
prefabs.Add(Guid.NewGuid(), null); prefabs.Add(Guid.NewGuid(), null);