예제 #1
0
        public void SeekOrigin_PositivePastEnd_Throws()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);

            Should.Throw <ArgumentException> (() => stream.Seek(11, SeekOrigin.Begin));
        }
예제 #2
0
        public void Seek_SeekToBeginningOfEmptyStream_SetsPosition()
        {
            var stream = new HttpResponseStream();

            stream.Seek(0, SeekOrigin.Begin);

            var position = stream.Position;

            Assert.AreEqual(0, position);
        }
예제 #3
0
        public void Seek_FromEnd_SetsPosition()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);
            stream.Seek(-3, SeekOrigin.End);

            long pos = stream.Position;

            Assert.AreEqual(7, pos);
        }
예제 #4
0
        public void Read_PastEndOfStream_ReturnsAmountRead()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);

            stream.Seek (-1, SeekOrigin.End);
            int amount_read = stream.Read (buffer, 0, 2);

            Assert.AreEqual (1, amount_read);
        }
예제 #5
0
        public void Read_PastEndOfStream_ReturnsAmountRead()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);

            stream.Seek(-1, SeekOrigin.End);
            int amount_read = stream.Read(buffer, 0, 2);

            Assert.AreEqual(1, amount_read);
        }
예제 #6
0
        public void Read_SingleBuffer_UpdatesPosition()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);
            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(buffer, 0, 5);

            long position = stream.Position;

            Assert.AreEqual(5, position);
        }
예제 #7
0
        public void Read_ReadLastItem_UpdatesPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);

            stream.Seek (-1, SeekOrigin.End);
            stream.Read (buffer, 0, 1);

            long position = stream.Position;
            Assert.AreEqual (10, position);
        }
예제 #8
0
        public void Read_ReadLastItem_UpdatesPosition()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);

            stream.Seek(-1, SeekOrigin.End);
            stream.Read(buffer, 0, 1);

            long position = stream.Position;

            Assert.AreEqual(10, position);
        }
예제 #9
0
        public void Seek_FromCurrentBackwards_SetsPosition()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);
            stream.Write(buffer, 0, 10);

            stream.Seek(-5, SeekOrigin.Current);

            long pos = stream.Position;

            Assert.AreEqual(15, pos);
        }
예제 #10
0
        public void Seek_FromBeginningLastIndexOfSegment_SetsPosition()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);
            stream.Write(buffer, 0, 10);

            stream.Seek(10, SeekOrigin.Begin);

            long pos = stream.Position;

            Assert.AreEqual(10, pos);
        }
예제 #11
0
        public void Seek_FromEndMultipleBuffersAcrossBoundries_SetsPosition()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);
            stream.Write(buffer, 0, 10);
            stream.Write(buffer, 0, 10);
            stream.Seek(-25, SeekOrigin.End);

            long pos = stream.Position;

            Assert.AreEqual(5, pos);
        }
예제 #12
0
        public void Read_MultipleBuffers_UpdatesPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);

            stream.Seek (15, SeekOrigin.Begin);
            stream.Read (buffer, 0, 5);

            long position = stream.Position;
            Assert.AreEqual (20, position);
        }
예제 #13
0
        public void Write_SeekedBackInLastSegment_SetsPosition()
        {
            var stream = new HttpResponseStream();
            var buffer = new byte [10];

            stream.Write(buffer, 0, 10);
            stream.Write(buffer, 0, 10);

            stream.Seek(-5, SeekOrigin.Current);
            stream.Write(buffer, 0, 10);

            long pos = stream.Position;

            Assert.AreEqual(25, pos);
        }
예제 #14
0
        public void Write_InFirstBufferOfTwoBufferStream_SetsCorrectLength()
        {
            var stream       = new HttpResponseStream();
            var write_buffer = new byte [5];

            stream.Write(write_buffer, 0, 5);
            stream.Write(write_buffer, 0, 5);
            stream.Seek(-6, SeekOrigin.End);

            stream.Write(write_buffer, 0, 5);

            var length = stream.Length;

            Assert.AreEqual(10, length);
        }
예제 #15
0
        public void Write_AcrossEntireMiddleBufferOfThreeBufferStream_SetsCorrectLength()
        {
            var stream        = new HttpResponseStream();
            var write_buffer  = new byte [5];
            var write_buffer2 = new byte [6];

            stream.Write(write_buffer, 0, 5);
            stream.Write(write_buffer, 0, 5);
            stream.Write(write_buffer, 0, 5);
            stream.Seek(2, SeekOrigin.Begin);

            stream.Write(write_buffer2, 0, 6);

            var length = stream.Length;

            Assert.AreEqual(15, length);
        }
예제 #16
0
        public void Read_SingleBuffer_CorrectData()
        {
            var stream       = new HttpResponseStream();
            var write_buffer = new byte [3];
            var read_buffer  = new byte [1];

            write_buffer [2] = 0xFA;

            stream.Write(write_buffer, 0, 3);

            stream.Seek(-1, SeekOrigin.End);
            stream.Read(read_buffer, 0, 1);

            byte read_byte = read_buffer [0];

            Assert.AreEqual(0xFA, read_byte);
        }
예제 #17
0
        public void Write_SeekedBackPastLastSegmentWriteOverAll_SetsPosition()
        {
            var stream     = new HttpResponseStream();
            var buffer     = new byte [10];
            var buffer_big = new byte [25];

            stream.Write(buffer, 0, 10);
            stream.Write(buffer, 0, 10);

            stream.Seek(-15, SeekOrigin.Current);
            Assert.AreEqual(5, stream.Position);

            stream.Write(buffer_big, 0, 25);

            long pos = stream.Position;

            Assert.AreEqual(30, pos);
        }
