/// <summary> /// Startup here /// </summary> /// <param name="csvFileSetting"></param> public void Run(CsvFileSetting csvFileSetting) { Console.WriteLine($"Applcation start: {DateTime.Now}"); Console.WriteLine("------------------------------------------------------"); try { var files = Directory.GetFiles(csvFileSetting.FilePath, "*.csv", SearchOption.TopDirectoryOnly); foreach (var file in files) { var fileName = Path.GetFileName(file); // Check file type var isLpFile = fileName.StartsWith(csvFileSetting.LpFilePrefix); var isTouFile = fileName.StartsWith(csvFileSetting.TouFilePrefix); var records = isLpFile ? _csvParserService.ReadCsvFileToCsvModel(file, new LpMap()) : isTouFile ? _csvParserService.ReadCsvFileToCsvModel(file, new TouMap()) : new List <CsvModel>(); // Skip unknown CSV file if (!records.Any()) { Console.WriteLine($"*** Unknown file type: {fileName}"); continue; } // Filter records var medianValue = _calculationService.GetMedianValue(records.Select(x => x.DataValue).ToList()); var percentValue = csvFileSetting.DetectPercentage / 100.0; var exceedingRecords = _calculationService.GetExceedingRecords(records, medianValue, percentValue); // Display filtered records OutputRecords(fileName, exceedingRecords, medianValue); } Console.WriteLine("------------------------------------------------------"); Console.WriteLine($"Application end: {DateTime.Now}"); } catch (Exception ex) { Console.WriteLine($"Unexpect exception: {ex.Message}"); } }
public void GivenLpCsvContent_WhenImported_ThenDataReturned() { // Arrange var csvContentBuilder = GetCsvContentBuilder(); var lpCsvBuilder = new StringBuilder(); lpCsvBuilder.AppendLine("Date/Time,Data Value"); lpCsvBuilder.Append(csvContentBuilder); var anyPath = "anyPath"; var ms = new MemoryStream(Encoding.UTF8.GetBytes(lpCsvBuilder.ToString())); _fileStreamReader.Setup(sr => sr.GetStreamReader(anyPath)).Returns(new StreamReader(ms)); // Act var results = _csvParserService.ReadCsvFileToCsvModel(anyPath, new LpMap()); // Assert Assert.True(results.Any()); }