Exemplo n.º 1
0
        public void TestBackupChain()
        {
            var testBackup1 = new TestBackup("Backup 1", addedOrChangedItems: new[] {"./file1.txt"});
            var testBackup2 = new TestBackup("Backup 2", parent: testBackup1, addedOrChangedItems: new[] {"./file2.txt"},
                                             deletedItems: new[] {"./file1.txt"});

            var chain = testBackup2.GetChain ();

            var chain2 = ((TestBackup) null).GetChain ();

            Assert.IsNotNull(chain2);

            Assert.AreEqual(chain.Count(), 2);

            Assert.AreEqual(chain.FirstBackup, testBackup2);

            Assert.Throws<FileNotFoundException>(() => chain.OpenFile("./file1.txt"));
            Assert.Throws<FileNotFoundException>(() => chain.GetFileSize("./file1.txt"));
            Assert.Throws<FileNotFoundException>(() => chain.GetFileHash("./file1.txt"));
            Assert.IsTrue(chain.OpenFile("./file2.txt") is MemoryStream);

            var items = chain.GetFiles ();

            Assert.IsNotNull(items);

            var enumerable = items as string[] ?? items.ToArray ();

            Assert.AreEqual(enumerable.Count(), 1);

            Assert.AreEqual(enumerable.First(), "./file2.txt");
        }
Exemplo n.º 2
0
        public TestBackup(string name, 
            TestBackup parent = null,
            bool isFullBackup = false,
            string[] addedOrChangedItems = null,
            string[] deletedItems = null)
        {
            Name = name;
            Description = "Description of " + name;
            Creator = "Creator of " + name;
            CreationDate = DateTime.Now;
            #pragma warning disable 665
            if (IsFullBackup = isFullBackup)
            #pragma warning restore 665
                SymbolicFullBackupParent = parent;
            else
                ParentBackup = parent;

            _addedOrChangedItems = addedOrChangedItems ?? new[]
                                                              {
                                                                  "./test1.txt",
                                                                  "./test2.txt",
                                                                  "./test3.txt",
                                                                  "./test4.txt",
                                                                  "./test5.txt",
                                                                  "./testdir1/test1.txt",
                                                                  "./testdir1/test2.txt",
                                                                  "./testdir1/test3.txt",
                                                                  "./testdir1/test4.txt",
                                                                  "./testdir1/test5.txt",
                                                                  "./testdir2/test1.txt",
                                                                  "./testdir2/test2.txt",
                                                                  "./testdir2/test3.txt",
                                                                  "./testdir2/test4.txt",
                                                                  "./testdir2/test5.txt"
                                                              };
            _deletedItems = deletedItems ?? new[]
                                                              {
                                                                  "./deltest1.txt",
                                                                  "./deltest2.txt",
                                                                  "./deltest3.txt",
                                                                  "./deltest4.txt",
                                                                  "./deltest5.txt",
                                                                  "./deltestdir1/test1.txt",
                                                                  "./deltestdir1/test2.txt",
                                                                  "./deltestdir1/test3.txt",
                                                                  "./deltestdir1/test4.txt",
                                                                  "./deltestdir1/test5.txt",
                                                                  "./deltestdir2/test1.txt",
                                                                  "./deltestdir2/test2.txt",
                                                                  "./deltestdir2/test3.txt",
                                                                  "./deltestdir2/test4.txt",
                                                                  "./deltestdir2/test5.txt"
                                                              };
        }