Exemple #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));
        }
Exemple #2
0
        public void Seek_SeekToBeginningOfEmptyStream_SetsPosition()
        {
            var stream = new HttpResponseStream();

            stream.Seek(0, SeekOrigin.Begin);

            var position = stream.Position;

            Assert.AreEqual(0, position);
        }
Exemple #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);
        }
        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);
        }
Exemple #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);
        }
Exemple #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);
        }
        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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
        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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
        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);
        }
Exemple #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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        public void Seek_SeekToBeginningOfEmptyStream_SetsPosition()
        {
            var stream = new HttpResponseStream ();

            stream.Seek (0, SeekOrigin.Begin);

            var position = stream.Position;
            Assert.AreEqual (0, position);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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));
        }
        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));
        }