当前位置: 首页>>代码示例>>C#>>正文


C# CsvWriter.DefineColumn方法代码示例

本文整理汇总了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);
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:22,代码来源:CsvWriterTests.cs

示例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);
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:22,代码来源:CsvWriterTests.cs

示例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);
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:20,代码来源:CsvWriterTests.cs

示例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);
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:24,代码来源:CsvWriterTests.cs


注:本文中的CsvWriter.DefineColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。