Пример #1
0
        public void CanNotDelete_NonRecursively_NonEmptyDir()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

            // 1. create dir and file
            string dir  = dllPath.CombineAssert("testing");
            string file = dir.Combine("file");

            File.WriteAllText(file, "hello");

            // 2. test it
            using (var t = new FileTransaction("Can not delete non-empty directory"))
            {
                IDirectoryAdapter da = t;
                t.Begin();
                Assert.That(da.Delete(dir, false),
                            Is.False,
                            "Did not delete non-empty dir.");
                IFileAdapter fa = t;
                fa.Delete(file);

                Assert.That(da.Delete(dir, false),
                            "After deleting the file in the folder, the folder is also deleted.");

                t.Commit();
            }
        }
        protected override void DoExecute()
        {
            if (_directoryAdapter.Exists(_dstDirPath.Value))
            {
                RetryUtils.RetryOnException(
                    new[] { typeof(UnauthorizedAccessException) },
                    _DeleteDstDirRetriesCount,
                    _DeleteDstDirRetryDelay,
                    () =>
                {
                    _directoryAdapter.GetDirectories(_dstDirPath.Value)
                    .Where(x => !_excludedDirs.Any(s => x.EndsWith(s, StringComparison.CurrentCultureIgnoreCase)))
                    .ToList()
                    .ForEach(dirPath => _directoryAdapter.Delete(dirPath, true));

                    _directoryAdapter.GetFiles(_dstDirPath.Value)
                    .ToList()
                    .ForEach(_fileAdapter.Delete);
                });
            }
            else
            {
                _directoryAdapter.CreateDirectory(_dstDirPath.Value);
            }
        }
Пример #3
0
        public void CanDelete_NonRecursively_EmptyDir()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

            // 1. create dir
            string dir = dllPath.CombineAssert("testing");

            // 2. test it
            using (var t = new FileTransaction("Can delete empty directory"))
            {
                IDirectoryAdapter da = t;
                t.Begin();
                Assert.That(da.Delete(dir, false), "Successfully deleted.");
                t.Commit();
            }
        }