public void GetByteRange_WhenBufferIsSmallerThanRequestedCount_Throws() { // Arrange var bytes1 = Enumerable.Repeat((byte)1, 10).ToArray(); var bytes2 = Enumerable.Repeat((byte)2, 10).ToArray(); var bytes3 = Enumerable.Repeat((byte)3, 10).ToArray(); var memoryByteBuffer1 = new MemoryByteBuffer(bytes1); var memoryByteBuffer2 = new MemoryByteBuffer(bytes2); var memoryByteBuffer3 = new MemoryByteBuffer(bytes3); var compositeByteBuffer = new CompositeByteBuffer(memoryByteBuffer1, memoryByteBuffer2, memoryByteBuffer3); // Act + Assert var actual = new byte[10]; Assert.Throws <ArgumentException>(() => compositeByteBuffer.GetByteRange(0, 20, actual)); }
public void GetByteRange_CompareWithInitializer_ExactMatch(int offset, int count) { // Arrange var bytes1 = Enumerable.Repeat((byte)1, 10).ToArray(); var bytes2 = Enumerable.Repeat((byte)2, 10).ToArray(); var bytes3 = Enumerable.Repeat((byte)3, 10).ToArray(); var memoryByteBuffer1 = new MemoryByteBuffer(bytes1); var memoryByteBuffer2 = new MemoryByteBuffer(bytes2); var memoryByteBuffer3 = new MemoryByteBuffer(bytes3); var compositeByteBuffer = new CompositeByteBuffer(memoryByteBuffer1, memoryByteBuffer2, memoryByteBuffer3); var expected = bytes1.Concat(bytes2).Concat(bytes3).Skip(offset).Take(count).ToArray(); // Act var actual = new byte[count]; compositeByteBuffer.GetByteRange(offset, count, actual); // Assert Assert.Equal(expected.Length, actual.Length); Assert.Equal(expected, actual); }