/// <summary> /// /// </summary> /// <param name="config"></param> /// <param name="jobID"></param> /// <param name="target"></param> /// <returns></returns> public string Execute(string config, int jobID, IBackupTarget target) { using (BackupRunner br = new BackupRunner(FileBackupConfig.Load(config), jobID, target)) { int count = br.Run(); return("{0} files was backed up".FillBlanks(count)); } }
public void TestBackup() { var folder = Path.Combine(Config.CurrentDirectory, "TestBackup"); DeleteFolder(folder); try { var config = Config.Get("Backup.Config.json"); var runner = new BackupRunner(config); runner.Run(); Assert.True(Directory.Exists(folder)); Assert.True(Directory.Exists(Path.Combine(folder, "TestDestinationFolder1"))); Assert.True(Directory.Exists(Path.Combine(folder, "TestDestinationFolder2"))); Assert.True(Directory.Exists(Path.Combine(folder, "TestDestinationFolder2", "TestSubFolder"))); Assert.True(File.Exists(Path.Combine(folder, "TestDestinationFolder1", "TestFile.txt"))); Assert.True(File.Exists(Path.Combine(folder, "TestDestinationFolder1", "TestFolderFile.txt"))); Assert.True(File.Exists(Path.Combine(folder, "TestDestinationFolder1", "TestSubFolderFile.txt"))); Assert.True(File.Exists(Path.Combine(folder, "TestDestinationFolder2", "TestFolderFile.txt"))); Assert.True(File.Exists(Path.Combine(folder, "TestDestinationFolder2", "TestSubFolderFile.txt"))); Assert.True(File.Exists(Path.Combine(folder, "TestDestinationFolder2", "TestSubFolder", "TestSubFolderFile.txt"))); } finally { DeleteFolder(folder); } }
public void Cleanup() { BackupCommandLineOptions options = new BackupCommandLineOptions {BackupPath = "backup", NumberOfDaysToKeepBackups = 30}; Mock<IFileSystem> mockFileSystem = new Mock<IFileSystem>(); mockFileSystem.Setup(fs => fs.DirectoryExists(options.BackupPath)) .Returns(true) .Verifiable(); Mock<IFileSystemInfo> mockTodayFile = new Mock<IFileSystemInfo>(); mockTodayFile.SetupGet(file => file.CreationTime) .Returns(DateTime.Today) .Verifiable(); mockTodayFile.SetupGet(file => file.FullName) .Returns(@"c:\path\to\file\today.zip") .Verifiable(); Mock<IFileSystemInfo> mockLastMonthFile = new Mock<IFileSystemInfo>(); mockLastMonthFile.SetupGet(file => file.CreationTime) .Returns(DateTime.Today.AddDays(-35)) .Verifiable(); mockLastMonthFile.SetupGet(file => file.FullName) .Returns(@"c:\path\to\file\lastMonth.zip") .Verifiable(); mockFileSystem.Setup(fs => fs.GetFiles(options.BackupPath)) .Returns(new[] {mockTodayFile.Object, mockLastMonthFile.Object}) .Verifiable(); mockFileSystem.Setup(fs => fs.DeleteFile(mockLastMonthFile.Object.FullName)) .Verifiable(); BackupRunner runner = new BackupRunner(options, mockFileSystem.Object); runner.Cleanup(); mockFileSystem.Verify(fs => fs.DeleteFile(mockTodayFile.Object.FullName), Times.Never()); mockFileSystem.Verify(); mockTodayFile.Verify(); mockLastMonthFile.Verify(); }
/// <summary> /// /// </summary> /// <param name="config"></param> /// <param name="jobID"></param> public void Delete(string config, int jobID) { BackupRunner.Cleanup(jobID); }
static void Main(string[] args) { BackupRunner backupRunner = new BackupRunner(); backupRunner.Run(); }