forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsvSerializerConfigTests.cs
More file actions
43 lines (37 loc) · 1.39 KB
/
CsvSerializerConfigTests.cs
File metadata and controls
43 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using NUnit.Framework;
using ServiceStack.Common.Tests.Models;
using ServiceStack.Text.Common;
namespace ServiceStack.Text.Tests
{
[TestFixture]
public class CsvSerializerConfigTests
{
[Test]
public void Does_use_CsvConfig()
{
CsvConfig.ItemSeperatorString = "|";
CsvConfig.ItemDelimiterString = "`";
CsvConfig.RowSeparatorString = "\n\n";
var dtos = new[] {
new ModelWithIdAndName { Id = 1, Name = "Value" },
new ModelWithIdAndName { Id = 2, Name = "Value|Escaped" },
};
var csv = dtos.ToCsv();
Assert.That(csv, Is.EqualTo("Id|Name\n\n1|Value\n\n2|`Value|Escaped`\n\n"));
var maps = new List<Dictionary<string, object>>()
{
new Dictionary<string,object> { {"Id", "1"}, {"Name", "Value"} },
new Dictionary<string,object> { {"Id", "2"}, {"Name", "Value|Escaped"} },
};
csv = maps.ToCsv();
Assert.That(csv, Is.EqualTo("Id|Name\n\n1|Value\n\n2|`Value|Escaped`\n\n"));
CsvConfig.ItemSeperatorString = JsWriter.ItemSeperatorString;
CsvConfig.ItemDelimiterString = JsWriter.QuoteString;
CsvConfig.RowSeparatorString = Environment.NewLine;
}
}
}