MessageTests: SyncEventMessageTest

This commit is contained in:
vis2k 2020-01-27 14:31:50 +01:00
parent 8d272a4107
commit ef7993cac1

View File

@ -79,5 +79,33 @@ public void RpcMessageTest()
Assert.That(fresh.payload.Array[fresh.payload.Offset + i],
Is.EqualTo(message.payload.Array[message.payload.Offset + i]));
}
[Test]
public void SyncEventMessageTest()
{
// try setting value with constructor
SyncEventMessage message = new SyncEventMessage {
netId = 42,
componentIndex = 4,
functionHash = 0xABCDEF,
payload = new ArraySegment<byte>(new byte[]{0x01, 0x02})
};
// serialize
NetworkWriter writer = new NetworkWriter();
message.Serialize(writer);
byte[] writerData = writer.ToArray();
// deserialize the same data - do we get the same result?
SyncEventMessage fresh = new SyncEventMessage();
fresh.Deserialize(new NetworkReader(writerData));
Assert.That(fresh.netId, Is.EqualTo(message.netId));
Assert.That(fresh.componentIndex, Is.EqualTo(message.componentIndex));
Assert.That(fresh.functionHash, Is.EqualTo(message.functionHash));
Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count));
for (int i = 0; i < fresh.payload.Count; ++i)
Assert.That(fresh.payload.Array[fresh.payload.Offset + i],
Is.EqualTo(message.payload.Array[message.payload.Offset + i]));
}
}
}