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