public void SendCallsSendOnConnection(int channel) { byte[] message = new byte[] { 0, 1, 2 }; player.Send(new ArraySegment <byte>(message), channel); if (channel == Channel.Reliable) { connection.Received(1).SendReliable(Arg.Is <ArraySegment <byte> >(arg => arg.SequenceEqual(message))); } else if (channel == Channel.Unreliable) { connection.Received(1).SendUnreliable(Arg.Is <ArraySegment <byte> >(arg => arg.SequenceEqual(message))); } }
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(); } }