Example #1
0
 protected void ListArchive(ICabManager cabManager, List <FileInCab> listFiles)
 {
     foreach (var groupedTheoreticalFiles in listFiles.GroupBy(f => f.CabPath))
     {
         var actualFiles = cabManager.ListFiles(groupedTheoreticalFiles.Key).ToList();
         foreach (var theoreticalFile in groupedTheoreticalFiles)
         {
             Assert.IsTrue(actualFiles.ToList().Exists(f => f.RelativePathInCab.Replace("/", "\\").Equals(theoreticalFile.RelativePathInCab)), $"Can't find file in list : {theoreticalFile.RelativePathInCab}");
         }
         Assert.AreEqual(groupedTheoreticalFiles.Count(), actualFiles.Count, $"Wrong number of files listed : {groupedTheoreticalFiles.Count()}!={actualFiles.Count}");
     }
 }
Example #2
0
        protected void CreateArchive(ICabManager archiver, List <FileInCab> listFiles)
        {
            archiver.OnProgress += ArchiverOnOnProgress;

            _nbFileProcessed   = 0;
            _nbArchiveFinished = 0;

            var modifiedList = listFiles.GetRange(1, listFiles.Count - 1);

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

            Assert.ThrowsException <OperationCanceledException>(() => archiver.PackFileSet(list));
            Assert.IsTrue(_nbArchiveFinished == 0, "Nothing was done again.");
            _nbFileProcessed = 0;
            _cancelSource    = null;
            archiver.SetCancellationToken(null);

            _nbFileProcessed = 0;
            CleanupArchives(listFiles);

            // try to add a non existing file
            modifiedList.Add(new FileInCab {
                CabPath           = listFiles.First().CabPath,
                ExtractionPath    = listFiles.First().ExtractionPath,
                RelativePathInCab = "random.name"
            });
            Assert.AreEqual(modifiedList.Count - 1, archiver.PackFileSet(modifiedList));
            Assert.AreEqual(modifiedList.Count - 1, modifiedList.Count(f => f.Processed));

            // test the update of archives
            modifiedList = listFiles.GetRange(0, 1);
            Assert.AreEqual(modifiedList.Count, archiver.PackFileSet(modifiedList));
            Assert.AreEqual(modifiedList.Count, modifiedList.Count(f => f.Processed));

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

            archiver.OnProgress -= ArchiverOnOnProgress;

            // check progress
            Assert.IsTrue(_hasReceivedGlobalProgression, "Should have received a progress event.");
            Assert.AreEqual(listFiles.Count, _nbFileProcessed, "Problem in the progress event");
            Assert.AreEqual(listFiles.GroupBy(f => f.CabPath).Count() + 1, _nbArchiveFinished, "Problem in the progress event, number of archives");
        }
Example #3
0
        protected void MoveInArchives(ICabManager archiver, List <FileInCab> listFiles)
        {
            archiver.OnProgress += ArchiverOnOnProgress;
            _nbFileProcessed     = 0;
            _nbArchiveFinished   = 0;


            var modifiedList = listFiles.ToList();

            modifiedList.Add(new FileInCab {
                CabPath           = listFiles.First().CabPath,
                ExtractionPath    = listFiles.First().ExtractionPath,
                RelativePathInCab = "random.name"
            });
            modifiedList.ForEach(f => f.NewRelativePathInCab = $"{f.RelativePathInCab}_move");

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

            Assert.ThrowsException <OperationCanceledException>(() => archiver.MoveFileSet(list));
            Assert.IsTrue(_nbArchiveFinished == 0, "Nothing was done again.");
            _nbFileProcessed = 0;
            _cancelSource    = null;
            archiver.SetCancellationToken(null);

            Assert.AreEqual(modifiedList.Count - 1, archiver.MoveFileSet(modifiedList));
            Assert.AreEqual(modifiedList.Count - 1, modifiedList.Count(f => f.Processed));

            archiver.OnProgress -= ArchiverOnOnProgress;

            // check progress
            Assert.IsTrue(_hasReceivedGlobalProgression, "Should have received a progress event.");
            Assert.AreEqual(listFiles.Count, _nbFileProcessed, "Problem in the progress event");
            Assert.AreEqual(listFiles.GroupBy(f => f.CabPath).Count(), _nbArchiveFinished, "Problem in the progress event, number of archives");

            // move them back
            modifiedList.ForEach(f => {
                f.RelativePathInCab    = f.NewRelativePathInCab;
                f.NewRelativePathInCab = f.NewRelativePathInCab.Substring(0, f.NewRelativePathInCab.Length - 5);
            });

            Assert.AreEqual(modifiedList.Count - 1, archiver.MoveFileSet(modifiedList));
            Assert.AreEqual(modifiedList.Count - 1, modifiedList.Count(f => f.Processed));

            modifiedList.ForEach(f => {
                f.RelativePathInCab = f.NewRelativePathInCab;
            });
        }
