public void Int16Tests(Int16 number, Byte[] expectedBytes) { // arrange var memoryStream = new MemoryStream(); var binaryWriter = new BigEndianBinaryWriter(memoryStream); // act binaryWriter.Write(number); // assert var actualBytes = memoryStream.ToArray(); Assert.That(expectedBytes, Is.EqualTo(actualBytes)); }
public void WhenMessageIsTruncatedThenBufferUnderRunExceptionIsThrown() { // arrange var offset = (Int64)0; var message = new Byte[] { }; var messageSize = message.Length + 1; var memoryStream = new MemoryStream(); var binaryWriter = new BigEndianBinaryWriter(memoryStream); binaryWriter.Write(offset); binaryWriter.Write(messageSize); binaryWriter.Write(message); var payloadBytes = memoryStream.ToArray(); // act/assert Assert.Throws<BufferUnderRunException>(() => Message.DecodeMessageSet(payloadBytes).ToList()); }
public KafkaMessagePacker() { _stream = new BigEndianBinaryWriter(new MemoryStream()); Pack(IntegerByteSize); //pre-allocate space for buffer length }
public void CharSubArrayTests(Char[] value, Int32 index, Int32 count, Byte[] expectedBytes) { // arrange var memoryStream = new MemoryStream(); var binaryWriter = new BigEndianBinaryWriter(memoryStream); // act binaryWriter.Write(value, index, count); // assert var actualBytes = memoryStream.ToArray(); Assert.That(expectedBytes, Is.EqualTo(actualBytes)); }
public void StringTests(String value, Byte[] expectedBytes, StringPrefixEncoding encoding) { // arrange var memoryStream = new MemoryStream(); var binaryWriter = new BigEndianBinaryWriter(memoryStream); // act binaryWriter.Write(value, encoding); // assert var actualBytes = memoryStream.ToArray(); Assert.That(expectedBytes, Is.EqualTo(actualBytes)); }
public void StringNotSupportedTest() { // arrange var memoryStream = new MemoryStream(); var binaryWriter = new BigEndianBinaryWriter(memoryStream); binaryWriter.Write("test"); }