Exemplo n.º 1
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));
        }
Exemplo n.º 2
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);
        }