NetworkManagerCallbacksOrderOnTheHost.cs
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine.TestTools;
using UnityEngine;
using UnityEngine.Networking;
#pragma warning disable 618
public class NetworkManagerCallbacksOrderOnTheHost
{
public static List<string> resultListOfCallbacks = new List<string>()
{
"OnStartHost",
"OnStartServer",
"OnServerConnect",
"OnStartClient",
"OnServerReady",
"OnServerAddPlayer",
"OnClientConnect",
"OnStopHost",
"OnStopServer",
"OnStopClient"
};
[UnityTest]
public IEnumerator CallbacksOrderInNetworkManagerOnTheHostIsCorrect()
{
NetworkServer.Reset();
NetworkClient.ShutdownAll();
GameObject nmObject = new GameObject();
CustomNetworkManagerWithCallbacks nmanager = nmObject.AddComponent<CustomNetworkManagerWithCallbacks>();
nmanager.playerPrefab = Resources.Load("CleanPlayerPrefab", typeof(GameObject)) as GameObject;
yield return null;
Assert.IsNotNull(nmanager.playerPrefab, "Player prefab field is not set on NetworkManager");
nmanager.StartHost();
yield return null;
Assert.IsTrue(NetworkServer.active, "Server is not active after StartHost");
Assert.IsTrue(NetworkClient.active, "Client is not active after StartHost");
yield return null;
while (!nmanager.isStartHostPartDone)
{
yield return null;
}
nmanager.StopHost();
while (!nmanager.isStopHostPartDone)
{
yield return null;
}
CollectionAssert.AreEqual(resultListOfCallbacks, nmanager.actualListOfCallbacks, "Wrong order of callbacks or some callback is missing");
Object.Destroy(nmObject);
}
}
#pragma warning restore 618