Tests: merge HostSetup into the only class that inherits from it

This commit is contained in:
vis2k 2021-08-10 19:19:14 +08:00
parent 87478178e9
commit 4925f1397a
3 changed files with 58 additions and 78 deletions

View File

@ -5,8 +5,65 @@
namespace Mirror.Tests.Runtime namespace Mirror.Tests.Runtime
{ {
public class ClientSceneTest_LocalPlayer_AsHost : HostSetup public class ClientSceneTest_LocalPlayer_AsHost : MirrorPlayModeTest
{ {
protected GameObject networkManagerGo;
protected NetworkManager manager;
protected GameObject playerGO;
protected NetworkIdentity identity;
protected virtual bool AutoAddPlayer => true;
protected virtual void afterStartHost() {}
protected virtual void beforeStopHost() {}
[UnitySetUp]
public override IEnumerator UnitySetUp()
{
base.SetUp();
networkManagerGo = transport.gameObject;
manager = networkManagerGo.AddComponent<NetworkManager>();
Transport.activeTransport = transport;
// create a tracked prefab (not spawned)
CreateGameObject(out playerGO);
identity = playerGO.AddComponent<NetworkIdentity>();
identity.assetId = System.Guid.NewGuid();
manager.playerPrefab = playerGO;
manager.autoStartServerBuild = false;
manager.autoCreatePlayer = AutoAddPlayer;
if (Application.isBatchMode)
{
Application.targetFrameRate = 60;
}
yield return null;
manager.StartHost();
yield return null;
afterStartHost();
}
[UnityTearDown]
public override IEnumerator UnityTearDown()
{
beforeStopHost();
yield return null;
// needed for stophost
Transport.activeTransport = transport;
manager.StopHost();
base.TearDown();
}
[UnityTest] [UnityTest]
public IEnumerator LocalPlayerIsSetToNullAfterNetworkDestroy() public IEnumerator LocalPlayerIsSetToNullAfterNetworkDestroy()
{ {

View File

@ -1,66 +0,0 @@
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;
namespace Mirror.Tests.Runtime
{
public class HostSetup : MirrorPlayModeTest
{
protected GameObject networkManagerGo;
protected NetworkManager manager;
protected GameObject playerGO;
protected NetworkIdentity identity;
protected virtual bool AutoAddPlayer => true;
protected virtual void afterStartHost() {}
protected virtual void beforeStopHost() {}
[UnitySetUp]
public override IEnumerator UnitySetUp()
{
base.SetUp();
networkManagerGo = transport.gameObject;
manager = networkManagerGo.AddComponent<NetworkManager>();
Transport.activeTransport = transport;
// create a tracked prefab (not spawned)
CreateGameObject(out playerGO);
identity = playerGO.AddComponent<NetworkIdentity>();
identity.assetId = System.Guid.NewGuid();
manager.playerPrefab = playerGO;
manager.autoStartServerBuild = false;
manager.autoCreatePlayer = AutoAddPlayer;
if (Application.isBatchMode)
{
Application.targetFrameRate = 60;
}
yield return null;
manager.StartHost();
yield return null;
afterStartHost();
}
[UnityTearDown]
public override IEnumerator UnityTearDown()
{
beforeStopHost();
yield return null;
// needed for stophost
Transport.activeTransport = transport;
manager.StopHost();
base.TearDown();
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ed9f33fa2d684c64cb12abd81ecdc849
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: