public void TestRenameFileDestinationExist()

in AdlsDotNetSDKUnitTest/SdkUnitTest.cs [1224:1277]


        public void TestRenameFileDestinationExist(bool overwrite)
        {
            string srcFilePath = $"{UnitTestDir}/testRenameSource6" + overwrite + ".txt";
            string destFilePath = $"{UnitTestDir}/testRenameDest6" + overwrite + ".txt";
            int strLength = 300;
            string srcFileText = RandomString(strLength);
            byte[] srcByte = Encoding.UTF8.GetBytes(srcFileText);
            using (var ostream = _adlsClient.CreateFile(srcFilePath, IfExists.Overwrite, ""))
            {
                ostream.Write(srcByte, 0, srcByte.Length);
            }
            string destFileText = RandomString(strLength);
            byte[] destByte = Encoding.UTF8.GetBytes(destFileText);
            using (var ostream = _adlsClient.CreateFile(destFilePath, IfExists.Overwrite, ""))
            {
                ostream.Write(destByte, 0, destByte.Length);
            }
            bool result = _adlsClient.Rename(srcFilePath, destFilePath, overwrite);
            if (overwrite)
            {
                Assert.IsTrue(result);
            }
            else
            {
                Assert.IsFalse(result);
            }
            try
            {
                _adlsClient.GetDirectoryEntry(srcFilePath);
                if (overwrite)
                {
                    Assert.Fail("Src file should not exist so Getfilestatus should throw an exception");
                }
            }
            catch (IOException)
            {
                if (!overwrite)
                {
                    Assert.Fail("Src file should exist so getfilestatus should not throw an exception");
                }
            }
            string output = "";
            using (var istream = _adlsClient.GetReadStream(destFilePath))
            {
                int noOfBytes;
                byte[] buffer = new byte[2 * 1024 * 1024];
                do
                {
                    noOfBytes = istream.Read(buffer, 0, buffer.Length);
                    output += Encoding.UTF8.GetString(buffer, 0, noOfBytes);
                } while (noOfBytes > 0);
            }
            Assert.IsTrue(overwrite ? output.Equals(srcFileText) : output.Equals(destFileText));
        }