public void GetLines() { // Arrange var csvData = new CsvData(); var aListA = new List <string>() { "A1", "A2", "A3", "A4" }; var aListB = new List <string>() { "B1", "B2", "B3", "B4" }; csvData.Add("A", aListA); csvData.Add("B", aListB); // Act var result = csvData.GetLines(); // Assert for (int i = 0; i < aListA.Count; i++) { Assert.Equal(aListA[i], result.ToList()[i]["A"]); Assert.Equal(aListB[i], result.ToList()[i]["B"]); } }
public void Replace() { // Arrange IEnumerable <ITupleReplace> replaces = new List <ITupleReplace>() { CreateReplace("A", "Z"), CreateReplace("B", "V", "B"), }; var csvDataOk = new CsvData(); var aListA = new List <string>() { "A1", "A2", "A3", "A4" }; var aListB = new List <string>() { "AB1", "AB2", "AB3", "AB4" }; csvDataOk.Add("A", aListA); csvDataOk.Add("B", aListB); var lines = csvDataOk.GetLines(); // Act var result = CsvActionCreator.Create( replaces); // Assert foreach (var item in result) { lines.ToList().ForEach(item); } lines.ToList().ForEach( x => { Assert.IsTrue(x["A"].Contains("Z")); Assert.IsTrue(!x["A"].Contains("A")); Assert.IsTrue(x["B"].Contains("Z")); Assert.IsTrue(!x["B"].Contains("A")); Assert.IsTrue(x["B"].Contains("V")); Assert.IsTrue(!x["B"].Contains("B")); } ); }
public static IEnumerable <ICsvLine> AddIntLine(this IEnumerable <ICsvLine> lines, int?repeatValue = null) { var csvData = new CsvData(); var aListA = repeatValue == null ? new List <string>() { "1", "2", "3", "4" } : new List <string>() { repeatValue.ToString(), repeatValue.ToString(), repeatValue.ToString(), repeatValue.ToString() }; csvData.Add("int", aListA); lines = lines.Append(csvData.GetLines().First()); return(lines); }
public static IEnumerable <ICsvLine> AddStringLine(this IEnumerable <ICsvLine> lines, string repeatValue = null) { var csvData = new CsvData(); var aListA = repeatValue == null ? new List <string>() { "S1", "S2", "S3", "S4" } : new List <string>() { repeatValue, repeatValue, repeatValue, repeatValue }; csvData.Add("string", aListA); lines = lines.Append(csvData.GetLines().First()); return(lines); }
public void Types() { // Arrange IEnumerable <ITypeColumn> types = new List <ITypeColumn>() { CreateType(ETypeColumn.text, "Z"), CreateType(ETypeColumn.number, "B"), CreateType(ETypeColumn.number, "C") }; var csvDataOk = new CsvData(); var aListA = new List <string>() { "A1", "A2", "A3", "A4" }; var aListB = new List <string>() { "1", "2", "3", "4" }; var aListC = new List <string>() { "c1", "c2", "c3", "c4" }; csvDataOk.Add("A", aListA); csvDataOk.Add("B", aListB); csvDataOk.Add("C", aListC); var lines = csvDataOk.GetLines(); // Act var result = CsvActionCreator.Create(types).ToList(); foreach (var item in lines) { result[0](item); result[1](item); Assert.ThrowsException <FormatException>(() => result[2](item)); } // Assert }
private IEnumerable <ICsvLine> CreateEmptyLines() { var csvData = new CsvData(); return(csvData.GetLines()); }