public static void WriteMessageAsync(this NetworkStream stream, MessageData msg) { if (stream == null) throw new ArgumentException(nameof(stream)); byte[] bytes = msg.ToByteArray(); stream.WriteAsync(bytes, 0, bytes.Length); }
public void TestMessageDataToByteConvertion2() { MessageData expectedMessage = new MessageData { Id = Guid.Empty, Command = Command.Login, Message = null, MessageTime = DateTime.MinValue, }; byte[] bytes = expectedMessage.ToByteArray(); var convertedMessage = (MessageData)bytes.ByteArrayToObject(); Assert.That(expectedMessage.Message, Is.EqualTo(convertedMessage.Message)); Assert.That(expectedMessage.Id, Is.EqualTo(convertedMessage.Id)); Assert.That(expectedMessage.Status, Is.EqualTo(convertedMessage.Status)); Assert.That(expectedMessage.Command, Is.EqualTo(convertedMessage.Command)); }