Exemplo n.º 1
0
        public void TestReactionTimeTimeContoroller()
        {
            var nowPlusSec = DateTime.Now + TimeSpan.FromSeconds(1);
            var testData   = new TestedData();

            var config = new Config()
            {
                schedulePeriod = TimeSpan.FromMilliseconds(400),
                reactionTime   = new ReactionTime()
                {
                    hour   = nowPlusSec.Hour,
                    minute = nowPlusSec.Minute,
                    second = nowPlusSec.Second
                },
                backupCondition = BackupCondition.AlwaysAtTheCertainTime
            };

            var dataPlace    = new DataPlace(testData.DirPath);
            var backupRule   = new BackupRule(dataPlace, config);
            var backuperMock = new Mock <IBackuper>();

            var timeController = new TimeController(config, backuperMock.Object);

            timeController.Start();

            Thread.Sleep(1600);

            timeController.Stop();

            backuperMock.Verify(backuper => backuper.Update(), Times.AtLeast(2));
        }
Exemplo n.º 2
0
 public static Task <IEnumerable <FileInfo> > TraverseDirectoryWithFilterAsync(
     string rootDirPath,
     BackupRule backupRule,
     traverseFSFileAdded callback)
 {
     return(TraverseDirectoryWithFilterAsync(
                rootDirPath,
                backupRule.FilterIncludes,
                backupRule.FilterExcludes,
                callback
                ));
 }
Exemplo n.º 3
0
        public void TestRules()
        {
            var backupRule = new BackupRule(_dataPlace, _config);
            var actionMock = new Mock <IBackupAction>();

            var backuper = new Backuper(actionMock.Object, backupRule);

            _testedData.ChangeFile();
            Thread.Sleep(MoreTime);
            backuper.Update();

            Thread.Sleep(MoreTime);
            backuper.Update();

            actionMock.Verify(act => act.Backup(), Times.Once);
        }
Exemplo n.º 4
0
        public void TestEncryptedArchives()
        {
            var newConfig = _config;

            newConfig.usePassword   = true;
            newConfig.password      = "******";
            newConfig.backupToPath += "\\test.zip";


            var backupRule   = new BackupRule(_dataPlace, newConfig);
            var backupAction = new BackupAction(_dataPlace, newConfig);

            var backuper = new Backuper(backupAction, backupRule);

            backupAction.Backup();

            var verificator = new DataVerificator(_testedData);

            Assert.Catch <InvalidDataException>(() => verificator.testArchive(newConfig.backupToPath));
            Assert.IsTrue(verificator.testEncryptedArchive(newConfig.backupToPath, newConfig.password));
        }
Exemplo n.º 5
0
        public void TestTimeContoroller()
        {
            var testData = new TestedData();

            var config = new Config()
            {
                schedulePeriod  = TimeSpan.FromMilliseconds(500),
                backupCondition = BackupCondition.SchedulePeriodIfChanged
            };

            var dataPlace    = new DataPlace(testData.DirPath);
            var backupRule   = new BackupRule(dataPlace, config);
            var backuperMock = new Mock <IBackuper>();

            var timeController = new TimeController(config, backuperMock.Object);

            timeController.Start();

            Thread.Sleep(1250);

            timeController.Stop();

            backuperMock.Verify(backuper => backuper.Update(), Times.Exactly(2));
        }
Exemplo n.º 6
0
 public static IEnumerable <FileInfo> TraverseDirectoryWithFilter(string rootDirPath, BackupRule backupRule)
 {
     return(TraverseDirectoryWithFilter(
                rootDirPath,
                backupRule.FilterIncludes,
                backupRule.FilterExcludes
                ));
 }