public async Task GuessStartRowAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt")))) Assert.AreEqual( 0, await improvedStream.GuessStartRow(65001, "\t", "\"", "", UnitTestInitializeCsv.Token), "BasicCSV.txt"); }
public async Task GuessStartRow12Async() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("SkippingEmptyRowsWithDelimiter.txt")))) Assert.AreEqual( 12, await improvedStream.GuessStartRow(-1, ",", "\"", "", UnitTestInitializeCsv.Token), "SkippingEmptyRowsWithDelimiter.txt"); }
public async Task GuessStartRowWithCommentsAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("LongHeaders.txt")))) Assert.AreEqual( 0, await improvedStream.GuessStartRow(65001, ",", "\"", "#", UnitTestInitializeCsv.Token), "LongHeaders.txt"); }
public void GetFileWriter() { using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { var res = FunctionalDI.GetFileWriter(m_CsvFile, processDisplay); Assert.IsInstanceOfType(res, typeof(IFileWriter)); } }
public void GetFileWriter() { using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { m_StructuredFile.SqlStatement = "dummy"; var res = FunctionalDI.GetFileWriter(m_StructuredFile, processDisplay); Assert.IsInstanceOfType(res, typeof(IFileWriter)); } }
public void GetFileReader() { m_CsvFile.FileName = UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"); using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) using (var res = FunctionalDI.GetFileReader(m_CsvFile, TimeZoneInfo.Local.Id, processDisplay)) { Assert.IsInstanceOfType(res, typeof(IFileReader)); } }
public void GetEncryptedPassphraseTest() { var setting = new CsvFile { Passphrase = "Hello World" }; var test = FunctionalDI.GetEncryptedPassphrase(setting); Assert.AreEqual(setting.Passphrase, test); }
public async Task GuessHeaderSkippingEmptyRowsWithDelimiterAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("SkippingEmptyRowsWithDelimiter.txt")))) { var result = await improvedStream.GuessHasHeader(65001, 0, "#", ",", UnitTestInitializeCsv.Token); Assert.IsFalse(result.Item1); } }
public async Task GuessHeaderAllFormatsAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("AllFormats.txt")))) { var result = await improvedStream.GuessHasHeader(65001, 0, "", "\t", UnitTestInitializeCsv.Token); Assert.IsTrue(result.Item1); Assert.AreEqual("Header seems present", result.Item2); } }
public async Task GuessHeaderBasicEscapedCharactersAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicEscapedCharacters.txt")))) { var result = await improvedStream.GuessHasHeader(65001, 0, "", ",", UnitTestInitializeCsv.Token); Assert.IsFalse(result.Item1); Assert.AreEqual("Headers 'a\\', 'b', 'c', 'd', 'e', 'f' very short", result.Item2); } }
public async Task GuessDelimiterTabAsync() { ICsvFile test = new CsvFile(UnitTestInitializeCsv.GetTestPath("txTranscripts.txt")) { CodePageId = -1 }; test.FileFormat.EscapeCharacter = "\\"; using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual("TAB", (await improvedStream.GuessDelimiter(test.CodePageId, test.SkipRows, test.FileFormat.EscapeCharacter, UnitTestInitializeCsv.Token)).Item1, true); }
public async Task GuessDelimiterQualifierAsync() { ICsvFile test = new CsvFile(UnitTestInitializeCsv.GetTestPath("TextQualifiers.txt")) { CodePageId = -1 }; test.FileFormat.EscapeCharacter = string.Empty; using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual(",", (await improvedStream.GuessDelimiter(test.CodePageId, test.SkipRows, test.FileFormat.EscapeCharacter, UnitTestInitializeCsv.Token)).Item1); }
public async Task GuessDelimiterPipeAsync() { ICsvFile test = new CsvFile(UnitTestInitializeCsv.GetTestPath("DifferentColumnDelimiter.txt")) { CodePageId = -1 }; test.FileFormat.EscapeCharacter = string.Empty; using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual("|", (await improvedStream.GuessDelimiter(-1, 0, string.Empty, UnitTestInitializeCsv.Token)).Item1); }
public async Task GuessHeaderLongHeadersAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("LongHeaders.txt")))) { var result = await improvedStream.GuessHasHeader(65001, 0, "#", ",", UnitTestInitializeCsv.Token); Assert.IsFalse(result.Item1); Assert.IsTrue(result.Item2.StartsWith("Headers", System.StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(result.Item2.EndsWith("very short", System.StringComparison.OrdinalIgnoreCase)); } }
public async Task GuessDelimiterCommaAsync() { ICsvFile test = new CsvFile(UnitTestInitializeCsv.GetTestPath("AlternateTextQualifiers.txt")) { CodePageId = -1 }; test.FileFormat.EscapeCharacter = "\\"; using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual(",", (await improvedStream.GuessDelimiter(-1, 0, "\\", UnitTestInitializeCsv.Token)).Item1); }
public void GetFileReader() { try { using (var dummy = FunctionalDI.GetFileReader(m_StructuredFile, TimeZoneInfo.Local.Id, new CustomProcessDisplay(UnitTestInitializeCsv.Token))) { Assert.Fail("Should throw error"); } } catch (NotImplementedException) { } }
public void GetFileWriterTest() { var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("AlternateTextQualifiers.txt") }; var test = FunctionalDI.GetFileWriter(setting, new CustomProcessDisplay(UnitTestInitializeCsv.Token)); Assert.IsInstanceOfType(test, typeof(CsvFileWriter)); var setting2 = new StructuredFile { FileName = UnitTestInitializeCsv.GetTestPath("AlternateTextQualifiers.txt") }; var test2 = FunctionalDI.GetFileWriter(setting2, new CustomProcessDisplay(UnitTestInitializeCsv.Token)); Assert.IsInstanceOfType(test2, typeof(StructuredFileWriter)); }
public async Task GuessCodePageAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt")))) { Assert.AreEqual(1200, (await improvedStream.GuessCodePage(UnitTestInitializeCsv.Token)).Item1); } using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("UnicodeUTF16BE.txt")))) { Assert.AreEqual(1201, (await improvedStream.GuessCodePage(UnitTestInitializeCsv.Token)).Item1); } using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("UnicodeUTF8.txt")))) { Assert.AreEqual(65001, (await improvedStream.GuessCodePage(UnitTestInitializeCsv.Token)).Item1); } }
public async Task GuessDelimiterAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt")))) Assert.AreEqual(",", (await improvedStream.GuessDelimiter(-1, 0, string.Empty, UnitTestInitializeCsv.Token)).Item1); using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("AllFormatsPipe.txt")))) Assert.AreEqual("|", (await improvedStream.GuessDelimiter(-1, 0, string.Empty, UnitTestInitializeCsv.Token)).Item1); ICsvFile test = new CsvFile(UnitTestInitializeCsv.GetTestPath("LateStartRow.txt")) { SkipRows = 10, CodePageId = 20127 }; test.FileFormat.FieldQualifier = "\""; using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual("|", (await improvedStream.GuessDelimiter(20127, 10, string.Empty, UnitTestInitializeCsv.Token)).Item1); }
public void GetFileReaderTest() { var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("AlternateTextQualifiers.txt") }; using (var test = FunctionalDI.GetFileReader(setting, null, new CustomProcessDisplay(UnitTestInitializeCsv.Token))) { Assert.IsInstanceOfType(test, typeof(CsvFileReader)); } setting.JsonFormat = true; using (var test2 = FunctionalDI.GetFileReader(setting, null, new CustomProcessDisplay(UnitTestInitializeCsv.Token))) { Assert.IsInstanceOfType(test2, typeof(JsonFileReader)); } }
public void AdjustTZTest() { var srcTime = new DateTime(2020, 02, 20); // time zone we convert to can not be changed... var test1 = FunctionalDI.AdjustTZImport(srcTime, "Hawaiian Standard Time", 1, null); // as the time of the system is not know, we do not know what we are converting to, people in Hawaiian would need no difference Assert.IsNotNull(test1); // Convert back should give us the original value though var test2 = FunctionalDI.AdjustTZExport(test1, "Hawaiian Standard Time", 1, null); Assert.AreEqual(srcTime, test2); var test3 = FunctionalDI.AdjustTZImport(srcTime, null, 1, null); Assert.AreEqual(srcTime, test3); var test4 = FunctionalDI.AdjustTZImport(srcTime, TimeZoneInfo.Local.Id, 1, null); Assert.AreEqual(srcTime, test4); }
public async Task <IFileReader> ReadDataAsync(string settingName, EventHandler <ProgressEventArgs> message, int timeout, CancellationToken token) { if (m_ReadSetting.Count == 0) { message.Invoke(null, new ProgressEventArgs($"{settingName} not found")); throw new ApplicationException($"{settingName} not found"); } var setting = m_ReadSetting.Any(x => x.Key.ID == settingName) ? m_ReadSetting.First(x => x.Key.ID == settingName) : m_ReadSetting.First(); using (var dummy = new CustomProcessDisplay(token)) { var reader = setting.Value != null ? new DataTableWrapper(setting.Value) : FunctionalDI.GetFileReader(setting.Key, null, dummy); await reader.OpenAsync(token).ConfigureAwait(false); return(reader); } }
public async Task GuessQualifierAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("TextQualifiers.txt")))) Assert.AreEqual("\"", await improvedStream.GuessQualifier(65001, 0, "\t", UnitTestInitializeCsv.Token)); }
public async Task HasUsedQualifierTrueAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("AlternateTextQualifiers.txt")))) Assert.IsTrue(await improvedStream.HasUsedQualifier(65001, 0, "\t", "\"", UnitTestInitializeCsv.Token)); }
public async Task HasUsedQualifierFalseAsync() { using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt")))) Assert.IsFalse(await improvedStream.HasUsedQualifier(65001, 0, "\t", "\"", UnitTestInitializeCsv.Token)); }
public async Task GuessNewlineTest() { // Storing Text file with given line ends is tricky, editor and source control might change // them therefore creating the text files in code var path = UnitTestInitializeCsv.GetTestPath("writeTestFile.txt"); try { FileSystemUtils.FileDelete(path); using (var file = File.CreateText(path)) { await file.WriteAsync("ID\tTitle\tObject ID\n"); await file.WriteAsync("12367890\t\"5\rOverview\"\tc41f21c8-d2cc-472b-8cd9-707ddd8d24fe\n"); file.Write("3ICC\t10/14/2010\t0e413ed0-3086-47b6-90f3-836a24f7cb2e\n"); file.Write("3SOF\t\"3 Overview\"\taff9ed00-016e-4202-a3df-27a3ce443e80\n"); file.Write("3T1SA\t3 Phase 1\t8d527a23-2777-4754-a73d-029f67abe715\n"); await file.WriteAsync("3T22A\t3 Phase 2\tf9a99add-4cc2-4e41-a29f-a01f5b3b61b2\n"); file.Write("3T25C\t3 Phase 2\tab416221-9f79-484e-a7c9-bc9a375a6147\n"); file.Write("7S721A\t\"7 راز\"\t2b9d291f-ce76-4947-ae7b-fec3531d1766\n"); file.Write("#Hello\t7th Heaven\t1d5b894b-95e6-4026-9ffe-64197e79c3d1\n"); } var test = new CsvFile(path) { CodePageId = 65001, FileFormat = { FieldQualifier = "\"" } }; using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual(RecordDelimiterType.LF, await improvedStream.GuessNewline(test.CodePageId, test.SkipRows, test.FileFormat.FieldQualifier, UnitTestInitializeCsv.Token)); FileSystemUtils.FileDelete(path); using (var file = File.CreateText(path)) { await file.WriteAsync("ID\tTitle\tObject ID\u001E"); await file.WriteAsync("12367890\t\"5\rOverview\"\tc41f21c8-d2cc-472b-8cd9-707ddd8d24fe\u001E"); file.Write("3ICC\t10/14/2010\t0e413ed0-3086-47b6-90f3-836a24f7cb2e\u001E"); file.Write("3SOF\t\"3 Overview\"\taff9ed00-016e-4202-a3df-27a3ce443e80\u001E"); file.Write("3T1SA\t3 Phase 1\t8d527a23-2777-4754-a73d-029f67abe715\u001E"); file.Write("3T22A\t3 Phase 2\tf9a99add-4cc2-4e41-a29f-a01f5b3b61b2\u001E"); file.Write("3T25C\t3 Phase 2\tab416221-9f79-484e-a7c9-bc9a375a6147\u001E"); file.Write("7S721A\t\"7 راز\"\t2b9d291f-ce76-4947-ae7b-fec3531d1766\u001E"); file.Write("#Hello\t7th Heaven\t1d5b894b-95e6-4026-9ffe-64197e79c3d1\u001E"); } using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual(RecordDelimiterType.RS, await improvedStream.GuessNewline(test.CodePageId, test.SkipRows, test.FileFormat.FieldQualifier, UnitTestInitializeCsv.Token)); FileSystemUtils.FileDelete(path); using (var file = File.CreateText(path)) { await file.WriteAsync("ID\tTitle\tObject ID\n\r"); await file.WriteAsync("12367890\t\"5\nOverview\"\tc41f21c8-d2cc-472b-8cd9-707ddd8d24fe\n\r"); file.Write("3ICC\t10/14/2010\t0e413ed0-3086-47b6-90f3-836a24f7cb2e\n\r"); file.Write("3SOF\t\"3 Overview\"\taff9ed00-016e-4202-a3df-27a3ce443e80\n\r"); file.Write("3T1SA\t3 Phase 1\t8d527a23-2777-4754-a73d-029f67abe715\n\r"); file.Write("3T22A\t3 Phase 2\tf9a99add-4cc2-4e41-a29f-a01f5b3b61b2\n\r"); file.Write("3T25C\t3 Phase 2\tab416221-9f79-484e-a7c9-bc9a375a6147\n\r"); file.Write("7S721A\t\"7 راز\"\t2b9d291f-ce76-4947-ae7b-fec3531d1766\n\r"); file.Write("#Hello\t7th Heaven\t1d5b894b-95e6-4026-9ffe-64197e79c3d1\n\r"); } using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual(RecordDelimiterType.LFCR, await improvedStream.GuessNewline(test.CodePageId, test.SkipRows, test.FileFormat.FieldQualifier, UnitTestInitializeCsv.Token)); FileSystemUtils.FileDelete(path); using (var file = File.CreateText(path)) { await file.WriteAsync("ID\tTitle\tObject ID\r\n"); await file.WriteAsync("12367890\t\"5\nOverview\"\tc41f21c8-d2cc-472b-8cd9-707ddd8d24fe\r\n"); file.Write("3ICC\t10/14/2010\t0e413ed0-3086-47b6-90f3-836a24f7cb2e\r\n"); file.Write("3SOF\t\"3 Overview\"\taff9ed00-016e-4202-a3df-27a3ce443e80\r\n"); file.Write("3T1SA\t3 Phase 1\t8d527a23-2777-4754-a73d-029f67abe715\r\n"); await file.WriteAsync("3T22A\t3 Phase 2\tf9a99add-4cc2-4e41-a29f-a01f5b3b61b2\r\n"); file.Write("3T25C\t3 Phase 2\tab416221-9f79-484e-a7c9-bc9a375a6147\r\n"); file.Write("7S721A\t\"7 راز\"\t2b9d291f-ce76-4947-ae7b-fec3531d1766\r\n"); await file.WriteAsync("#Hello\t7th Heaven\t1d5b894b-95e6-4026-9ffe-64197e79c3d1\r\n"); } using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(test))) Assert.AreEqual(RecordDelimiterType.CRLF, await improvedStream.GuessNewline(test.CodePageId, test.SkipRows, test.FileFormat.FieldQualifier, UnitTestInitializeCsv.Token)); } finally { FileSystemUtils.FileDelete(path); } }