public FieldParser(FileType fileType, DelimiterType delimiterType, TextQualifierType textQualifierType, string otherDelimiter, string fixedFieldLengths) { this.fileType = fileType; this.delimiterType = delimiterType; this.textQualifierType = textQualifierType; this.otherDelimiter = otherDelimiter; this.fixedFieldLengths = fixedFieldLengths; }
private void FieldsAsStringsTester( string textQualifierInFile, TextQualifierType textQualifierForComponent, Tuple <string, string, string>[] expectedResults, DelimiterType delimiterType, string otherDelimiter = "", bool loopResults = false) { string delimiter = ""; switch (delimiterType) { case DelimiterType.Comma: delimiter = ","; break; case DelimiterType.Tab: delimiter = "\t"; break; case DelimiterType.Other: delimiter = otherDelimiter; break; default: throw new Exception("Unexpected DelimiterType " + delimiterType); } string fileName = WriteTextToFile(String.Format("{1}a{1}{0}b{0}c\r\n{1}d{1}{0}e{0}f\r\n{1}g{1}{0}h{0}{1}{1}", delimiter, textQualifierInFile)); var fields = new TextFileReaderFields(); fields.Delimiter = delimiterType; if (delimiterType == DelimiterType.Other) { fields.OtherDelimiter = otherDelimiter; } fields.TextQualifier = textQualifierForComponent; var fieldCollection = new AfieldCollection(); fieldCollection.Add(new Afield { Name = "Field1" }); fieldCollection.Add(new Afield { Name = "Field2" }); fieldCollection.Add(new Afield { Name = "Field3" }); fields.FieldList = fieldCollection; FunctionResult output = Execute(fileName, loopResults ? FileReadOptions.LineByLine : FileReadOptions.ListOfLines, fields); if (loopResults) { List <NextResult> resultList = ((IEnumerable <NextResult>)output.ExecutionPathResult).ToList(); for (int i = 0; i < expectedResults.Length; i++) { Assert.AreEqual(expectedResults[i].Item1, resultList[i].Value.LineContents.Field1); Assert.AreEqual(expectedResults[i].Item2, resultList[i].Value.LineContents.Field2); Assert.AreEqual(expectedResults[i].Item3, resultList[i].Value.LineContents.Field3); } } else { dynamic results = output.Value; for (int i = 0; i < expectedResults.Length; i++) { Assert.AreEqual(expectedResults[i].Item1, results[i].Field1); Assert.AreEqual(expectedResults[i].Item2, results[i].Field2); Assert.AreEqual(expectedResults[i].Item3, results[i].Field3); } } }