Пример #1
0
        public void Length_IsMovedByReservedBytesForSize()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act and assert
            Assert.Equal(stream.Position, sizeof(int));
        }
Пример #2
0
        public void Seek_ThrowsEndOfStream_WhenValueIsToBig()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act and assert
            Assert.Throws <EndOfStreamException>(() => stream.Seek(int.MaxValue, SeekOrigin.Begin));
        }
Пример #3
0
        public void Position_IsMovedAfterWriting()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act and assert
            Assert.Equal(stream.Position, sizeof(int));
        }
Пример #4
0
        public void IsClean_IsTrue_WhenIsNew()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act
            bool isClean = stream.IsClean;

            // Assert
            Assert.True(isClean);
        }
Пример #5
0
        public void Flush_DoesNotThrow()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act
            var ex = Record.Exception(() => stream.Flush());

            // Assert
            Assert.Null(ex);
        }
Пример #6
0
        public void CanWrite_IsTrue()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act
            bool value = stream.CanWrite;

            // Assert
            Assert.True(value);
        }
Пример #7
0
        public void SetLength_ThrowsNotSupportedException()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act
            var ex = Record.Exception(() => stream.SetLength(0));

            // Assert
            Assert.NotNull(ex);
        }
Пример #8
0
        public void CanSeek_IsFalse()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act
            bool value = stream.CanSeek;

            // Assert
            Assert.False(value);
        }
Пример #9
0
        public void Rawbytes_ReturnsCollection()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act
            byte[] bytes = stream.RawBytes;

            // Assert
            Assert.NotNull(bytes);
            Assert.NotEmpty(bytes);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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));
        }
Пример #15
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);
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
0
        public void Dispose_DoesNotThrow()
        {
            // Arrange
            var stream = new BufferedStream();

            // Act
            stream.Flush();

            // Assert
            int sum = 0;

            foreach (byte b in stream.RawBytes)
            {
                sum += b;
            }

            Assert.Equal(sum, 0);
        }