NetworkServerTest: SendToAll simplified

This commit is contained in:
vis2k 2021-06-15 17:12:58 +08:00
parent b2ae4ef7e1
commit afeef26fdb

View File

@ -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));