Пример #1
0
 public void DisconnectStopsMessagesBeingSentToConnection()
 {
     player.Disconnect();
     player.Send(new ArraySegment <byte>(new byte[] { 0, 1, 2 }));
     connection.DidNotReceive().SendReliable(Arg.Any <byte[]>());
     connection.DidNotReceive().SendUnreliable(Arg.Any <byte[]>());
 }
Пример #2
0
        public void DisconnectsIfHandlerHasException(bool disconnectOnThrow)
        {
            messageHandler = new MessageHandler(null, disconnectOnThrow);

            int invoked = 0;

            messageHandler.RegisterHandler <SceneReadyMessage>(_ => { invoked++; throw new InvalidOperationException("Fun Exception"); });

            var packet = new ArraySegment <byte>(MessagePacker.Pack(new SceneReadyMessage()));

            LogAssert.ignoreFailingMessages = true;
            Assert.DoesNotThrow(() =>
            {
                messageHandler.HandleMessage(player, packet);
            });
            LogAssert.ignoreFailingMessages = false;

            Assert.That(invoked, Is.EqualTo(1), "Should have been invoked");

            if (disconnectOnThrow)
            {
                connection.Received(1).Disconnect();
            }
            else
            {
                connection.DidNotReceive().Disconnect();
            }
        }