diff options
author | chai <215380520@qq.com> | 2023-05-12 09:24:40 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-05-12 09:24:40 +0800 |
commit | 2a1cd4fda8a4a8e649910d16b4dfa1ce7ae63543 (patch) | |
tree | a471fafed72e80b4ac3ac3002e06c34220dd6058 /ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Writing/WriteNullTests.cs | |
parent | b8a694746562b37dc8dc5b8b5aec8612bb0964fc (diff) |
*misc
Diffstat (limited to 'ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Writing/WriteNullTests.cs')
-rw-r--r-- | ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Writing/WriteNullTests.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Writing/WriteNullTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Writing/WriteNullTests.cs new file mode 100644 index 0000000..7d7f23f --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Writing/WriteNullTests.cs @@ -0,0 +1,84 @@ +using CsvHelper.Configuration; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using Xunit; + +namespace CsvHelper.Tests.Writing +{ + public class WriteNullTests + { + [Fact] + public void WriteRecordsEnumerableGeneric_RecordIsNull_WritesEmptyRecord() + { + var records = new List<Foo> + { + new Foo { Id = 1, Name = "one"}, + null, + new Foo { Id = 2, Name = "two" }, + }; + var config = new CsvConfiguration(CultureInfo.InvariantCulture); + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, config)) + { + csv.WriteRecords(records); + csv.Flush(); + + var expected = new TestStringBuilder(config.NewLine); + expected.AppendLine("Id,Name"); + expected.AppendLine("1,one"); + expected.AppendLine(","); + expected.AppendLine("2,two"); + + Assert.Equal(expected, writer.ToString()); + } + } + + [Fact] + public void WriteRecordsEnumerable_RecordIsNull_WritesEmptyRecord() + { + IEnumerable records = new List<Foo> + { + new Foo { Id = 1, Name = "one"}, + null, + new Foo { Id = 2, Name = "two" }, + }; + var config = new CsvConfiguration(CultureInfo.InvariantCulture); + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, config)) + { + csv.WriteRecords(records); + csv.Flush(); + + var expected = new TestStringBuilder(config.NewLine); + expected.AppendLine("Id,Name"); + expected.AppendLine("1,one"); + expected.AppendLine(""); + expected.AppendLine("2,two"); + + Assert.Equal(expected, writer.ToString()); + } + } + + [Fact] + public void WriteRecord_RecordIsNull_WritesEmptyRecord() + { + var config = new CsvConfiguration(CultureInfo.InvariantCulture); + using (var writer = new StringWriter()) + using (var csv = new CsvWriter(writer, config)) + { + csv.WriteRecord((Foo)null); + csv.Flush(); + + Assert.Equal(",", writer.ToString()); + } + } + + private class Foo + { + public int Id { get; set; } + public string Name { get; set; } + } + } +} |