예제 #1
0
        protected void CreateArchive(IArchiver archiverBasic, List <FileInArchive> listFiles)
        {
            var modifiedList = listFiles.GetRange(1, listFiles.Count - 1);

            // Test the cancellation.
            _cancelSource = new CancellationTokenSource();
            archiverBasic.SetCancellationToken(_cancelSource.Token);
            var list = modifiedList;

            Assert.ThrowsException <OperationCanceledException>(() => archiverBasic.ArchiveFileSet(list));
            _cancelSource = null;
            archiverBasic.SetCancellationToken(null);

            CleanupArchives(listFiles);

            // try to add a non existing file
            modifiedList.Add(new FileInArchive {
                ArchivePath    = listFiles.First().ArchivePath,
                ExtractionPath = listFiles.First().ExtractionPath,
                PathInArchive  = "random.name"
            });

            Assert.AreEqual(modifiedList.Count - 1, archiverBasic.ArchiveFileSet(modifiedList));
            Assert.AreEqual(modifiedList.Count - 1, modifiedList.Count(f => f.Processed), "Wrong number of processed files.");

            // test the update of archives
            modifiedList = listFiles.GetRange(0, 1);
            Assert.AreEqual(modifiedList.Count, archiverBasic.ArchiveFileSet(modifiedList));

            foreach (var archive in listFiles.GroupBy(f => f.ArchivePath))
            {
                if (Directory.Exists(Path.GetDirectoryName(archive.Key)))
                {
                    Assert.IsTrue(File.Exists(archive.Key) || Directory.Exists(archive.Key), $"The archive does not exist : {archive}");
                }
            }

            // check progress
            Assert.IsTrue(_hasReceivedGlobalProgression, "Should have received a progress event.");
            Assert.AreEqual(listFiles.Count, listFiles.Count(f => f.Processed), "Wrong number of processed files.");
        }