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());
        }
        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));

            bu = new BackupAzureTables(AzureStorageConfigConnection, ConnectionSpecNoServer);
            Assert.Throws <BackupFailedException>(() => bu.BackupTableToBlobDirect(DefaultTableName, DefaultBlobRoot, false, 30, 5));
        }
        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());
        }