public static T AssertLengthMatches <T> (this T self) where T : Message, new() { if (self == null) { throw new ArgumentNullException("self"); } var stream = new MemoryStream(20480); var writer = new StreamValueWriter(stream); var reader = new StreamValueReader(stream); var msg = new T(); var context = SerializationContextTests.GetContext(msg.Protocol); self.WritePayload(context, writer); long len = stream.Position; stream.Position = 0; msg.ReadPayload(context, reader); Assert.AreEqual(len, stream.Position); return(msg); }
public void Serializer() { byte[] buffer = new byte[1024]; var writer = new BufferValueWriter(buffer); var c = SerializationContextTests.GetContext(MockProtocol.Instance); var p = new Protocol(42, 248); p.Serialize(c, writer); writer.Flush(); var reader = new BufferValueReader(buffer); var p2 = new Protocol(c, reader); Assert.AreEqual(p.id, p2.id); Assert.AreEqual(p.Version, p2.Version); }
public void Setup() { context = SerializationContextTests.GetContext(MockProtocol.Instance); }
public void CtorNull() { Assert.Throws <ArgumentNullException> (() => new RSAAsymmetricKey(null)); Assert.Throws <ArgumentNullException> (() => new RSAAsymmetricKey(SerializationContextTests.GetContext(MockProtocol.Instance), null)); }