Tests: MultiplexTransportEnableTest moved to separate file

This commit is contained in:
vis2k 2021-05-26 19:30:02 +08:00
parent 227402c6aa
commit 9b78ee82f1
3 changed files with 58 additions and 52 deletions

View File

@ -2,7 +2,7 @@
using NUnit.Framework; using NUnit.Framework;
using UnityEngine; using UnityEngine;
namespace Mirror.Tests.Runtime.TransportEnableTest namespace Mirror.Tests.Runtime
{ {
public class FallbackTransportEnableTest public class FallbackTransportEnableTest
{ {
@ -53,55 +53,4 @@ public void DisableShouldDisableAvailableTransport()
Assert.That(transport2.enabled, Is.True); Assert.That(transport2.enabled, Is.True);
} }
} }
public class MultiplexTransportEnableTest
{
MemoryTransport transport1;
MemoryTransport transport2;
MultiplexTransport transport;
[SetUp]
public void Setup()
{
GameObject gameObject = new GameObject();
// set inactive so that awake isn't called
gameObject.SetActive(false);
transport1 = gameObject.AddComponent<MemoryTransport>();
transport2 = gameObject.AddComponent<MemoryTransport>();
transport = gameObject.AddComponent<MultiplexTransport>();
transport.transports = new[] { transport1, transport2 };
gameObject.SetActive(true);
}
[TearDown]
public void TearDown()
{
GameObject.DestroyImmediate(transport.gameObject);
}
[Test]
public void DisableShouldDisableAllTransports()
{
transport.Awake();
// starts enabled
Assert.That(transport1.enabled, Is.True);
Assert.That(transport2.enabled, Is.True);
// disabling MultiplexTransport
transport.enabled = false;
Assert.That(transport1.enabled, Is.False);
Assert.That(transport2.enabled, Is.False);
// enabling MultiplexTransport
transport.enabled = true;
Assert.That(transport1.enabled, Is.True);
Assert.That(transport2.enabled, Is.True);
}
}
} }

View File

@ -0,0 +1,54 @@
using NUnit.Framework;
using UnityEngine;
namespace Mirror.Tests.Runtime
{
public class MultiplexTransportEnableTest
{
MemoryTransport transport1;
MemoryTransport transport2;
MultiplexTransport transport;
[SetUp]
public void Setup()
{
GameObject gameObject = new GameObject();
// set inactive so that awake isn't called
gameObject.SetActive(false);
transport1 = gameObject.AddComponent<MemoryTransport>();
transport2 = gameObject.AddComponent<MemoryTransport>();
transport = gameObject.AddComponent<MultiplexTransport>();
transport.transports = new[] { transport1, transport2 };
gameObject.SetActive(true);
}
[TearDown]
public void TearDown()
{
GameObject.DestroyImmediate(transport.gameObject);
}
[Test]
public void DisableShouldDisableAllTransports()
{
transport.Awake();
// starts enabled
Assert.That(transport1.enabled, Is.True);
Assert.That(transport2.enabled, Is.True);
// disabling MultiplexTransport
transport.enabled = false;
Assert.That(transport1.enabled, Is.False);
Assert.That(transport2.enabled, Is.False);
// enabling MultiplexTransport
transport.enabled = true;
Assert.That(transport1.enabled, Is.True);
Assert.That(transport2.enabled, Is.True);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 06352e90eaaa45b09d12e717dd0cae7c
timeCreated: 1622028545