From 152ffb11a7a94a578079abf1250e6cbcc5e7fd18 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 19 May 2021 19:23:27 +0800 Subject: [PATCH] NetworkMatchCheckerTest reuses MirrorTest --- Assets/Mirror/Tests/Common/MirrorTest.cs.meta | 2 +- .../Tests/Editor/NetworkMatchCheckerTest.cs | 39 ++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Assets/Mirror/Tests/Common/MirrorTest.cs.meta b/Assets/Mirror/Tests/Common/MirrorTest.cs.meta index 2db44f149..2f51f7e36 100644 --- a/Assets/Mirror/Tests/Common/MirrorTest.cs.meta +++ b/Assets/Mirror/Tests/Common/MirrorTest.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7fa0fda5a1b61474d915a9ab9f9b3a1e +guid: a6110480a9c07423290301aedafb2a93 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Mirror/Tests/Editor/NetworkMatchCheckerTest.cs b/Assets/Mirror/Tests/Editor/NetworkMatchCheckerTest.cs index a8140e896..5fa719bbc 100644 --- a/Assets/Mirror/Tests/Editor/NetworkMatchCheckerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkMatchCheckerTest.cs @@ -5,7 +5,7 @@ namespace Mirror.Tests { - public class NetworkMatchCheckerTest + public class NetworkMatchCheckerTest : MirrorTest { GameObject player1; GameObject player2; @@ -17,32 +17,26 @@ public class NetworkMatchCheckerTest NetworkConnection player1Connection; NetworkConnection player2Connection; NetworkConnection player3Connection; - GameObject transportGO; static int nextConnectionId; Dictionary> matchPlayers; [SetUp] - public void Setup() + public override void SetUp() { - transportGO = new GameObject("transportGO"); - Transport.activeTransport = transportGO.AddComponent(); + base.SetUp(); #pragma warning disable 618 - player1 = new GameObject("TestPlayer1", typeof(NetworkIdentity), typeof(NetworkMatchChecker)); - player2 = new GameObject("TestPlayer2", typeof(NetworkIdentity), typeof(NetworkMatchChecker)); -#pragma warning restore 618 + CreateNetworked(out player1, out NetworkIdentity _, out player1MatchChecker); + player1.name = "TestPlayer1"; + + CreateNetworked(out player2, out NetworkIdentity _, out player2MatchChecker); + player2.name = "TestPlayer2"; + player3 = new GameObject("TestPlayer3", typeof(NetworkIdentity)); -#pragma warning disable 618 - player1MatchChecker = player1.GetComponent(); - player2MatchChecker = player2.GetComponent(); -#pragma warning restore 618 - - player1Connection = CreateNetworkConnection(player1); player2Connection = CreateNetworkConnection(player2); player3Connection = CreateNetworkConnection(player3); -#pragma warning disable 618 matchPlayers = NetworkMatchChecker.matchPlayers; #pragma warning restore 618 } @@ -58,15 +52,14 @@ static NetworkConnection CreateNetworkConnection(GameObject player) } [TearDown] - public void TearDown() + public override void TearDown() { - UnityEngine.Object.DestroyImmediate(player1); - UnityEngine.Object.DestroyImmediate(player2); UnityEngine.Object.DestroyImmediate(player3); - UnityEngine.Object.DestroyImmediate(transportGO); matchPlayers.Clear(); matchPlayers = null; + + base.TearDown(); } [Test] @@ -74,8 +67,8 @@ public void OnCheckObserverShouldBeTrueForSameMatchId() { string guid = Guid.NewGuid().ToString(); - player1MatchChecker.currentMatch = new Guid(guid); - player2MatchChecker.currentMatch = new Guid(guid); + player1MatchChecker.currentMatch = new Guid(guid); + player2MatchChecker.currentMatch = new Guid(guid); bool player1Visable = player1MatchChecker.OnCheckObserver(player1Connection); Assert.IsTrue(player1Visable); @@ -123,8 +116,8 @@ public void OnCheckObserverShouldBeFalseForEmptyGuid() { string guid = Guid.Empty.ToString(); - player1MatchChecker.currentMatch = new Guid(guid); - player2MatchChecker.currentMatch = new Guid(guid); + player1MatchChecker.currentMatch = new Guid(guid); + player2MatchChecker.currentMatch = new Guid(guid); bool player1Visable = player1MatchChecker.OnCheckObserver(player1Connection); Assert.IsFalse(player1Visable);