Пример #1
0
        public void TestInUseMove()
        {
            const Boolean recursive = true;

#if SHORT_SOURCE
            var tempPathFilename1 = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), System.IO.Path.GetRandomFileName());
            System.IO.Directory.CreateDirectory(tempPathFilename1);
            Assert.IsTrue(System.IO.Directory.Exists(Path.GetFullPath(tempPathFilename1)));
            var tempPathFilename2 = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), System.IO.Path.GetRandomFileName());
            System.IO.Directory.CreateDirectory(tempPathFilename2);
            Assert.IsTrue(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename2)));
            try
            {
                using (
                    var writer = System.IO.File.CreateText(System.IO.Path.Combine(tempPathFilename2, "TestInUseMove")))
                {
                    string destinationPath =
                        System.IO.Path.GetFullPath(System.IO.Path.Combine(tempPathFilename1, System.IO.Path.GetFileName(tempPathFilename2)));
                    System.IO.Directory.Move(tempPathFilename2, destinationPath);
                    Assert.IsTrue(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename1)));
                    Assert.IsFalse(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename2)));
                    Assert.IsTrue(System.IO.Directory.Exists(destinationPath));
                }
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                Directory.Delete(tempPathFilename1, recursive);
                Directory.Delete(tempPathFilename2, recursive);
            }
#endif
            var tempLongPathFilename1 = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName());
            tempLongPathFilename1.CreateDirectory();
            Assert.IsTrue(tempLongPathFilename1.GetFullPath().Exists());
            var tempLongPathFilename2 = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName());
            tempLongPathFilename2.CreateDirectory();
            Assert.IsTrue(tempLongPathFilename2.GetFullPath().Exists());

            try {
                using (var writer = File.CreateText(tempLongPathFilename2.Combine("TestInUseMove"))) {
                    var destinationPath = tempLongPathFilename1.Combine(tempLongPathFilename2.GetFileName()).GetFullPath();
                    Assert.Throws <IOException>(() => Directory.Move(tempLongPathFilename2, destinationPath));
                }
            }
            finally {
                Directory.Delete(tempLongPathFilename1, recursive);
                Directory.Delete(tempLongPathFilename2, recursive);
            }
        }
Пример #2
0
        public void TestMove()
        {
            var tempLongPathFilename1 = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName());

            tempLongPathFilename1.CreateDirectory();
            Assert.IsTrue(tempLongPathFilename1.GetFullPath().Exists());
            var tempLongPathFilename2 = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName());

            tempLongPathFilename2.CreateDirectory();
            Assert.IsTrue(tempLongPathFilename2.GetFullPath().Exists());

            var destinationPath = tempLongPathFilename1.Combine(tempLongPathFilename2.GetFileName()).GetFullPath();

            Directory.Move(tempLongPathFilename2, destinationPath);
            Assert.IsTrue(tempLongPathFilename1.GetFullPath().Exists());
            Assert.IsFalse(tempLongPathFilename2.GetFullPath().Exists());
            Assert.IsTrue(destinationPath.Exists());

            const Boolean recursive = true;

            Directory.Delete(tempLongPathFilename1, recursive);
            Directory.Delete(tempLongPathFilename2, recursive);
        }