public void TestFilterExceptions() { Filter f1 = new Filter("PartitionKey", "Bad", "Test", ""); Assert.False(Filter.IsValidFilter(f1)); List <Filter> filters = new List <Filter>(); filters.Add(f1); BackupAzureTables bu = new BackupAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); var exception = Assert.Throws <ParameterSpecException>(() => bu.BackupTableToFile("TestTable", "baddir", false, false, 30, filters)); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exception)); Assert.Contains("One or more of the supplied filter criteria is invalid.", exception.ToString()); var exceptionBlob = Assert.Throws <BackupFailedException>(() => bu.BackupTableToBlob("TestTable", "blobroot", "baddir", false, false, 30, 30, filters)); Assert.Contains("One or more of the supplied filter criteria is invalid.", exceptionBlob.ToString()); DeleteAzureTables instanceDelete = new DeleteAzureTables(AzureStorageConfigConnection); var exceptionDeleteRows = Assert.Throws <ParameterSpecException>(() => instanceDelete.DeleteAzureTableRows("XX", 30, filters)); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionDeleteRows)); Assert.Contains("One or more of the supplied filter criteria is invalid.", exceptionDeleteRows.ToString()); }
public void TestBackupToBlob() { BackupAzureTables instanceBackup = new BackupAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); CopyAzureTables instanceCopy = new CopyAzureTables(AzureStorageConfigConnection); DeleteAzureTables instanceDelete = new DeleteAzureTables(AzureStorageConfigConnection); RestoreAzureTables instanceRestore = new RestoreAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); InitializeTables(instanceDelete, instanceRestore, FileNamePathThatExists_SystemLogs); List <Filter> Filters = new List <Filter>(); Filters.Add(new Filter("RowKey", "=", "User1")); Filters.Add(new Filter("RowKey", "=", "User2", "OR")); string copySetup = instanceCopy.CopyTableToTable(TableNameFrom, TableNameTo, 30); int InitialRowCount = ExtractNextInt(copySetup, "total records"); string backupToBlob = instanceBackup.BackupTableToBlob(TableNameFrom, BlobRoot, WorkingDirectory, true, true, 10, 10); //int BackupRowCount = ExtractNextInt(backupToBlob, "total records"); //Need to restore to confirm string restoreResult = instanceRestore.RestoreTableFromBlob(TableNameRestoreTo, TableNameFrom, BlobRoot, WorkingDirectory, ExtractFileName(backupToBlob), 30); string copyVerify = instanceCopy.CopyTableToTable(TableNameRestoreTo, TableNameTo2, 30); int VerifyRowCount = ExtractNextInt(copyVerify, "total records"); Assert.Equal(InitialRowCount, VerifyRowCount); }
public void TestBackupServerNotRunning() { BackupAzureTables bu = new BackupAzureTables(ConnectionSpecNoServer, AzureBlobStorageConfigConnection); Assert.Throws <BackupFailedException>(() => bu.BackupTableToFile(DefaultTableName, WorkingDirectory, false, false, 5)); bu = new BackupAzureTables(AzureStorageConfigConnection, ConnectionSpecNoServer); Assert.Throws <BackupFailedException>(() => bu.BackupTableToBlob(DefaultTableName, DefaultBlobRoot, WorkingDirectory, false, false, 30, 5)); }
public void TestBackupBadConnSpec() { BackupAzureTables bu = new BackupAzureTables(BadConnectionSpec, AzureBlobStorageConfigConnection); Assert.Throws <ConnectionException>(() => bu.BackupTableToFile(DefaultTableName, WorkingDirectory, false, false, 5)); bu = new BackupAzureTables(AzureStorageConfigConnection, BadConnectionSpec); Assert.Throws <ConnectionException>(() => bu.BackupTableToBlob(DefaultTableName, DefaultBlobRoot, WorkingDirectory, false, false, 5, 5)); }
public void TestBackupBadDir() { BackupAzureTables bu = new BackupAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); Assert.Throws <ParameterSpecException>(() => bu.BackupTableToFile("TestTable", "baddir", false)); var exception = Assert.Throws <BackupFailedException>(() => bu.BackupTableToBlob(DefaultTableName, DefaultBlobRoot, "baddir", false, false, 30)); Assert.Contains("ParameterSpecException", exception.InnerException.ToString()); }
public void TestBackupOutfileDirectoryDoesNotExist() { BackupAzureTables bu = new BackupAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); var exception1 = Assert.Throws <ParameterSpecException>(() => bu.BackupTableToFile("TestTable", DirectoryDoesNotExist, false)); Assert.Contains("OutFileDirectory does not exist", exception1.ToString()); var exception2 = Assert.Throws <ParameterSpecException>(() => bu.BackupTableToBlob(DefaultTableName, DefaultBlobRoot, DirectoryDoesNotExist, false, false, 30)); Assert.Contains("OutFileDirectory does not exist", exception2.ToString()); }
private string Backup(SecureString AzureBlobStorageConfigConnection, SecureString AzureStorageConfigConnection, IConfiguration config) { try { BackupAzureTables me = new BackupAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); string Target = GetFromParmOrFile(config, TargetParmName).ToLower(); if (!String.IsNullOrEmpty(Target)) { var sectionFilters = config.GetSection("Filters"); List <Filter> filters = sectionFilters.Get <List <Filter> >(); if (!Filter.AreFiltersValid(filters)) { throw new Exception("One or more of the supplied filter cirteria is invalid."); } if (Target.Contains("file")) { return(me.BackupTableToFile(GetFromParmOrFile(config, TableNameParmName), GetFromParmOrFile(config, OutFileDirectoryParmName), GetBoolFromParmOrFile(config, CompressParmName), GetBoolFromParmOrFile(config, ValidateParmName), GetIntFromParmOrFile(config, TimeoutSecondsParmName), filters)); } else if (Target.Contains("blob")) { return(me.BackupTableToBlob(GetFromParmOrFile(config, TableNameParmName), GetFromParmOrFile(config, BlobRootParmName), GetFromParmOrFile(config, OutFileDirectoryParmName), GetBoolFromParmOrFile(config, CompressParmName), GetBoolFromParmOrFile(config, ValidateParmName), GetIntFromParmOrFile(config, RetentionDaysParmName), GetIntFromParmOrFile(config, TimeoutSecondsParmName), filters)); } else { throw new Exception("Missing or invalid configuration for requested command."); } } else { throw new Exception("Missing or invalid configuration for requested command."); } } catch (Exception ex) { throw ex; } }
public void TestBackupParameterExceptions() { BackupAzureTables instanceBackup = new BackupAzureTables(AzureStorageConfigConnection); var exceptionToFileTableMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToFile("", "baddir")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToFileTableMissing)); Assert.Contains("TableName is missing.", exceptionToFileTableMissing.ToString()); var exceptionToFileOutDirMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToFile("XX", "")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToFileOutDirMissing)); Assert.Contains("OutFileDirectory is missing.", exceptionToFileOutDirMissing.ToString()); var exceptionToBlobTableMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlob("", "badroot", "baddir")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobTableMissing)); Assert.Contains("TableName is missing.", exceptionToBlobTableMissing.ToString()); var exceptionToBlobBlobRootMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlob("XX", "", "baddir")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobBlobRootMissing)); Assert.Contains("BlobRoot is missing.", exceptionToBlobBlobRootMissing.ToString()); var exceptionToBlobOutDirMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlob("XX", "XX", "")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobOutDirMissing)); Assert.Contains("OutFileDirectory is missing.", exceptionToBlobOutDirMissing.ToString()); var exceptionToBlobDirectTableMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlobDirect("", "badroot")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobDirectTableMissing)); Assert.Contains("TableName is missing.", exceptionToBlobDirectTableMissing.ToString()); var exceptionToBlobDirectBlobRootMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlobDirect("XX", "")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobDirectBlobRootMissing)); Assert.Contains("BlobRoot is missing.", exceptionToBlobDirectBlobRootMissing.ToString()); }