本文整理汇总了C#中CsvWriter.DefineColumn方法的典型用法代码示例。如果您正苦于以下问题:C# CsvWriter.DefineColumn方法的具体用法?C# CsvWriter.DefineColumn怎么用?C# CsvWriter.DefineColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvWriter
的用法示例。
在下文中一共展示了CsvWriter.DefineColumn方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CsvWriter_WithThreeDefinedColumns_WritesValuesInOrder
public void CsvWriter_WithThreeDefinedColumns_WritesValuesInOrder()
{
// Arrange
CsvWriter<object> writer = new CsvWriter<object>(A.Dummy<IExcelSanitizer>());
writer.DefineColumn("Column 1", x => "Value 1");
writer.DefineColumn("Column 2", x => "Value 2");
writer.DefineColumn("Column 3", x => "Value 3");
object[] data = new object[2];
// Act
string csv = writer.Write(data);
// Assert
string expectedValue =
"Column 1,Column 2,Column 3" + Environment.NewLine +
"Value 1,Value 2,Value 3" + Environment.NewLine +
"Value 1,Value 2,Value 3" + Environment.NewLine;
Assert.Equal(expectedValue, csv);
}
示例2: CsvWriter_WithFuncColumn_UsesFuncToRetrieveValues
public void CsvWriter_WithFuncColumn_UsesFuncToRetrieveValues()
{
// Arrange
CsvWriter<int> writer = new CsvWriter<int>(A.Dummy<IExcelSanitizer>());
writer.DefineColumn("Column 1", x => x * x);
List<int> data = new List<int>() { 1, 2, 3, 4 };
// Act
string csv = writer.Write(data);
// Assert
string expectedValue =
"Column 1" + Environment.NewLine +
"1" + Environment.NewLine +
"4" + Environment.NewLine +
"9" + Environment.NewLine +
"16" + Environment.NewLine;
Assert.Equal(expectedValue, csv);
}
示例3: CsvWriter_WithFormatAsText_EscapesValuesAndWritesAsFormula
public void CsvWriter_WithFormatAsText_EscapesValuesAndWritesAsFormula()
{
// Arrange
CsvWriter<string> writer = new CsvWriter<string>(A.Dummy<IExcelSanitizer>());
writer.DefineColumn("Column 1", x => x, true);
List<string> data = new List<string>() { "01234 555 555", "The man said \"Hello World\" to the dog." };
// Act
string csv = writer.Write(data);
// Assert
string expectedValue =
"Column 1" + Environment.NewLine +
"=\"01234 555 555\"" + Environment.NewLine +
"=\"The man said \"\"Hello World\"\" to the dog.\"" + Environment.NewLine;
Assert.Equal(expectedValue, csv);
}
示例4: CsvWriter_WithExcelSanitizer_SanitizesValues
public void CsvWriter_WithExcelSanitizer_SanitizesValues()
{
// Arrange
IExcelSanitizer sanitizer = A.Fake<IExcelSanitizer>();
A.CallTo(() => sanitizer.IsThreat("Bad String")).Returns(true);
A.CallTo(() => sanitizer.Sanitize("Bad String")).Returns("Sanitized Bad String");
CsvWriter<string> writer = new CsvWriter<string>(sanitizer);
writer.DefineColumn("Column 1", x => x);
List<string> data = new List<string>() { "Good String", "Bad String" };
// Act
string csv = writer.Write(data);
// Assert
string expectedValue =
"Column 1" + Environment.NewLine +
"Good String" + Environment.NewLine +
"Sanitized Bad String" + Environment.NewLine;
Assert.Equal(expectedValue, csv);
}