public void CanSerializeMovePacket()
        {
            _mockGuidSerializer.Serialize(_packet.Id).Returns("A");
            _mockVectorSerializer.Serialize(_packet.Move).Returns("B");
            _mockQuaternionSerializer.Serialize(_packet.Rotation).Returns("C");

            Check.That(_serializer.Serialize(_packet)).IsEqualTo(
                string.Format("A{0}B{0}C{0}1", Environment.NewLine));
        }
Example #2
0
        private PacketSerializer SetupPacketSerializer()
        {
            var packetSerializer     = new PacketSerializer();
            var movePacketSerializer = new MovePacketSerializer(new GuidSerializer(), new Vector3Serializer(),
                                                                new QuaternionSerializer());
            var spawnPacketSerializer = new SpawnPacketSerializer(new GuidSerializer(), new Vector3Serializer(),
                                                                  new QuaternionSerializer());
            var destroyPacketSerializer = new DestroyPacketSerializer();

            packetSerializer.Serializers.Add(typeof(MovePacket), packet => movePacketSerializer.Serialize((MovePacket)packet));
            packetSerializer.Serializers.Add(typeof(SpawnPacket), packet => spawnPacketSerializer.Serialize((SpawnPacket)packet));
            packetSerializer.Serializers.Add(typeof(DestroyPacket), packet => destroyPacketSerializer.Serialize(((DestroyPacket)packet).Id));
            return(packetSerializer);
        }
Example #3
0
        private PacketSerializer GetPacketSerializer()
        {
            var serializer     = new PacketSerializer();
            var spawnConverter = new SpawnPacketSerializer(
                new GuidSerializer(),
                new Vector3Serializer(),
                new QuaternionSerializer());
            var moveConverter = new MovePacketSerializer(
                new GuidSerializer(),
                new Vector3Serializer(),
                new QuaternionSerializer());
            IPacketConverter <DestroyPacket> destroyConverter = new DestroyPacketSerializer();

            serializer.Deserializers.Add(typeof(SpawnPacket), s => spawnConverter.Deserialize(s));
            serializer.Deserializers.Add(typeof(MovePacket), s => moveConverter.Deserialize(s));
            serializer.Deserializers.Add(typeof(DestroyPacket), s => destroyConverter.Deserialize(s));

            serializer.Serializers.Add(typeof(SpawnPacket), packet => spawnConverter.Serialize((SpawnPacket)packet));
            serializer.Serializers.Add(typeof(MovePacket), packet => moveConverter.Serialize((MovePacket)packet));
            serializer.Serializers.Add(typeof(DestroyPacket), packet => destroyConverter.Serialize((DestroyPacket)packet));

            return(serializer);
        }