public void TickTester_CheckEncodeDecode() { Tick tick1 = new Tick(10); tick1.LogicalClock = 100; ByteList bytes = new ByteList(); tick1.Encode(bytes); Tick tick2 = Tick.Create(bytes); Assert.AreEqual(10, tick1.ForAgentId); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); tick1.LogicalClock = 0; bytes = new ByteList(); tick1.Encode(bytes); tick2 = Tick.Create(bytes); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); tick1.LogicalClock = Int32.MaxValue; bytes = new ByteList(); tick1.Encode(bytes); tick2 = Tick.Create(bytes); Assert.AreEqual(tick1.ForAgentId, tick1.ForAgentId); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); bytes.Clear(); tick1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { tick2 = Tick.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); tick1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { tick2 = Tick.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }