public void EverfiExcelTemplate_ImportFromList_ReturnsTrueIfDataIsImported() { FileInfo existingFilePath = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); var mockLogger = new Mock <ILogger>(); bool dataImported = false; List <EverfiUser> userList = new List <EverfiUser>(); for (int count = 0; count < 4; count++) { EverfiUser user = new EverfiUser { FIRST_NAME = "FIRST", LAST_NAME = "LAST", EMAIL = "EMAIL", SUPERVISOR = "SUPER", EMPLOYEE_ID = "Employee", GROUP_TITLE = "GROUP_T", GROUP_ABR = "GROUP_A", LOCATION_ABR = "LOC_A", LOCATION_TITLE = "LOC_T" }; userList.Add(user); } using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingFilePath, mockLogger.Object)) { dataImported = excelTemplate.ImportDataFromList(userList); } Assert.True(dataImported); }
public void EverfiExcelTemplate_ImportCSV_ThrowsFileNotFoundIfFileDoesNotExist() { FileInfo existingFilePath = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); FileInfo nonExistingCSVFile = new FileInfo("../../../Utilities/TestData/nonexisting.csv"); var mockLogger = new Mock <ILogger>(); using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingFilePath, mockLogger.Object)) { ExcelTextFormat format = new ExcelTextFormat(); Assert.Throws <FileNotFoundException>(() => excelTemplate.ImportCsv(format, nonExistingCSVFile)); } }
public void Run() { try { if (!VerifyImportFiles()) { logger.Error("Required Files do not exist. Exiting the application."); Environment.Exit(0); } IEnumerable <EverfiUser> userList = GetEverfiUsersFromCSV(); logger.Information("Loading Template at: {0}", templateFile.FullName); using (EverfiExcelTemplate template = new EverfiExcelTemplate(this.templateFile, this.logger)) { logger.Information("Importing CSV File from: {0}", csvFile.FullName); template.ImportDataFromList(userList.ToList()); DateFileTagger fileTagger = new DateFileTagger(); FileInfo saveDestination = new FileInfo(Environment.ExpandEnvironmentVariables(this.configuration.ReportSavePath)); saveDestination = fileTagger.Tag(saveDestination, this.timeStamp); logger.Information("Saving report to: {0}", saveDestination.FullName); bool saveSuccessful = template.SaveTemplateTo(saveDestination); if (saveSuccessful) { logger.Information("Save successful | Path: {0}", saveDestination.FullName); DirectoryInfo archiveDirectory = new DirectoryInfo(Environment.ExpandEnvironmentVariables(configuration.ArchiveDirectory)); FileInfo archivedFile = this.fileArchiver.Archive(csvFile, archiveDirectory); if (!archivedFile.Exists) { logger.Warning("Could not archive the CSV File: {0}", archivedFile.FullName); } else { logger.Information("Archive successful: {0}", archivedFile.FullName); } } else { logger.Error("Failed to save the exported excel sheet in the specified location: {0}", saveDestination.FullName); Environment.Exit(0); } } } catch (Exception ex) { logger.Error("Something unexpected happened | Reason: {0}", ex); Environment.Exit(0); } }
public void EverfiExcelTemplate_SaveTemplateTo_ReturnsFalseIfFileAlreadyExist() { FileInfo existingTemplate = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); FileInfo existingFilePathPath = new FileInfo("../../../Utilities/TestData/existingsaveas.xlsx"); var mockLogger = new Mock <ILogger>(); bool didFileSave = true; using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingTemplate, mockLogger.Object)) { didFileSave = excelTemplate.SaveTemplateTo(existingFilePathPath); } Assert.False(didFileSave); }
public void EverfiExcelTemplate_SaveTemplateTo_ReturnsTrueIfFileSaveSuccessful() { FileInfo existingTemplate = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); FileInfo nonexistingFilePath = new FileInfo("../../../Utilities/TestData/nonexistingsaveas.xlsx"); var mockLogger = new Mock <ILogger>(); bool didFileSave = false; using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingTemplate, mockLogger.Object)) { didFileSave = excelTemplate.SaveTemplateTo(nonexistingFilePath); } nonexistingFilePath.Delete(); Assert.True(didFileSave); }
public void EverfiExcelTemplate_ImportCSV_ReturnsTrueIfDataIsImported() { FileInfo existingFilePath = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); FileInfo csvFile = new FileInfo("../../../Utilities/TestData/data.csv"); bool csvDataImported = false; var mockLogger = new Mock <ILogger>(); using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingFilePath, mockLogger.Object)) { ExcelTextFormat format = new ExcelTextFormat(); csvDataImported = excelTemplate.ImportCsv(format, csvFile); } Assert.True(csvDataImported); }
public void EverfiExcelTemplate_ImportFromList_ReturnsFalseIfDataIsEmpty() { FileInfo existingFilePath = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); var mockLogger = new Mock <ILogger>(); bool dataImported = true; List <EverfiUser> userList = new List <EverfiUser>(); using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingFilePath, mockLogger.Object)) { dataImported = excelTemplate.ImportDataFromList(userList); } Assert.False(dataImported); }
public void EverfiExcelTemplate_ImportCSV_ReturnsFalseIfSheetDoesNotExist() { FileInfo existingFilePath = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); FileInfo csvFile = new FileInfo("../../../Utilities/TestData/data.csv"); string wrongSheetName = "Does Not Exist"; bool csvDataImported = true; var mockLogger = new Mock <ILogger>(); using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingFilePath, mockLogger.Object)) { ExcelTextFormat format = new ExcelTextFormat(); excelTemplate.TEMPLATE_SHEET_NAME = wrongSheetName; csvDataImported = excelTemplate.ImportCsv(format, csvFile); } Assert.False(csvDataImported); }
public void EverfiExcelTemplate_SaveTemplateTo_WillLeaveCreatedFileBehind() { FileInfo existingTemplate = new FileInfo("../../../Utilities/TestData/faketemplate.xlsx"); FileInfo nonexistingFilePath = new FileInfo("../../../Utilities/TestData/nonexistingsaveas.xlsx"); var mockLogger = new Mock <ILogger>(); bool doesFileInitiallyExist = nonexistingFilePath.Exists; bool doesFileExistAfterSaveAs = false; using (EverfiExcelTemplate excelTemplate = new EverfiExcelTemplate(existingTemplate, mockLogger.Object)) { excelTemplate.SaveTemplateTo(nonexistingFilePath); nonexistingFilePath.Refresh(); doesFileExistAfterSaveAs = nonexistingFilePath.Exists; } nonexistingFilePath.Delete(); Assert.False(doesFileInitiallyExist); Assert.True(doesFileExistAfterSaveAs); }