NetworkIdentityTests: OnStartServer test makes sure that OnStartServer was called exactly once

This commit is contained in:
vis2k 2020-02-27 10:04:58 +01:00
parent 617bd0a175
commit f6c8e0e89e

View File

@ -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<NetworkIdentity>();
gameObject.AddComponent<StartServerExceptionNetworkBehaviour>();
StartServerExceptionNetworkBehaviour comp = gameObject.AddComponent<StartServerExceptionNetworkBehaviour>();
// 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);
}