Beispiel #1
0
            public void CancellationTokenOverwrite_ExceptionThrown()
            {
                var contents = Enumerable.Repeat("This is a test line.", 300000).ToList();
                var path     = Path.Combine(copyTestFolder, nameof(CancellationTokenOverwrite_ExceptionThrown));

                Directory.CreateDirectory(copyTestFolder);
                File.WriteAllLines(path, contents);

                var copyPath = Path.Combine(copyTestFolder, $"{nameof(CancellationTokenOverwrite_ExceptionThrown)}_Copy");

                if (!File.Exists(copyPath))
                {
                    File.Create(copyPath).Dispose();
                }

                var tokenSource = new CancellationTokenSource();

                Assert.ThrowsAsync <TaskCanceledException>(async() =>
                {
                    var task = AsyncFile.CopyAsync(path, copyPath, true, tokenSource.Token);
                    tokenSource.Cancel();
                    await task;
                });

                var result = File.ReadAllLines(copyPath);

                Assert.IsTrue(contents.Count > result.Length);
            }
Beispiel #2
0
        public static async Task CopyAsync(string sourceFileName, string destFileName, bool overwrite, CancellationToken cancellationToken)
        {
            string dir = Path.GetDirectoryName(destFileName);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            await AsyncFile.CopyAsync(sourceFileName, destFileName, overwrite, cancellationToken);
        }
Beispiel #3
0
        public static async Task CopyAsync(string sourceFileName, string destFileName)
        {
            string dir = Path.GetDirectoryName(destFileName);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            await AsyncFile.CopyAsync(sourceFileName, destFileName);
        }
Beispiel #4
0
            public async Task Default_FileCopied()
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(copyTestFolder, nameof(Default_FileCopied));


                Directory.CreateDirectory(copyTestFolder);
                File.WriteAllLines(path, contents);

                var copyPath = Path.Combine(copyTestFolder, $"{nameof(Default_FileCopied)}_Copy");

                File.Delete(copyPath);

                await AsyncFile.CopyAsync(path, copyPath);

                var result = File.ReadAllLines(copyPath);

                CollectionAssert.AreEqual(contents, result);
            }
Beispiel #5
0
            public async Task Overwrite_FileCopied()
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(copyTestFolder, nameof(Overwrite_FileCopied));

                Directory.CreateDirectory(copyTestFolder);
                File.WriteAllLines(path, contents);

                var copyPath = Path.Combine(copyTestFolder, $"{nameof(Overwrite_FileCopied)}_Copy");

                if (!File.Exists(copyPath))
                {
                    File.Create(copyPath).Dispose();
                }

                await AsyncFile.CopyAsync(path, copyPath, true);

                var result = File.ReadAllLines(copyPath);

                CollectionAssert.AreEqual(contents, result);
            }