예제 #18
0
        public void Read_MultipleBuffers_CorrectData()
        {
            var stream = new HttpResponseStream ();
            var write_buffer1 = new byte [3];
            var write_buffer2 = new byte [3];
            var read_buffer = new byte [6];

            stream.Write (write_buffer1, 0, 3);

            write_buffer2 [0] = 0xFA;
            stream.Write (write_buffer2, 0, 3);

            stream.Seek (0, SeekOrigin.Begin);
            stream.Read (read_buffer, 0, 6);

            byte read_byte = read_buffer [3];
            Assert.AreEqual (0xFA, read_byte);
        }
예제 #19
0
        public void Read_MultipleBuffers_CorrectData()
        {
            var stream        = new HttpResponseStream();
            var write_buffer1 = new byte [3];
            var write_buffer2 = new byte [3];
            var read_buffer   = new byte [6];

            stream.Write(write_buffer1, 0, 3);

            write_buffer2 [0] = 0xFA;
            stream.Write(write_buffer2, 0, 3);

            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(read_buffer, 0, 6);

            byte read_byte = read_buffer [3];

            Assert.AreEqual(0xFA, read_byte);
        }
예제 #20
0
        public void Write_SeekedBackPastLastSegmentWriteOverAll_SetsPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];
            var buffer_big = new byte [25];

            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);

            stream.Seek (-15, SeekOrigin.Current);
                        Assert.AreEqual (5, stream.Position);

            stream.Write (buffer_big, 0, 25);

            long pos = stream.Position;
            Assert.AreEqual (30, pos);
        }
예제 #21
0
        public void Write_SeekedBackInLastSegment_SetsPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);

            stream.Seek (-5, SeekOrigin.Current);
            stream.Write (buffer, 0, 10);

            long pos = stream.Position;
            Assert.AreEqual (25, pos);
        }
예제 #22
0
        public void Write_InFirstBufferOfTwoBufferStream_SetsCorrectLength()
        {
            var stream = new HttpResponseStream ();
            var write_buffer = new byte [5];

            stream.Write (write_buffer, 0, 5);
            stream.Write (write_buffer, 0, 5);
            stream.Seek (-6, SeekOrigin.End);

            stream.Write (write_buffer, 0, 5);

            var length = stream.Length;
            Assert.AreEqual (10, length);
        }
예제 #23
0
        public void Write_AcrossEntireMiddleBufferOfThreeBufferStream_SetsCorrectLength()
        {
            var stream = new HttpResponseStream ();
            var write_buffer = new byte [5];
            var write_buffer2 = new byte [6];

            stream.Write (write_buffer, 0, 5);
            stream.Write (write_buffer, 0, 5);
            stream.Write (write_buffer, 0, 5);
            stream.Seek (2, SeekOrigin.Begin);

            stream.Write (write_buffer2, 0, 6);

            var length = stream.Length;
            Assert.AreEqual (15, length);
        }
예제 #24
0
        public void Seek_SeekToBeginningOfEmptyStream_SetsPosition()
        {
            var stream = new HttpResponseStream ();

            stream.Seek (0, SeekOrigin.Begin);

            var position = stream.Position;
            Assert.AreEqual (0, position);
        }
예제 #25
0
        public void Seek_FromEnd_SetsPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);
            stream.Seek (-3, SeekOrigin.End);

            long pos = stream.Position;
            Assert.AreEqual (7, pos);
        }
예제 #26
0
        public void Seek_FromEndMultipleBuffersAcrossBoundries_SetsPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);
            stream.Seek (-25, SeekOrigin.End);

            long pos = stream.Position;
            Assert.AreEqual (5, pos);
        }
예제 #27
0
        public void Seek_FromCurrentBackwards_SetsPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);

            stream.Seek (-5, SeekOrigin.Current);

            long pos = stream.Position;
            Assert.AreEqual (15, pos);
        }
예제 #28
0
        public void Seek_FromBeginningMultipleSegments_SetsPosition()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);
            stream.Write (buffer, 0, 10);

            stream.Seek (25, SeekOrigin.Begin);

            long pos = stream.Position;
            Assert.AreEqual (25, pos);
        }
예제 #29
0
        public void SeekOrigin_PositivePastEnd_Throws()
        {
            var stream = new HttpResponseStream ();
            var buffer = new byte [10];

            stream.Write (buffer, 0, 10);

            Should.Throw<ArgumentException> (() => stream.Seek (11, SeekOrigin.Begin));
        }
예제 #30
0
        public void Read_SingleBuffer_CorrectData()
        {
            var stream = new HttpResponseStream ();
            var write_buffer = new byte [3];
            var read_buffer = new byte [1];

            write_buffer [2] = 0xFA;

            stream.Write (write_buffer, 0, 3);

            stream.Seek (-1, SeekOrigin.End);
            stream.Read (read_buffer, 0, 1);

            byte read_byte = read_buffer [0];
            Assert.AreEqual (0xFA, read_byte);
        }
        public void SeekThrows()
        {
            var stream = new HttpResponseStream(Mock.Of <IHttpBodyControlFeature>(), new MockHttpResponseControl());

            Assert.Throws <NotSupportedException>(() => stream.Seek(0, SeekOrigin.Begin));
        }