public void VerifyLeadingCharsRemoved() { string actual = string.Empty; string[] record = {",954999991", " _teststu01", "Student01"}; CsvFormat target = new CsvFormat(); target.FieldSeparator = "|"; char[] trimStartChars = new[] {',', ' '}; target.FieldTrimLeadingChars = trimStartChars; DataTable table = new DataTable(); table.Columns.Add("SID", typeof(string)); table.Columns.Add("Username", typeof(string)); table.Columns.Add("Last Name", typeof(string)); table.Rows.Add(record); using (DataSet ds = new DataSet()) { ds.Tables.Add(table); actual = target.Serialize(ds); } string expected = string.Empty; foreach (string s in record) { if (string.IsNullOrWhiteSpace(expected)) { expected = s.TrimStart(trimStartChars); } else { expected = string.Concat(expected, "|", s.TrimStart(trimStartChars)); } } Assert.AreEqual(string.Concat(expected, Environment.NewLine), actual); }
public void SerializeToPipeSeparated() { string actual = string.Empty; string expected = "954999991|_teststu01|Student01"; CsvFormat target = new CsvFormat(); target.FieldSeparator = "|"; DataTable table = new DataTable(); table.Columns.Add("SID", typeof(string)); table.Columns.Add("Username", typeof(string)); table.Columns.Add("Last Name", typeof(string)); table.Rows.Add(expected.Split('|')); using (DataSet ds = new DataSet()) { ds.Tables.Add(table); actual = target.Serialize(ds); } Assert.AreEqual(string.Concat(expected, Environment.NewLine), actual); }