public void NoBackupFilesAvailable() { m_fileOs.ExistingDirectories.Add(FwDirectoryFinder.DefaultBackupDirectory); BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory); Assert.AreEqual(0, repo.AvailableProjectNames.Count()); Assert.Throws(typeof(KeyNotFoundException), () => repo.GetAvailableVersions("monkey")); Assert.Throws(typeof(KeyNotFoundException), () => repo.GetBackupFile("monkey", DateTime.Now, false)); Assert.IsNull(repo.GetMostRecentBackup("monkey")); }
public void BackupsForSingleProjectExists() { DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey", "Floozy", null, FDOBackendProviderType.kXML); string backupFileName1 = backupSettings.ZipFileName; m_fileOs.AddExistingFile(backupFileName1); // Force the second backup to appear to be older backupSettings.BackupTime = backupSettings.BackupTime.AddHours(-3); string backupFileName2 = backupSettings.ZipFileName; m_fileOs.AddExistingFile(backupFileName2); BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory); Assert.AreEqual(1, repo.AvailableProjectNames.Count()); Assert.AreEqual(2, repo.GetAvailableVersions("Floozy").Count()); Assert.AreEqual(backupFileName2, repo.GetBackupFile("Floozy", backupSettings.BackupTime, false).File); Assert.AreEqual(backupFileName1, repo.GetMostRecentBackup("Floozy").File); Assert.Throws(typeof(KeyNotFoundException), () => repo.GetAvailableVersions("monkey")); Assert.Throws(typeof(KeyNotFoundException), () => repo.GetBackupFile("monkey", backupSettings.BackupTime, false)); Assert.Throws(typeof(KeyNotFoundException), () => repo.GetBackupFile("Floozy", DateTime.MinValue, false)); Assert.IsNull(repo.GetMostRecentBackup("monkey")); }
public void BackupsForMultipleProjects() { DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey", "AAA", null, FDOBackendProviderType.kXML); backupSettings.Comment = "thing1"; string backupFileName1 = backupSettings.ZipFileName; m_fileOs.AddExistingFile(backupFileName1); backupSettings.ProjectName = "ZZZ"; backupSettings.Comment = "thing2"; string backupFileName2 = backupSettings.ZipFileName; m_fileOs.AddExistingFile(backupFileName2); // Add another backup for "AAA" that appears to be older backupSettings.ProjectName = "AAA"; backupSettings.Comment = null; backupSettings.BackupTime = backupSettings.BackupTime.AddHours(-3); string backupFileName3 = backupSettings.ZipFileName; m_fileOs.AddExistingFile(backupFileName3); BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory); Assert.AreEqual(2, repo.AvailableProjectNames.Count()); Assert.AreEqual(2, repo.GetAvailableVersions("AAA").Count()); Assert.AreEqual(1, repo.GetAvailableVersions("ZZZ").Count()); BackupFileSettings fileSettings = repo.GetBackupFile("AAA", backupSettings.BackupTime, false); Assert.AreEqual(backupFileName3, fileSettings.File); Assert.AreEqual(string.Empty, fileSettings.Comment); fileSettings = repo.GetMostRecentBackup("AAA"); Assert.AreEqual(backupFileName1, fileSettings.File); Assert.AreEqual("thing1", fileSettings.Comment); fileSettings = repo.GetMostRecentBackup("ZZZ"); Assert.AreEqual(backupFileName2, fileSettings.File); Assert.AreEqual("thing2", fileSettings.Comment); }
public void BackupHasOldStyleDatetimeFormat() { DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey", "Floozy", null, FDOBackendProviderType.kXML); string backupFileName1 = Path.Combine(FwDirectoryFinder.DefaultBackupDirectory, Path.ChangeExtension("Floozy 2010-8-21-0506", FdoFileHelper.ksFwBackupFileExtension)); m_fileOs.AddExistingFile(backupFileName1); BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory); Assert.AreEqual(1, repo.AvailableProjectNames.Count()); Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count()); Assert.AreEqual(backupFileName1, repo.GetMostRecentBackup("Floozy").File); }
public void InavlidBackupFile() { DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey", "Floozy", null, FDOBackendProviderType.kXML); string backupFileName1 = backupSettings.ZipFileName; m_fileOs.AddExistingFile(backupFileName1); // Force the second backup to appear to be older backupSettings.BackupTime = backupSettings.BackupTime.AddHours(-3); string backupFileName2 = backupSettings.ZipFileName; m_fileOs.AddExistingFile(backupFileName2); BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory); BackupFileSettings invalidFileSettings = repo.GetMostRecentBackup("Floozy"); BackupFileSettings validFileSettings = repo.GetBackupFile("Floozy", backupSettings.BackupTime, false); ReflectionHelper.SetProperty(validFileSettings, "ProjectName", "Floozy"); // Force it to think it's already loaded and happy. Assert.AreEqual(2, repo.GetAvailableVersions("Floozy").Count()); Assert.IsNull(repo.GetBackupFile("Floozy", invalidFileSettings.BackupTime, true)); Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count()); Assert.AreEqual(validFileSettings, repo.GetBackupFile("Floozy", validFileSettings.BackupTime, true)); Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count()); }