Multiplex Test: reuse CreateGameObject with component

This commit is contained in:
vis2k 2021-08-07 13:44:52 +08:00
parent 70f117a950
commit 3350760edb

View File

@ -1,38 +1,29 @@
using System; using System;
using NSubstitute; using NSubstitute;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine;
namespace Mirror.Tests namespace Mirror.Tests
{ {
public class MultiplexTest public class MultiplexTest : MirrorTest
{ {
Transport transport1; Transport transport1;
Transport transport2; Transport transport2;
MultiplexTransport transport; new MultiplexTransport transport;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
base.SetUp();
CreateGameObject(out _, out transport);
transport1 = Substitute.For<Transport>(); transport1 = Substitute.For<Transport>();
transport2 = Substitute.For<Transport>(); transport2 = Substitute.For<Transport>();
GameObject gameObject = new GameObject();
transport = gameObject.AddComponent<MultiplexTransport>();
transport.transports = new[] { transport1, transport2 }; transport.transports = new[] { transport1, transport2 };
transport.Awake(); transport.Awake();
} }
[TearDown]
public void TearDown()
{
GameObject.DestroyImmediate(transport.gameObject);
}
#region Client tests
// A Test behaves as an ordinary method // A Test behaves as an ordinary method
[Test] [Test]
public void TestAvailable() public void TestAvailable()
@ -165,10 +156,6 @@ public void TestClient2Connected()
callback.Received().Invoke(); callback.Received().Invoke();
} }
#endregion
#region Server tests
[Test] [Test]
public void TestServerConnected() public void TestServerConnected()
{ {
@ -189,9 +176,5 @@ void SendMessage(int connectionId)
transport1.Received().ServerSend(1, segment, 5); transport1.Received().ServerSend(1, segment, 5);
} }
#endregion
} }
} }