public void CanWriteReadByteArray() { // Arrange MySerializationMessage <MyIdentity> msg = new MySerializationMessage <MyIdentity>(BuildId(), "Blah", "Blah blah ..."); // Act byte[] data = Serializer.Serialize(msg); Assert.IsNotNull(data); Assert.Greater(data.Length, 0); MySerializationMessage <MyIdentity> result = (MySerializationMessage <MyIdentity>)Serializer.Deserialize(data); // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Id); Assert.IsNotNull(result.Title); Assert.IsNotNull(result.Description); Assert.AreEqual(msg.Id.Literal, result.Id.Literal); Assert.AreEqual(msg.Id, result.Id); Assert.AreEqual(msg.Title, result.Title); Assert.AreEqual(msg.Description, result.Description); }
public void CanWriteReadStream() { // Arrange MySerializationMessage <MyIdentity> msg = new MySerializationMessage <MyIdentity>(BuildId(), "Blah", "Blah blah ..."); // Act using (var s1 = new MemoryStream()) { Serializer.Serialize(s1, msg); using (var s2 = new MemoryStream(s1.ToArray())) { MySerializationMessage <MyIdentity> result = (MySerializationMessage <MyIdentity>)Serializer.Deserialize(s2); // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Id); Assert.IsNotNull(result.Title); Assert.IsNotNull(result.Description); Assert.AreEqual(msg.Id, result.Id); Assert.AreEqual(msg.Title, result.Title); Assert.AreEqual(msg.Description, result.Description); } } }