Exemplo n.º 1
0
        public void CopyTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile().FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            Assert.That(() => BackgroundCopyManager.Copy(srcFile, dstFile), Throws.Nothing);

            Assert.That(File.Exists(dstFile));
        }
Exemplo n.º 2
0
        public void CopyAsyncTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile().FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            using var cts = new CancellationTokenSource();

            Assert.That(() => BackgroundCopyManager.CopyAsync(srcFile, dstFile, cts.Token, null), Throws.Nothing);

            Assert.That(File.Exists(dstFile), Is.True);
        }
Exemplo n.º 3
0
        public void FileCollTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile().FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            using var job = BackgroundCopyManager.Jobs.Add(GetCurrentMethodName());

            Assert.That(() => job.Files.Add(srcFile, dstFile), Throws.Nothing);

            Assert.That(job.Files.Count, Is.EqualTo(1));

            Assert.That(job.Files.Count(), Is.EqualTo(1));

            Assert.That(job.Files.First().LocalFilePath, Is.EqualTo(dstFile));

            Assert.That(() => job.Cancel(), Throws.Nothing);
        }
Exemplo n.º 4
0
        public void CopyAsyncReportTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile().FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            using var cts = new CancellationTokenSource();

            var collection = new Collection <string>();

            var prog = new Progress <Tuple <BackgroundCopyJobState, byte> >(t => collection.Add($"{t.Item2}% : {t.Item1}"));


            Assert.That(() => BackgroundCopyManager.CopyAsync(srcFile, dstFile, cts.Token, prog), Throws.Nothing);

            Assert.That(File.Exists(dstFile), Is.True);

            Assert.That(collection.Count, Is.GreaterThan(0));

            TestContext.Write(string.Join("\r\n", collection));
        }