mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkServerTest: SendToAll simplified
This commit is contained in:
parent
b2ae4ef7e1
commit
afeef26fdb
@ -553,32 +553,17 @@ public void ActivateHostSceneCallsOnStartClient()
|
|||||||
[Test]
|
[Test]
|
||||||
public void SendToAll()
|
public void SendToAll()
|
||||||
{
|
{
|
||||||
// listen
|
// message handler
|
||||||
NetworkServer.Listen(1);
|
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
|
||||||
|
|
||||||
// setup connections
|
|
||||||
CreateLocalConnectionPair(out LocalConnectionToClient connectionToClient,
|
|
||||||
out LocalConnectionToServer connectionToServer);
|
|
||||||
|
|
||||||
// setup NetworkServer/Client connections so messages are handled
|
|
||||||
NetworkClient.connection = connectionToServer;
|
|
||||||
NetworkServer.connections[connectionToClient.connectionId] = connectionToClient;
|
|
||||||
|
|
||||||
// set a client handler
|
|
||||||
int called = 0;
|
int called = 0;
|
||||||
void Handler(TestMessage1 _) => ++called;
|
NetworkClient.RegisterHandler<TestMessage1>(msg => ++called, false);
|
||||||
NetworkClient.RegisterHandler<TestMessage1>(Handler, false);
|
|
||||||
NetworkServer.AddConnection(connectionToClient);
|
|
||||||
|
|
||||||
// create a message
|
// listen & connect
|
||||||
TestMessage1 message = new TestMessage1 { IntValue = 1, DoubleValue = 2, StringValue = "3" };
|
NetworkServer.Listen(1);
|
||||||
|
ConnectClientBlocking();
|
||||||
|
|
||||||
// send it to all
|
// send & process
|
||||||
NetworkServer.SendToAll(message);
|
NetworkServer.SendToAll(new TestMessage1());
|
||||||
|
ProcessMessages();
|
||||||
// update local connection once so that the incoming queue is processed
|
|
||||||
connectionToClient.connectionToServer.Update();
|
|
||||||
|
|
||||||
// was it send to and handled by the connection?
|
// was it send to and handled by the connection?
|
||||||
Assert.That(called, Is.EqualTo(1));
|
Assert.That(called, Is.EqualTo(1));
|
||||||
|
Loading…
Reference in New Issue
Block a user