NetworkMatchCheckerTest reuses MirrorTest

This commit is contained in:
vis2k 2021-05-19 19:23:27 +08:00
parent 09d749e613
commit 152ffb11a7
2 changed files with 17 additions and 24 deletions

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 7fa0fda5a1b61474d915a9ab9f9b3a1e guid: a6110480a9c07423290301aedafb2a93
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -5,7 +5,7 @@
namespace Mirror.Tests namespace Mirror.Tests
{ {
public class NetworkMatchCheckerTest public class NetworkMatchCheckerTest : MirrorTest
{ {
GameObject player1; GameObject player1;
GameObject player2; GameObject player2;
@ -17,32 +17,26 @@ public class NetworkMatchCheckerTest
NetworkConnection player1Connection; NetworkConnection player1Connection;
NetworkConnection player2Connection; NetworkConnection player2Connection;
NetworkConnection player3Connection; NetworkConnection player3Connection;
GameObject transportGO;
static int nextConnectionId; static int nextConnectionId;
Dictionary<Guid, HashSet<NetworkIdentity>> matchPlayers; Dictionary<Guid, HashSet<NetworkIdentity>> matchPlayers;
[SetUp] [SetUp]
public void Setup() public override void SetUp()
{ {
transportGO = new GameObject("transportGO"); base.SetUp();
Transport.activeTransport = transportGO.AddComponent<MemoryTransport>();
#pragma warning disable 618 #pragma warning disable 618
player1 = new GameObject("TestPlayer1", typeof(NetworkIdentity), typeof(NetworkMatchChecker)); CreateNetworked(out player1, out NetworkIdentity _, out player1MatchChecker);
player2 = new GameObject("TestPlayer2", typeof(NetworkIdentity), typeof(NetworkMatchChecker)); player1.name = "TestPlayer1";
#pragma warning restore 618
CreateNetworked(out player2, out NetworkIdentity _, out player2MatchChecker);
player2.name = "TestPlayer2";
player3 = new GameObject("TestPlayer3", typeof(NetworkIdentity)); player3 = new GameObject("TestPlayer3", typeof(NetworkIdentity));
#pragma warning disable 618
player1MatchChecker = player1.GetComponent<NetworkMatchChecker>();
player2MatchChecker = player2.GetComponent<NetworkMatchChecker>();
#pragma warning restore 618
player1Connection = CreateNetworkConnection(player1); player1Connection = CreateNetworkConnection(player1);
player2Connection = CreateNetworkConnection(player2); player2Connection = CreateNetworkConnection(player2);
player3Connection = CreateNetworkConnection(player3); player3Connection = CreateNetworkConnection(player3);
#pragma warning disable 618
matchPlayers = NetworkMatchChecker.matchPlayers; matchPlayers = NetworkMatchChecker.matchPlayers;
#pragma warning restore 618 #pragma warning restore 618
} }
@ -58,15 +52,14 @@ static NetworkConnection CreateNetworkConnection(GameObject player)
} }
[TearDown] [TearDown]
public void TearDown() public override void TearDown()
{ {
UnityEngine.Object.DestroyImmediate(player1);
UnityEngine.Object.DestroyImmediate(player2);
UnityEngine.Object.DestroyImmediate(player3); UnityEngine.Object.DestroyImmediate(player3);
UnityEngine.Object.DestroyImmediate(transportGO);
matchPlayers.Clear(); matchPlayers.Clear();
matchPlayers = null; matchPlayers = null;
base.TearDown();
} }
[Test] [Test]
@ -74,8 +67,8 @@ public void OnCheckObserverShouldBeTrueForSameMatchId()
{ {
string guid = Guid.NewGuid().ToString(); string guid = Guid.NewGuid().ToString();
player1MatchChecker.currentMatch = new Guid(guid); player1MatchChecker.currentMatch = new Guid(guid);
player2MatchChecker.currentMatch = new Guid(guid); player2MatchChecker.currentMatch = new Guid(guid);
bool player1Visable = player1MatchChecker.OnCheckObserver(player1Connection); bool player1Visable = player1MatchChecker.OnCheckObserver(player1Connection);
Assert.IsTrue(player1Visable); Assert.IsTrue(player1Visable);
@ -123,8 +116,8 @@ public void OnCheckObserverShouldBeFalseForEmptyGuid()
{ {
string guid = Guid.Empty.ToString(); string guid = Guid.Empty.ToString();
player1MatchChecker.currentMatch = new Guid(guid); player1MatchChecker.currentMatch = new Guid(guid);
player2MatchChecker.currentMatch = new Guid(guid); player2MatchChecker.currentMatch = new Guid(guid);
bool player1Visable = player1MatchChecker.OnCheckObserver(player1Connection); bool player1Visable = player1MatchChecker.OnCheckObserver(player1Connection);
Assert.IsFalse(player1Visable); Assert.IsFalse(player1Visable);