public void GetByteRange_WhenBufferIsSmallerThanRequestedCount_Throws() { // Arrange var bytes = Enumerable.Range(0, 255).Select(i => (byte)i).ToArray(); using var ms = new MemoryStream(bytes); var streamByteBuffer = new StreamByteBuffer(ms, 0, 255); // Act + Assert var buffer = new byte[10]; Assert.Throws <ArgumentException>(() => streamByteBuffer.GetByteRange(0, 20, buffer)); }
public void GetByteRange_CompareWithInitializer_ExactMatch(int ctorOffset, int ctorCount, int byteRangeOffset, int byteRangeCount) { // Arrange var bytes = Enumerable.Range(0, 255).Select(i => (byte)i).ToArray(); using var ms = new MemoryStream(bytes); var buffer = new StreamByteBuffer(ms, ctorOffset, ctorCount); var expected = new ArraySegment <byte>(bytes, ctorOffset + byteRangeOffset, Math.Min(ctorCount, byteRangeCount)); // Act var actual = new byte[Math.Min(ctorCount, byteRangeCount)]; buffer.GetByteRange(byteRangeOffset, byteRangeCount, actual); // Assert Assert.Equal(expected.Count, actual.Length); Assert.Equal(expected, actual); }