Example #1
0
        public void IsClean_IsFalse_WhenDataIsWritten()
        {
            // Arrange
            var stream = new BufferedStream();

            byte[] data = new byte[1024];
            stream.Write(data, 0, data.Length);

            // Act
            bool isClean = stream.IsClean;

            // Assert
            Assert.False(isClean);
        }
Example #2
0
        public void Position_IsMovedByReservedBytesForSize()
        {
            // Arrange
            var stream = new BufferedStream();
            int length = (int)stream.Length;

            byte[] data = new byte[1024];

            // Act
            stream.Write(data, 0, data.Length);

            // Assert
            Assert.Equal(stream.Length, length + data.Length);
        }
Example #3
0
        public void Length_IsMovedAfterWriting()
        {
            // Arrange
            var stream   = new BufferedStream();
            int position = (int)stream.Position;

            byte[] data = new byte[1024];

            // Act
            stream.Write(data, 0, data.Length);

            // Assert
            Assert.Equal(stream.Position, position + data.Length);
        }
Example #4
0
        public void Seek_Begin_ChangesPosition()
        {
            // Arrange
            var       stream       = new BufferedStream();
            long      initPosition = stream.Position;
            const int toMove       = 2;
            var       data         = new byte[1024];

            // Act
            stream.Write(data, 0, data.Length);
            stream.Seek(toMove, SeekOrigin.Begin);

            // Act and assert
            Assert.Equal(stream.Position, initPosition + toMove);
        }
Example #5
0
        public void Read_ReadsDataFromStream_WhenCountIsBigger()
        {
            // Arrange
            var stream = new BufferedStream();

            byte[] data = new byte[1024];
            new Random().NextBytes(data);

            // Act
            stream.Write(data, 0, data.Length);
            stream.Seek(0, SeekOrigin.Begin);
            byte[] receivedBytes = new byte[data.Length + 1];

            // Assert
            Assert.Throws <EndOfStreamException>(() => stream.Read(receivedBytes, 0, receivedBytes.Length));
        }
Example #6
0
        public void Seek_Current_ChangesPosition()
        {
            // Arrange
            var  stream = new BufferedStream();
            var  data   = new byte[1024];
            long toMove = -2;

            // Act
            stream.Write(data, 0, data.Length);
            long position = stream.Position;

            stream.Seek(toMove, SeekOrigin.Current);

            // Act and assert
            Assert.Equal(stream.Position, position + toMove);
        }
Example #7
0
        public void Read_ReadsDataFromStream_WhenCountIsSmaller()
        {
            // Arrange
            var stream = new BufferedStream();

            byte[] data = new byte[1024];
            new Random().NextBytes(data);

            // Act
            stream.Write(data, 0, data.Length);
            stream.Seek(0, SeekOrigin.Begin);
            byte[] receivedBytes = new byte[data.Length - 1];
            stream.Read(receivedBytes, 0, receivedBytes.Length);

            // Assert
            Assert.Equal(data.Take(receivedBytes.Length), receivedBytes);
        }
Example #8
0
        public void Clean_ResetsPositions()
        {
            // Arrange
            var stream   = new BufferedStream();
            int length   = (int)stream.Length;
            int position = (int)stream.Position;

            byte[] data = new byte[1024];
            stream.Write(data, 0, data.Length);

            // Act
            stream.Clean();

            // Assert
            Assert.Equal(stream.Position, position);
            Assert.Equal(stream.Length, length);
        }