public void TestSeekCurrent()

in AdlsDotNetSDKUnitTest/SdkUnitTest.cs [714:772]


        public void TestSeekCurrent()
        {

            string path = $"{UnitTestDir}/testSeekCurrent.txt";
            int strLength = 24 * 1024 * 1024;
            string text1 = RandomString(strLength);
            int lengthToReadBeforeSeek = strLength / 8;
            byte[] textByte1 = Encoding.UTF8.GetBytes(text1);
            using (var ostream = _adlsClient.CreateFile(path, IfExists.Overwrite, ""))
            {
                ostream.Write(textByte1, 0, textByte1.Length);
            }
            string expectedOp = "";
            string actualOp = "";
            using (var istream = _adlsClient.GetReadStream(path))
            {
                byte[] buff = new byte[strLength];
                int totalBytes = 0, startByte = 0;
                int noBytes;
                int totalLengthToRead = lengthToReadBeforeSeek;
                do
                {
                    noBytes = istream.Read(buff, 0, totalLengthToRead);
                    actualOp += Encoding.UTF8.GetString(buff, 0, noBytes);
                    totalBytes += noBytes;
                    totalLengthToRead -= noBytes;
                } while (noBytes > 0 && totalLengthToRead > 0);
                expectedOp += text1.Substring(startByte, totalBytes);
                istream.Seek(lengthToReadBeforeSeek, SeekOrigin.Current);
                totalBytes += lengthToReadBeforeSeek;
                startByte = totalBytes;
                totalLengthToRead = lengthToReadBeforeSeek;
                do
                {
                    noBytes = istream.Read(buff, 0, totalLengthToRead);
                    actualOp += Encoding.UTF8.GetString(buff, 0, noBytes);
                    totalBytes += noBytes;
                    totalLengthToRead -= noBytes;
                } while (noBytes > 0 && totalLengthToRead > 0);
                expectedOp += text1.Substring(startByte, totalBytes - startByte);
                istream.Seek(lengthToReadBeforeSeek, SeekOrigin.Current);
                try
                {
                    istream.Seek(3 * strLength / 4, SeekOrigin.Current);
                    Assert.Fail("Trying to seek beyond the end of file so it should throw an exception");
                }
                catch (IOException)
                {
                }
                totalBytes += lengthToReadBeforeSeek;
                do
                {
                    noBytes = istream.Read(buff, 0, buff.Length);
                    actualOp += Encoding.UTF8.GetString(buff, 0, noBytes);
                } while (noBytes > 0);
                expectedOp += text1.Substring(totalBytes, text1.Length - totalBytes);
            }
            Assert.IsTrue(actualOp.Equals(expectedOp));
        }