QBackupTests/Tests.cs
/// <summary>
/// Test that backup won't write into non empty dir when compressing/extracting.
/// </summary>
Test that backup won't write into non empty dir when compressing/extracting.
Test that backup won ' t write into non empty dir when compressing / extracting .
[Test]
        public static void TestCheckDirectoryBeforeWriting()
        {
            var log = new LogLines();
            var t = new TestDir(InputDir);
            t.Create();
            var src = AnalyzedBackup.Create(t.Dirs[0], true, log);
            var expected_error = "The directory is not empty.";
            var archived_dir = src.GetDestinationDirForCompression(OutputDir);
            test(() => src.Compress(OutputDir, Password, 256, log), expected_error, archived_dir, p => Directory.CreateDirectory(p.Path + "dir\\"));
            test(() => src.Compress(OutputDir, Password, 256, log), expected_error, archived_dir, p => System.IO.File.WriteAllText(p.Path + "file.txt", "content"));
            src.Compress(OutputDir, Password, 256, log);
            var archived = ArchivedBackup.CreateFromPath(archived_dir, Password, log);
            QAssert.AreEqual(src, archived);
            var extracted_dir = archived.GetDestinationForExtraction(ExtractedDir);
            test(() => archived.Extract(ExtractedDir, Password, log), expected_error, extracted_dir, p => Directory.CreateDirectory(p.Path + "dir\\"));
            test(() => archived.Extract(ExtractedDir, Password, log), expected_error, extracted_dir, p => System.IO.File.WriteAllText(p.Path + "file.txt", "content"));
            archived.Extract(ExtractedDir, Password, log);
            var extracted = AnalyzedBackup.Create(extracted_dir, true, log);
            QAssert.AreEqual(src, extracted);
            Directory.Delete(src.Root.Path, true);
            Directory.Delete(archived_dir.Path, true);
            Directory.Delete(extracted_dir.Path, true);
            void test(Action a, string msg, QualifiedPath path, Action<QualifiedPath> do_on_dir)
            {
                Directory.CreateDirectory(path.Path);
                do_on_dir(path);
                try
                {
                    a();
                }
                catch (Exception e)
                {
                    Assert.AreEqual(msg, e.Message);
                }
                Directory.Delete(path.Path, true);
            }
        }
[ Test ] public static void TestCheckDirectoryBeforeWriting ( ) { var log = new LogLines ( ) ; var t = new TestDir ( InputDir ) ; t . Create ( ) ; var src = AnalyzedBackup . Create ( t . Dirs [ 0 ] , true , log ) ; var expected_error = " " ; var archived_dir = src . GetDestinationDirForCompression ( OutputDir ) ; test ( ( ) => src . Compress ( OutputDir , Password , 256 , log ) , expected_error , archived_dir , p => Directory . CreateDirectory ( p . Path + " \\ " ) ) ; test ( ( ) => src . Compress ( OutputDir , Password , 256 , log ) , expected_error , archived_dir , p => System . IO . File . WriteAllText ( p . Path + " " , " " ) ) ; src . Compress ( OutputDir , Password , 256 , log ) ; var archived = ArchivedBackup . CreateFromPath ( archived_dir , Password , log ) ; QAssert . AreEqual ( src , archived ) ; var extracted_dir = archived . GetDestinationForExtraction ( ExtractedDir ) ; test ( ( ) => archived . Extract ( ExtractedDir , Password , log ) , expected_error , extracted_dir , p => Directory . CreateDirectory ( p . Path + " \\ " ) ) ; test ( ( ) => archived . Extract ( ExtractedDir , Password , log ) , expected_error , extracted_dir , p => System . IO . File . WriteAllText ( p . Path + " " , " " ) ) ; archived . Extract ( ExtractedDir , Password , log ) ; var extracted = AnalyzedBackup . Create ( extracted_dir , true , log ) ; QAssert . AreEqual ( src , extracted ) ; Directory . Delete ( src . Root . Path , true ) ; Directory . Delete ( archived_dir . Path , true ) ; Directory . Delete ( extracted_dir . Path , true ) ; void test ( Action a , string msg , QualifiedPath path , Action < QualifiedPath > do_on_dir ) { Directory . CreateDirectory ( path . Path ) ; do_on_dir ( path ) ; try { a ( ) ; } catch ( Exception e ) { Assert . AreEqual ( msg , e . Message ) ; } Directory . Delete ( path . Path , true ) ; } }
Test that backup won't write into non empty dir when compressing/extracting.
Test that backup won ' t write into non empty dir when compressing / extracting .
//clean up