bug.ReadBeyondEndTest C# (CSharp) Method

ReadBeyondEndTest() public static method

public static ReadBeyondEndTest ( Stream, s ) : bool
s Stream,
return bool
    public static bool ReadBeyondEndTest(Stream s)
    {
        Console.WriteLine("Read Beyond End test on "+s.GetType().Name);
        byte[] bytes = new byte[10];
        for(int i=0; i<bytes.Length; i++)
            bytes[i] = (byte) i;
        s.Seek(5, SeekOrigin.End);
        if (s.Position != s.Length + 5)
        {
            iCountErrors++;
            throw new Exception("Position is incorrect!  Seek(5, SeekOrigin.End) should leave us at s.Length + 5, but got: "+s.Position);
        }
        int numRead = s.Read(bytes, 0, bytes.Length);
        if (numRead != 0)
        {
            iCountErrors++ ;
            throw new Exception("Reading from past end of stream is broken!  Expected 0, got: "+numRead);
        }
        for(int i=0; i<bytes.Length; i++)
        {
            if (bytes[i] != (byte) i)
            {
                iCountErrors++ ;
                throw new Exception("Error in byte[] - Read overwrote it!  pos: "+i+"  got: "+bytes[i]);
            }
        }
        numRead = s.ReadByte();
        if (numRead != -1)
        {
            iCountErrors++ ;
            throw new Exception("ReadByte didn't return -1!  got: "+numRead);
        }
        IAsyncResult ar = s.BeginRead(bytes, 0, bytes.Length, null, null);
        numRead = s.EndRead(ar);
        if (numRead != 0)
        {
            iCountErrors++ ;
            throw new Exception("Reading from past end of stream with BeginRead is broken!  Expected 0, got: "+numRead);
        }
        for(int i=0; i<bytes.Length; i++)
            if (bytes[i] != (byte) i)
            {
                iCountErrors++ ;
                throw new Exception("Error in byte[] - BeginRead overwrote it!  pos: "+i+"  got: "+bytes[i]);
            }
        return true;
    }
}