public void SetUp() { data = new SceneMessage(); mockTransportConnection = Substitute.For <IConnection>(); void ParsePacket(ArraySegment <byte> data) { var reader = new NetworkReader(data); _ = MessagePacker.UnpackId(reader); lastSent = reader.ReadNotifyPacket(); lastSerializedPacket = new byte[data.Count]; Array.Copy(data.Array, data.Offset, lastSerializedPacket, 0, data.Count); } mockTransportConnection.Send( Arg.Do <ArraySegment <byte> >(ParsePacket), Channel.Unreliable); player = new NetworkPlayer(mockTransportConnection); serializedMessage = MessagePacker.Pack(new ReadyMessage()); player.RegisterHandler <ReadyMessage>(message => { }); delivered = Substitute.For <Action <INetworkPlayer, object> >(); lost = Substitute.For <Action <INetworkPlayer, object> >(); player.NotifyDelivered += delivered; player.NotifyLost += lost; }
public void UnpackInvalidMessage() { // try an invalid message Assert.Throws <EndOfStreamException>(() => { var reader2 = new NetworkReader(new byte[0]); _ = MessagePacker.UnpackId(reader2); }); }
public void UnpackInvalidMessage() { // try an invalid message Assert.Throws <EndOfStreamException>(() => { reader.Reset(new byte[0]); _ = MessagePacker.UnpackId(reader); }); }
public void TestUnpackMessageNonGeneric() { // try a regular message var message = new SceneMessage { scenePath = "Hello world", sceneOperation = SceneOperation.LoadAdditive }; byte[] data = MessagePacker.Pack(message); var reader = new NetworkReader(data); int msgType = MessagePacker.UnpackId(reader); Assert.That(msgType, Is.EqualTo(BitConverter.ToUInt16(data, 0))); }
public void TestUnpackMessageNonGeneric() { // try a regular message var message = new SceneMessage { MainActivateScene = "Hello world", SceneOperation = SceneOperation.LoadAdditive }; var data = MessagePacker.Pack(message); reader.Reset(data); var msgType = MessagePacker.UnpackId(reader); Assert.That(msgType, Is.EqualTo(BitConverter.ToUInt16(data, 0))); }