public void SourceLocationsValidateCallsValidateOnSourcesInsideCollection() { var loc1 = new LocalSourceLocation(); loc1.Path = Environment.CurrentDirectory; loc1.RevisionCount = 1; loc1.ID = 1; loc1.FileMatchFilter = "*"; var loc2 = new LocalSourceLocation(); loc2.Path = Environment.CurrentDirectory; loc2.RevisionCount = 1; loc2.ID = 2; loc2.FileMatchFilter = "*"; var loc3 = new LocalSourceLocation(); loc3.Path = Environment.CurrentDirectory; loc3.RevisionCount = 0; // this should cause a validation error loc3.ID = 3; loc3.FileMatchFilter = "*"; var locations = new ArchivialLibrary.Folders.SourceLocations(); locations.Add(loc1); locations.Add(loc2); locations.Add(loc3); // should throw locations.Validate(); }
public void SourceLocationsValidateThrowsExceptionOnDuplicateIDs() { var loc1 = new LocalSourceLocation(); loc1.Path = Environment.CurrentDirectory; loc1.RevisionCount = 1; loc1.ID = 1; loc1.FileMatchFilter = "*"; var loc2 = new LocalSourceLocation(); loc2.Path = Environment.CurrentDirectory; loc2.RevisionCount = 1; loc2.ID = 2; loc2.FileMatchFilter = "*"; var loc3 = new LocalSourceLocation(); loc3.Path = Environment.CurrentDirectory; loc3.RevisionCount = 1; loc3.ID = 2; loc3.FileMatchFilter = "*"; var locations = new ArchivialLibrary.Folders.SourceLocations(); locations.Add(loc1); locations.Add(loc2); locations.Add(loc3); // should throw locations.Validate(); }
public void SourceLocationsValidateDoesNotThrowOnAllValidSources() { var loc1 = new LocalSourceLocation(); loc1.Path = Environment.CurrentDirectory; loc1.RevisionCount = 1; loc1.ID = 1; loc1.FileMatchFilter = "*"; var loc2 = new LocalSourceLocation(); loc2.Path = Environment.CurrentDirectory; loc2.RevisionCount = 1; loc2.ID = 2; loc2.FileMatchFilter = "*"; var loc3 = new LocalSourceLocation(); loc3.Path = Environment.CurrentDirectory; loc3.RevisionCount = 1; loc3.ID = 3; loc3.FileMatchFilter = "*"; var locations = new ArchivialLibrary.Folders.SourceLocations(); locations.Add(loc1); locations.Add(loc2); locations.Add(loc3); // should throw locations.Validate(); Assert.IsTrue(true); }
public void SourceLocationValidateThrowsExceptionWhenInvalidFolderPathIsProvided() { var loc = new LocalSourceLocation(); loc.Path = null; loc.ValidateParameters(); }
public void RemoveArchivialLocalSourceCommand_ThrowsIfSourceIsNotFound() { var mockedDb = new Mock <IClientDatabase>(); LocalSourceLocation databaseCommitedObject = null; mockedDb.Setup(x => x.GetSourceLocationsAsync()).ReturnsAsync( new SourceLocations() { new LocalSourceLocation() { ID = 1 } } ); mockedDb.Setup(x => x.RemoveSourceLocationAsync(It.IsAny <LocalSourceLocation>())) .Returns(Task.CompletedTask) .Callback <LocalSourceLocation>(x => databaseCommitedObject = x); var mockedCoreSettings = new Mock <ICoreSettings>(); var depedencies = new CmdletDependencies() { ClientDatabase = mockedDb.Object, CoreSettings = mockedCoreSettings.Object }; var command = new RemoveArchivialLocalSourceCommand(depedencies) { SourceID = 2 }; var result = command.Invoke().GetEnumerator().MoveNext(); }
public void SourceLocationValidateThrowsExceptionWhenInvalidRevisionCountProvided2() { var loc = new LocalSourceLocation(); loc.Path = Environment.CurrentDirectory; loc.RevisionCount = -15; loc.ValidateParameters(); }
public void SourceLocationShouldScanExample2() { var loc = new LocalSourceLocation(); loc.LastCompletedScan = null; loc.ShouldScan(null); }
public void SourceLocationValidateThrowsExceptionWhenInvalidFileMatchPatternIsProvided2() { var loc = new LocalSourceLocation(); loc.Path = Environment.CurrentDirectory; loc.FileMatchFilter = "test.mp3"; loc.ValidateParameters(); }
public void SourceLocationValidatePassesValidExample3() { var loc = new LocalSourceLocation(); loc.Path = Environment.CurrentDirectory; loc.RevisionCount = 12345678; loc.ID = 1; loc.ValidateParameters(); Assert.IsTrue(true); }
public void SourceLocationValidatePassesValidExample14() { var loc = new LocalSourceLocation(); loc.Path = Environment.CurrentDirectory; loc.RevisionCount = 1; loc.FileMatchFilter = "t?st.do?"; loc.ID = 1; loc.ValidateParameters(); Assert.IsTrue(true); }
public void SourceLocationShouldScanExample14() { var loc = new LocalSourceLocation(); loc.LastCompletedScan = DateTime.Now.AddHours(-1250); loc.Priority = ArchivialLibrary.Files.FileBackupPriority.Low; var options = new ArchivialLibrary.Folders.ScanFrequencies(); options.LowPriorityScanFrequencyInHours = 72; Assert.IsTrue(loc.ShouldScan(options)); }
public void SourceLocationShouldScanExample8() { var loc = new LocalSourceLocation(); loc.LastCompletedScan = DateTime.Now.AddHours(-23); loc.Priority = ArchivialLibrary.Files.FileBackupPriority.Medium; var options = new ArchivialLibrary.Folders.ScanFrequencies(); options.MedPriorityScanFrequencyInHours = 24; Assert.IsFalse(loc.ShouldScan(options)); }
public void SourceLocationShouldScanExample5() { var loc = new LocalSourceLocation(); loc.LastCompletedScan = DateTime.Now.AddMinutes(-61); loc.Priority = ArchivialLibrary.Files.FileBackupPriority.High; var options = new ArchivialLibrary.Folders.ScanFrequencies(); options.HighPriorityScanFrequencyInHours = 1; Assert.IsTrue(loc.ShouldScan(options)); }
public void SourceLocationShouldScanExample1() { var loc = new LocalSourceLocation(); loc.LastCompletedScan = null; var options = new ArchivialLibrary.Folders.ScanFrequencies(); options.LowPriorityScanFrequencyInHours = 72; options.MedPriorityScanFrequencyInHours = 24; options.HighPriorityScanFrequencyInHours = 1; Assert.IsTrue(loc.ShouldScan(options)); }
/// <summary> /// Cmdlet invocation. /// </summary> protected override void ProcessRecord() { FileBackupPriority priorityEnum; if (!Enum.TryParse(Priority, out priorityEnum)) { throw new ArgumentException(nameof(Priority) + " value was not valid."); } if (MatchFilter == null) { MatchFilter = ArchivialLibrary.Constants.CommandLine.DefaultSourceMatchFilter; } var db = GetDatabaseConnection(); WriteVerbose("Querying for existing scan sources to check for duplicates."); var allSources = db.GetSourceLocationsAsync().GetAwaiter().GetResult(); var allLocalSources = allSources.Where(x => x is LocalSourceLocation).ToList(); if (allLocalSources.Any(x => string.Equals(x.Path, FolderPath, StringComparison.CurrentCultureIgnoreCase) && string.Equals(x.FileMatchFilter, MatchFilter, StringComparison.CurrentCultureIgnoreCase))) { // there already exists a source with this folder location and match filter. throw new SourceLocationException("Unable to add source: the specified folder and match filter combination is already listed as a source."); } else { WriteVerbose("No duplicate sources found."); } var newSource = new LocalSourceLocation(); newSource.Path = FolderPath; newSource.FileMatchFilter = MatchFilter; newSource.RevisionCount = Revisions; newSource.Priority = priorityEnum; WriteVerbose("Validating the source parameters are acceptable."); newSource.ValidateParameters(); WriteVerbose("The specified scan source has normal parameters."); WriteVerbose("Saving the source to the database."); db.SetSourceLocationAsync(newSource).GetAwaiter().GetResult(); WriteVerbose("Successfully saved source to the database."); }
/// <summary> /// Imports sources for scanning. /// </summary> /// <remarks> /// This function is marked as safe and should not throw exceptions. /// </remarks> /// <returns></returns> private async Task <SourceLocations> SafeImportSourcesAsync() { try { // grab the current copy from DB (this includes last scanned timestamp) var dbSources = await GetSourceLocationsFromDatabaseAsync().ConfigureAwait(false); if (dbSources.Any(x => x.Path == CoreSettings.GetDatabaseBackupsDirectory()) == false) { // add the base meta DB backup folder. var databaseFolderSource = new LocalSourceLocation(); databaseFolderSource.Path = CoreSettings.GetDatabaseBackupsDirectory(); databaseFolderSource.FileMatchFilter = "*.bak"; databaseFolderSource.RevisionCount = 1; databaseFolderSource.Priority = Files.FileBackupPriority.Meta; databaseFolderSource.DestinationContainerName = "archivial-core-database-backups"; await Database.SetSourceLocationAsync(databaseFolderSource).ConfigureAwait(false); } if (dbSources.Any(x => x.Path == CoreSettings.GetLogFilesArchiveDirectory()) == false) { // add the base meta log backup folder. var logFolderSource = new LocalSourceLocation(); logFolderSource.Path = CoreSettings.GetLogFilesArchiveDirectory(); logFolderSource.FileMatchFilter = "*.log"; logFolderSource.RevisionCount = 1; logFolderSource.Priority = Files.FileBackupPriority.Meta; logFolderSource.DestinationContainerName = "archivial-core-log-backups"; await Database.SetSourceLocationAsync(logFolderSource).ConfigureAwait(false); } return(dbSources); } catch (Exception ex) { string err = "Failed to import scan sources."; Logger.WriteSystemEvent(err, ex, Logger.GenerateFullContextStackTrace(), Constants.EventIDs.FailedToLoadScanSources, true); return(null); } }
public void RemoveArchivialLocalSourceCommand_CanRemoveSource_FromSourceObject() { var mockedDb = new Mock <IClientDatabase>(); LocalSourceLocation databaseCommitedObject = null; mockedDb.Setup(x => x.GetSourceLocationsAsync()).ReturnsAsync( new SourceLocations() { new LocalSourceLocation() { ID = 1 } } ); mockedDb.Setup(x => x.RemoveSourceLocationAsync(It.IsAny <LocalSourceLocation>())) .Returns(Task.CompletedTask) .Callback <LocalSourceLocation>(x => databaseCommitedObject = x); var mockedCoreSettings = new Mock <ICoreSettings>(); var depedencies = new CmdletDependencies() { ClientDatabase = mockedDb.Object, CoreSettings = mockedCoreSettings.Object }; var command = new RemoveArchivialLocalSourceCommand(depedencies) { LocalSource = new LocalSourceLocation() { ID = 1 } }; var result = command.Invoke().GetEnumerator().MoveNext(); mockedDb.Verify(x => x.RemoveSourceLocationAsync(It.IsAny <LocalSourceLocation>()), Times.Once); Assert.IsNotNull(databaseCommitedObject); Assert.AreEqual(1, databaseCommitedObject.ID); }