public void Teardown()
 {
     //delete temp export file
     _exportFileCreator.DeleteExportFileAsync().Wait();
     _exportFileCreator = null;
 }
        private async Task VerifyIfExportWorkerQueueContainsRecordsForJobAsync(int workspaceArtifactId, int exportJobArtifactId)
        {
            _errorContext = $"An error occurred while creating the export file. [WorkspaceArtifactId = {WorkspaceArtifactId}, ExportJobArtifactId = {exportJobArtifactId}]";

            var exportWorkerQueueRecordCount = await QueryHelper.GetExportResultsRecordCountAsync(AgentHelper.GetDBContext(-1), workspaceArtifactId, exportJobArtifactId, AgentId);

            if (exportWorkerQueueRecordCount > 0)
            {
                try
                {
                    //Create export.csv in a Temp folder
                    var exportFullFilePath = await _exportFileCreator.CreateExportFileAsync(_markupUtilityExportJob.Name);

                    //Write Records to Export File
                    await WriteResultsToExportFileAsync();

                    //Create Markup Utility File record name
                    var redactionFileName = _exportFileCreator.ExportFileName;

                    //Create new RDO File record
                    var redactionFileRdoArtifactId = await _artifactQueries.CreateMarkupUtilityFileRdoRecordAsync(_serviceMgr, ExecutionIdentity.CurrentUser, workspaceArtifactId, redactionFileName);

                    //Attach export csv to File RDO
                    var fileArtifactId = await QueryHelper.GetArtifactIdByGuidAsync(AgentHelper.GetDBContext(workspaceArtifactId), Constant.Guids.Field.MarkupUtilityFile.File);

                    await _artifactQueries.AttachFileToMarkupUtilityFileRecord(_serviceMgr, ExecutionIdentity.CurrentUser, workspaceArtifactId, redactionFileRdoArtifactId, exportFullFilePath, fileArtifactId);

                    //Attach RDO File record to Export Job
                    await _artifactQueries.AttachRedactionFileToExportJob(_serviceMgr, ExecutionIdentity.CurrentUser, workspaceArtifactId, _markupUtilityExportJob.ArtifactId, redactionFileRdoArtifactId);

                    //Update Exported Redaction Count
                    await _artifactQueries.UpdateRdoJobTextFieldAsync(_serviceMgr, workspaceArtifactId, ExecutionIdentity.CurrentUser, Constant.Guids.ObjectType.MarkupUtilityExportJob, _markupUtilityExportJob.ArtifactId, Constant.Guids.Field.MarkupUtilityExportJob.ExportedRedactionCount, exportWorkerQueueRecordCount.ToString());
                }
                catch (Exception ex)
                {
                    RaiseMessage(_errorContext);
                    throw new MarkupUtilityException(_errorContext, ex);
                }
                finally
                {
                    //Delete CSV file
                    await _exportFileCreator.DeleteExportFileAsync();
                }

                //Set the status of the Export Job to Complete
                await UpdateStatusFieldAsync(_markupUtilityExportJob.ArtifactId, Constant.Status.Job.COMPLETED);
            }
            else
            {
                //Query Worker Queue to see if any other records exist for the Export Job, if not, set status to Completed
                //This is for a scenario where no redactions were found for the Export Job
                var exportWorkerQueueCount = await QueryHelper.GetJobWorkerRecordCountAsync(AgentHelper.GetDBContext(-1), workspaceArtifactId, exportJobArtifactId, Constant.Tables.ExportWorkerQueue, "ExportJobArtifactID");

                if (exportWorkerQueueCount == 0)
                {
                    //Set the status of the Export Job to Complete
                    await UpdateStatusFieldAsync(_markupUtilityExportJob.ArtifactId, Constant.Status.Job.COMPLETED);

                    //Update Exported Redation Count to 0
                    await _artifactQueries.UpdateRdoJobTextFieldAsync(_serviceMgr, workspaceArtifactId, ExecutionIdentity.CurrentUser, Constant.Guids.ObjectType.MarkupUtilityExportJob, _markupUtilityExportJob.ArtifactId, Constant.Guids.Field.MarkupUtilityExportJob.ExportedRedactionCount, "0");
                }
            }
        }