Example #4
0
        protected void DeleteFilesInArchive(ICabManager archiver, List <FileInCab> listFiles)
        {
            archiver.OnProgress += ArchiverOnOnProgress;
            _nbFileProcessed     = 0;
            _nbArchiveFinished   = 0;

            var modifiedList = listFiles.ToList();

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

            Assert.ThrowsException <OperationCanceledException>(() => archiver.DeleteFileSet(list));
            Assert.IsTrue(_nbArchiveFinished == 0, "Nothing was done again.");
            _nbFileProcessed = 0;
            _cancelSource    = null;
            archiver.SetCancellationToken(null);

            // try to delete a non existing file
            modifiedList.Add(new FileInCab {
                CabPath           = listFiles.First().CabPath,
                ExtractionPath    = listFiles.First().ExtractionPath,
                RelativePathInCab = "random.name"
            });
            Assert.AreEqual(modifiedList.Count - 1, archiver.DeleteFileSet(modifiedList));
            Assert.AreEqual(modifiedList.Count - 1, modifiedList.Count(f => f.Processed));

            foreach (var groupedFiles in listFiles.GroupBy(f => f.CabPath))
            {
                var files = archiver.ListFiles(groupedFiles.Key);
                Assert.AreEqual(0, files.Count(), $"The archive is not empty : {groupedFiles.Key}");
            }

            archiver.OnProgress -= ArchiverOnOnProgress;

            // check progress
            Assert.IsTrue(_hasReceivedGlobalProgression, "Should have received a progress event.");
            Assert.AreEqual(listFiles.Count, _nbFileProcessed, "Problem in the progress event");
            Assert.AreEqual(listFiles.GroupBy(f => f.CabPath).Count(), _nbArchiveFinished, "Problem in the progress event, number of archives");
        }
Example #5
0
        protected void Extract(ICabManager archiver, List <FileInCab> listFiles)
        {
            archiver.OnProgress += ArchiverOnOnProgress;
            _nbFileProcessed     = 0;
            _nbArchiveFinished   = 0;

            var modifiedList = listFiles.ToList();

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

            Assert.ThrowsException <OperationCanceledException>(() => archiver.ExtractFileSet(list));
            Assert.IsTrue(_nbArchiveFinished == 0, "Nothing was done again.");
            _nbFileProcessed = 0;
            _cancelSource    = null;
            archiver.SetCancellationToken(null);

            // try to extract a non existing file
            modifiedList.Add(new FileInCab {
                CabPath           = listFiles.First().CabPath,
                ExtractionPath    = listFiles.First().ExtractionPath,
                RelativePathInCab = "random.name"
            });
            Assert.AreEqual(modifiedList.Count - 1, archiver.ExtractFileSet(modifiedList));
            Assert.AreEqual(modifiedList.Count - 1, modifiedList.Count(f => f.Processed));

            foreach (var fileToExtract in listFiles)
            {
                Assert.IsTrue(File.Exists(fileToExtract.ExtractionPath), $"Extracted file does not exist : {fileToExtract.ExtractionPath}");
                Assert.AreEqual(File.ReadAllText(fileToExtract.SourcePath), File.ReadAllText(fileToExtract.ExtractionPath), "Incoherent extracted file content");
            }

            archiver.OnProgress -= ArchiverOnOnProgress;

            // check progress
            Assert.IsTrue(_hasReceivedGlobalProgression, "Should have received a progress event.");
            Assert.AreEqual(listFiles.Count, _nbFileProcessed, "Problem in the progress event");
            Assert.AreEqual(listFiles.GroupBy(f => f.CabPath).Count(), _nbArchiveFinished, "Problem in the progress event, number of archives");
        }
Example #6
0
 internal CabArchiver()
 {
     _cabManager = CabManager.New();
 }