Exemplo n.º 1
0
        public void ReturnsZero_WhenTryingToReadMoreThanStreamLength(int maxBytesPerRead)
        {
            var bytes         = Encoding.ASCII.GetBytes("This is the stream content.");
            var networkStream = new NetworkStreamEmulator(new MemoryStream(bytes))
            {
                MaxBytesPerRead = maxBytesPerRead
            };
            var fixLengthInputStream = new FixLengthInputStream(networkStream, bytes.Length);

            var buff = new byte[bytes.Length + 1];

            while (fixLengthInputStream.NbRemainingBytesToRead > 0)
            {
                fixLengthInputStream.Read(buff);
            }

            Assert.Equal(0, fixLengthInputStream.Read(buff));
            Assert.Equal(0, fixLengthInputStream.NbRemainingBytesToRead);

            Assert.Equal(0, fixLengthInputStream.Read(new byte[500], 0, 500));
            Assert.Equal(0, fixLengthInputStream.NbRemainingBytesToRead);

            Assert.Equal(0, fixLengthInputStream.Read(new byte[1000], 0, 1000));
            Assert.Equal(0, fixLengthInputStream.NbRemainingBytesToRead);
        }
Exemplo n.º 2
0
        public void ReturnsZero_WhenCountIsZero()
        {
            var networkStream        = new NetworkStreamEmulator(new MemoryStream());
            var fixLengthInputStream = new FixLengthInputStream(networkStream, 5);

            const int count = 0;

            Assert.Equal(0, fixLengthInputStream.Read(new byte[50], 0, count));
        }
Exemplo n.º 3
0
        public void ThrowsStreamEndException(int nbMissingBytes, int maxBytesPerRead)
        {
            var bytes         = Encoding.ASCII.GetBytes("This is the stream content.");
            var networkStream = new NetworkStreamEmulator(new MemoryStream(bytes))
            {
                MaxBytesPerRead = maxBytesPerRead
            };
            var fixLengthInputStream = new FixLengthInputStream(networkStream, bytes.Length + nbMissingBytes);

            Assert.Throws <StreamEndException>(() =>
            {
                var buff = new byte[10];
                while (fixLengthInputStream.NbRemainingBytesToRead > 0)
                {
                    fixLengthInputStream.Read(buff);
                }
            });
        }