public void WatchdogScheduledItem_SerializationTest() { // Serialize to the output buffer as binary. OutputBuffer output = new OutputBuffer(); CompactBinaryWriter <OutputBuffer> writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, hcs); // De-serialize from the binary output. InputBuffer input = new InputBuffer(output.Data); CompactBinaryReader <InputBuffer> reader = new CompactBinaryReader <InputBuffer>(input); WatchdogScheduledItem hcs1 = Deserialize <WatchdogScheduledItem> .From(reader); Assert.IsTrue(hcs.Equals(hcs1)); // Using the generic BondCustomSerializer. using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { BondCustomSerializer <WatchdogScheduledItem> bcs = new BondCustomSerializer <WatchdogScheduledItem>(); bcs.Write(hcs, bw); ms.Position = 0L; using (BinaryReader br = new BinaryReader(ms)) { hcs1 = bcs.Read(br); Assert.IsTrue(hcs.Equals(hcs1)); } } } }
public void HealthCheck_SerializationTest() { // Serialize to the output buffer as binary. OutputBuffer output = new OutputBuffer(); CompactBinaryWriter <OutputBuffer> writer = new CompactBinaryWriter <OutputBuffer>(output); Serialize.To(writer, hc); // De-serialize from the binary output. InputBuffer input = new InputBuffer(output.Data); CompactBinaryReader <InputBuffer> reader = new CompactBinaryReader <InputBuffer>(input); HealthCheck hc1 = Deserialize <HealthCheck> .From(reader); Assert.IsTrue(hc.Equals(hc1)); // Serialize as JSON using NewtonSoft. string json = JsonConvert.SerializeObject(hc, Formatting.None); hc1 = JsonConvert.DeserializeObject <HealthCheck>(json); Assert.IsTrue(hc.Equals(hc1)); // Using the generic BondCustomSerializer. using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { BondCustomSerializer <HealthCheck> bcs = new BondCustomSerializer <HealthCheck>(); bcs.Write(hc, bw); ms.Position = 0L; using (BinaryReader br = new BinaryReader(ms)) { hc1 = bcs.Read(br); Assert.IsTrue(hc.Equals(hc1)); } } } }