Exemple #1
0
        public void GetByteRange_WhenBufferIsSmallerThanRequestedCount_Throws()
        {
            // Arrange
            var bytes = Enumerable.Range(0, 255).Select(i => (byte)i).ToArray();

            Write(bytes);
            var fileByteBuffer = new FileByteBuffer(_fileReference, 0, 255);

            // Act + Assert
            var buffer = new byte[10];

            Assert.Throws <ArgumentException>(() => fileByteBuffer.GetByteRange(0, 20, buffer));
        }
Exemple #2
0
        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();

            Write(bytes);
            var buffer   = new FileByteBuffer(_fileReference, 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);
        }