public void GetTempTableDataTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser); var taskUser = GetTaskUser(); // File location for Test Data var testLocation = @"C:\Development\Evolution\Evolution\Evolution.Tests\Evolution.NuOrderImportServiceTest\TestData"; var files = Directory.GetFiles(testLocation); NuOrderImportService.NuOrderImportService nuOrderImportService = new NuOrderImportService.NuOrderImportService(db); int expected; int actual; foreach (var fileName in files) { var orderLines = nuOrderImportService.ProcessFile(fileName, testCompany.AccountName); List <NuOrderImportTemp> nuOrderImportTemp = nuOrderImportService.MapFileToTemp(testCompany.AccountName, orderLines, taskUser); expected = nuOrderImportTemp.Count; List <NuOrderImportTemp> nuOrderImportTempTableData = nuOrderImportService.GetTempTableData(); actual = nuOrderImportTempTableData.Count; Assert.AreEqual(expected, actual, $"Error: {expected} number of lines in the .csv file, when {actual} were retrieved from the database."); } }
public void NoDetailsInFileTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser); var taskUser = GetTaskUser(); // File location for Test Data var testLocation = @"C:\Development\Evolution\Evolution\Evolution.Tests\Evolution.NuOrderImportServiceTests\TestData\NoLines"; var file = Directory.GetFiles(testLocation); NuOrderImportService.NuOrderImportService service = new NuOrderImportService.NuOrderImportService(db); int expected = 0; int actual; var orderLines = service.ProcessFile(file[0], testCompany.AccountName); List <NuOrderImportTemp> nuOrderImportTempTableData = service.MapFileToTemp(testCompany.AccountName, orderLines, taskUser); actual = (nuOrderImportTempTableData == null || nuOrderImportTempTableData.Count == 0) ? 0 : nuOrderImportTempTableData.Count; Assert.IsTrue(expected == actual, $"Error: {expected} lines were expected when {actual} were found"); }
public override int DoProcessing(string[] args) { var nuOrderImportService = new NuOrderImportService.NuOrderImportService(_db); DataTransferService.DataTransferService dts = new DataTransferService.DataTransferService(_db); int i = 1; var profileName = GetTaskParameter($"DataTransfer{1}", ""); var taskUser = GetTaskUser(); string errorMsg = ""; var config = dts.FindDataTransferConfigurationModel(profileName); if (config == null) { TaskService.WriteTaskLog(this.Task, $"Error: Failed to find Data Transfer configuration '{profileName}' !"); } else { string fileLoc = config.TargetFolder; while (!string.IsNullOrEmpty(fileLoc)) { string businessName = GetTaskParameter($"BusinessName{i}", "");; string[] files = null; try { files = Directory.GetFiles(fileLoc); } catch (Exception ex) { TaskService.WriteTaskLog(this.Task, $"Error: There was a problem getting files from '{fileLoc}'\r\n" + ex, LogSeverity.Severe); } if (files.Length > 0 && files != null) { foreach (string fileName in files) { // ProcessFile TaskService.WriteTaskLog(this.Task, $"Success: Processing file '{fileName}'", LogSeverity.Normal); List <Dictionary <string, string> > orderLines = null; try { orderLines = nuOrderImportService.ProcessFile(fileName, businessName); } catch (Exception ex) { TaskService.WriteTaskLog(this.Task, $"Error: Could not process file '{fileName}'\r\n" + ex, LogSeverity.Severe); } if (orderLines != null || orderLines.Count == 0) { List <NuOrderImportTemp> nuOrderImportTempList = new List <NuOrderImportTemp>(); // MapFileToTemp try { nuOrderImportTempList = nuOrderImportService.MapFileToTemp(businessName, orderLines, taskUser); TaskService.WriteTaskLog(this.Task, $"Success: Saved '{fileName}' temp table", LogSeverity.Normal); // GetTempTableData try { nuOrderImportTempList = nuOrderImportService.GetTempTableData(); } catch (Exception ex) { TaskService.WriteTaskLog(this.Task, $"Error: Failed to get temp data from database\r\n" + ex, LogSeverity.Severe); } // CopyTempToProduction & Move to file to appropriate folder if (nuOrderImportTempList.Count > 0) { try { if (nuOrderImportService.CopyTempDataToProduction(nuOrderImportTempList, businessName)) { TaskService.WriteTaskLog(this.Task, $"Success: Data Saved to Sales tables", LogSeverity.Normal); if (dts.MoveToArchive(config, fileName, ref errorMsg)) { TaskService.WriteTaskLog(this.Task, $"Failed to move to Archive folder\r\n{errorMsg}", LogSeverity.Severe); } else { TaskService.WriteTaskLog(this.Task, $"Successfully moved file '{fileName}' to Archive folder", LogSeverity.Normal); } } else { MoveFileToErrorFolder(dts, config, fileName); } } catch (Exception ex) { TaskService.WriteTaskLog(this.Task, $"Error: Could not copy data to sales table/s\r\n" + ex, LogSeverity.Severe); MoveFileToErrorFolder(dts, config, fileName); } } } catch (Exception ex) { TaskService.WriteTaskLog(this.Task, $"Error: Failed to map '{fileName}'\r\n" + ex, LogSeverity.Severe); MoveFileToErrorFolder(dts, config, fileName); } } else { TaskService.WriteTaskLog(this.Task, $"Error: The file '{fileName}' was empty", LogSeverity.Severe); MoveFileToErrorFolder(dts, config, fileName); } } } else { TaskService.WriteTaskLog(this.Task, $"INFO: There were no files to process.'", LogSeverity.Normal); } i++; profileName = GetTaskParameter($"DataTransfer{i}", ""); config = dts.FindDataTransferConfigurationModel(profileName); fileLoc = (config != null) ? config.TargetFolder : ""; } } return(0); }