-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fallback and Multiplex now disable their transports when they ar…
…e disabled (#2048) * test to check if fallbacks disables other transport * using ondisable to disable other transport * fixing teardown * adding test for Multiplex * using ondisable to disable other transport * fixing NSubstitute for 2019
- Loading branch information
1 parent
ab1b92f
commit 61d44b2
Showing
5 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
Assets/Mirror/Tests/Runtime/FallbackTransportEnableTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace Mirror.Tests.Runtime.TransportEnableTest | ||
{ | ||
public class FallbackTransportEnableTest | ||
{ | ||
Transport transport1; | ||
MemoryTransport transport2; | ||
FallbackTransport transport; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
GameObject gameObject = new GameObject(); | ||
// set inactive so that awake isnt called | ||
gameObject.SetActive(false); | ||
|
||
transport1 = Substitute.For<Transport>(); | ||
transport2 = gameObject.AddComponent<MemoryTransport>(); | ||
|
||
transport = gameObject.AddComponent<FallbackTransport>(); | ||
transport.transports = new[] { transport1, transport2 }; | ||
|
||
gameObject.SetActive(true); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
GameObject.DestroyImmediate(transport.gameObject); | ||
} | ||
|
||
[Test] | ||
public void DisableShouldDisableAvailableTransport() | ||
{ | ||
// make transport2 the active transport | ||
transport1.Available().Returns(false); | ||
transport.Awake(); | ||
|
||
// starts enabled | ||
Assert.That(transport2.enabled, Is.True); | ||
|
||
// disabling FallbackTransport | ||
transport.enabled = false; | ||
Assert.That(transport2.enabled, Is.False); | ||
|
||
// enabling FallbackTransport | ||
transport.enabled = 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 isnt 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); | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Mirror/Tests/Runtime/FallbackTransportEnableTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters