public void TestSeekBegin()

in AdlsDotNetSDKUnitTest/SdkUnitTest.cs [783:850]


        public void TestSeekBegin()
        {
            string path = $"{UnitTestDir}/testSeekBegin.txt";
            int strLength = 12 * 1024 * 1024;
            string text1 = RandomString(strLength);
            int readTill = strLength / 2;
            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, startBytes = 0;
                int noBytes;
                int totalLengthToRead = readTill - startBytes;
                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(startBytes, totalBytes - startBytes);
                istream.Seek(strLength / 4, SeekOrigin.Begin);
                startBytes = totalBytes = strLength / 4;
                totalLengthToRead = readTill - startBytes;
                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(startBytes, totalBytes - startBytes);
                istream.Seek(3 * strLength / 4, SeekOrigin.Begin);
                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)
                {
                }
                startBytes = totalBytes = 3 * strLength / 4;
                totalLengthToRead = 2 * readTill - startBytes;
                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(startBytes, totalBytes - startBytes);
                try
                {
                    istream.Seek(-1, SeekOrigin.Begin);
                    Assert.Fail("Trying to seek beyond the begining of file so it should throw an exception");
                }
                catch (IOException)
                {
                }
            }
            Assert.IsTrue(actualOp.Equals(expectedOp));
        }