Exemple #1
0
        public void TestBackupToBlobDirect()
        {
            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.BackupTableToBlobDirect(TableNameFrom, BlobDirectRoot, false, 10, 10);
            int    BackupRowCount = ExtractNextInt(backupToBlob, "total records");

            //Need to restore to confirm
            string restoreResult = instanceRestore.RestoreTableFromBlobDirect(TableNameRestoreTo, TableNameFrom, BlobDirectRoot, ExtractFileName(backupToBlob), 30);

            string copyVerify     = instanceCopy.CopyTableToTable(TableNameRestoreTo, TableNameTo2, 30);
            int    VerifyRowCount = ExtractNextInt(copyVerify, "total records");

            Assert.Equal(InitialRowCount, VerifyRowCount);
        }
        public void TestCopy()
        {
            CopyAzureTables    instanceCopy    = new CopyAzureTables(AzureStorageConfigConnection);
            DeleteAzureTables  instanceDelete  = new DeleteAzureTables(AzureStorageConfigConnection);
            RestoreAzureTables instanceRestore = new RestoreAzureTables(AzureStorageConfigConnection);

            string deleteInitializeResult  = instanceDelete.DeleteAzureTableRows(TableNameTo);
            string deleteInitialize2Result = instanceDelete.DeleteAzureTableRows(TableNameTo2);
            string deleteInitialize3Result = instanceDelete.DeleteAzureTableRows(TableNameFrom);

            string restoreResult = instanceRestore.RestoreTableFromFile(TableNameFrom, FileNamePathThatExists_SystemLogs);
            int    RestoreCount  = ExtractNextInt(restoreResult, "Successful;", "entries");

            string copySetup = instanceCopy.CopyTableToTable(TableNameFrom, TableNameTo);
            //pull result of rows copied    "Table 'SystemLogs' copied to table 'TestCopy', total records 370."
            int InitialRowCount = ExtractNextInt(copySetup, "total records");

            List <Filter> Filters = new List <Filter>();

            Filters.Add(new Filter("PartitionKey", "=", "SecurityLog"));

            string delete2Result    = instanceDelete.DeleteAzureTableRows(TableNameTo, 30, Filters);
            int    RowsDeletedCount = ExtractNextInt(delete2Result, "total rows deleted");

            Assert.True(RowsDeletedCount > 0);

            string copy2Result    = instanceCopy.CopyTableToTable(TableNameTo, TableNameTo2);
            int    SecondRowCount = ExtractNextInt(copy2Result, "total records");

            Assert.Equal(InitialRowCount, SecondRowCount + RowsDeletedCount);
        }
Exemple #3
0
        public void TestCopyParameterExceptions()
        {
            CopyAzureTables instanceCopy = new CopyAzureTables(AzureStorageConfigConnection);

            var exceptionFromMissing = Assert.Throws <ParameterSpecException>(() => instanceCopy.CopyTableToTable("", TableNameTo2));

            Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionFromMissing));
            Assert.Contains("SourceTableName is missing.", exceptionFromMissing.ToString());

            var exceptionToMissing = Assert.Throws <ParameterSpecException>(() => instanceCopy.CopyTableToTable(TableNameTo, ""));

            Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToMissing));
            Assert.Contains("DestinationTableName is missing.", exceptionToMissing.ToString());
        }
        public void TestCopyServerNotRunning()
        {
            CopyAzureTables instance = new CopyAzureTables(ConnectionSpecNoServer, AzureStorageConfigConnection);

            Assert.Throws <CopyFailedException>(() => instance.CopyTableToTable(DefaultTableName, DefaultTableName, 5));

            instance = new CopyAzureTables(AzureStorageConfigConnection, ConnectionSpecNoServer);
            Assert.Throws <CopyFailedException>(() => instance.CopyTableToTable(DefaultTableName, DefaultTableName, 5));
        }
        public void TestCopyBadConnSpec()
        {
            CopyAzureTables instance = new CopyAzureTables(BadConnectionSpec, AzureBlobStorageConfigConnection);

            Assert.Throws <ConnectionException>(() => instance.CopyTableToTable(DefaultTableName, DefaultTableName, 5));

            instance = new CopyAzureTables(AzureStorageConfigConnection, BadConnectionSpec);
            Assert.Throws <ConnectionException>(() => instance.CopyTableToTable(DefaultTableName, DefaultTableName, 5));
        }
Exemple #6
0
        public void TestBackupToBlob_LargeFile()
        {
            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_LargeFile);

            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);
        }
Exemple #7
0
        public void TestDeleteRows_LargeFile()
        {
            BackupAzureTables  instanceBackup  = new BackupAzureTables(AzureStorageConfigConnection, AzureStorageConfigConnection);
            CopyAzureTables    instanceCopy    = new CopyAzureTables(AzureStorageConfigConnection);
            DeleteAzureTables  instanceDelete  = new DeleteAzureTables(AzureStorageConfigConnection);
            RestoreAzureTables instanceRestore = new RestoreAzureTables(AzureStorageConfigConnection, AzureStorageConfigConnection);

            InitializeTables(instanceDelete, instanceRestore, FileNamePathThatExists_SystemLogs_LargeFile);

            string copySetup       = instanceCopy.CopyTableToTable(TableNameFrom, TableNameTo, 30);
            int    InitialRowCount = ExtractNextInt(copySetup, "total records");

            List <Filter> DeleteFilters = new List <Filter>();

            DeleteFilters.Add(new Filter("PartitionKey", "=", "WebAppLog"));
            string DeleteResult = instanceDelete.DeleteAzureTableRows(TableNameTo, 30, DeleteFilters);
            int    DeleteCount  = ExtractNextInt(DeleteResult, "total rows deleted");

            string copyVerify        = instanceCopy.CopyTableToTable(TableNameTo, TableNameTo2, 30);
            int    RemainingRowCount = ExtractNextInt(copyVerify, "total records");

            Assert.Equal(InitialRowCount, DeleteCount + RemainingRowCount);
        }
Exemple #8
0
        public void TestCopyRowKey()
        {
            CopyAzureTables    instanceCopy    = new CopyAzureTables(AzureStorageConfigConnection);
            DeleteAzureTables  instanceDelete  = new DeleteAzureTables(AzureStorageConfigConnection);
            RestoreAzureTables instanceRestore = new RestoreAzureTables(AzureStorageConfigConnection);

            string deleteInitializeResult  = instanceDelete.DeleteAzureTableRows(TableNameTo);
            string deleteInitialize2Result = instanceDelete.DeleteAzureTableRows(TableNameTo2);
            string deleteInitialize3Result = instanceDelete.DeleteAzureTableRows(TableNameFrom);

            string restoreResult = instanceRestore.RestoreTableFromFile(TableNameFrom, FileNamePathThatExists_UserProfile);
            int    RestoreCount  = ExtractNextInt(restoreResult, "Successful;", "entries");

            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, Filters);
            int    InitialRowCount = ExtractNextInt(copySetup, "total records");

            List <Filter> Filters2 = new List <Filter>();

            Filters2.Add(new Filter("RowKey", "=", "User1"));

            string delete2Result    = instanceDelete.DeleteAzureTableRows(TableNameTo, 30, Filters2);
            int    RowsDeletedCount = ExtractNextInt(delete2Result, "total rows deleted");

            Assert.True(RowsDeletedCount > 0);

            string copy2Result    = instanceCopy.CopyTableToTable(TableNameTo, TableNameTo2);
            int    SecondRowCount = ExtractNextInt(copy2Result, "total records");

            Assert.Equal(InitialRowCount, SecondRowCount + RowsDeletedCount);

            System.Console.WriteLine("Test");
        }
        private string Copy(SecureString AzureStorageSourceConfigConnection, SecureString AzureStorageDestinationConfigConnection, IConfiguration config)
        {
            try
            {
                CopyAzureTables me = new CopyAzureTables(AzureStorageSourceConfigConnection, AzureStorageDestinationConfigConnection);

                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.");
                }

                return(me.CopyTableToTable(GetFromParmOrFile(config, TableNameParmName),
                                           GetFromParmOrFile(config, DestinationTableNameParmName),
                                           GetIntFromParmOrFile(config, TimeoutSecondsParmName),
                                           filters));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }