From f6c8e0e89e50813158d0e52b54e8b3a925cd828a Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 27 Feb 2020 10:04:58 +0100 Subject: [PATCH] NetworkIdentityTests: OnStartServer test makes sure that OnStartServer was called exactly once --- Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs index 097e90582..4d6b126e2 100644 --- a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs @@ -24,8 +24,10 @@ public override void OnStartServer() class StartServerExceptionNetworkBehaviour : NetworkBehaviour { + public int called; public override void OnStartServer() { + ++called; throw new Exception("some exception"); } } @@ -325,16 +327,20 @@ public void OnStartServerComponentExceptionIsCaught() // create a networkidentity with our test component GameObject gameObject = new GameObject(); NetworkIdentity identity = gameObject.AddComponent(); - gameObject.AddComponent(); + StartServerExceptionNetworkBehaviour comp = gameObject.AddComponent(); + // make sure that comp.OnStartServer was called and make sure that + // the exception was caught and not thrown in here. // an exception in OnStartServer should be caught, so that one // component's exception doesn't stop all other components from // being initialized // (an error log is expected though) LogAssert.ignoreFailingMessages = true; identity.OnStartServer(); // should catch the exception internally and not throw it + Assert.That(comp.called, Is.EqualTo(1)); LogAssert.ignoreFailingMessages = false; + // clean up GameObject.DestroyImmediate(gameObject); }