forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicJsonTests.cs
More file actions
35 lines (27 loc) · 1 KB
/
DynamicJsonTests.cs
File metadata and controls
35 lines (27 loc) · 1 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
using NUnit.Framework;
namespace ServiceStack.Text.Tests
{
[TestFixture]
public class DynamicJsonTests
{
[Test]
public void Can_Serialize_dynamic_collection()
{
dynamic rows = new[] { new { Name = "Foo" }, new { Name = "Bar" } };
string json = JsonSerializer.SerializeToString(rows);
Assert.That(json, Is.EqualTo("[{\"Name\":\"Foo\"},{\"Name\":\"Bar\"}]"));
string csv = CsvSerializer.SerializeToString(rows);
Assert.That(csv.NormalizeNewLines(), Is.EqualTo("Name\nFoo\nBar\n"));
}
[Test]
public void Can_deserialize_dynamic_instance()
{
var dog = new { Name = "Spot" };
var json = DynamicJson.Serialize(dog);
Assert.That(json, Is.EqualTo("{\"Name\":\"Spot\"}"));
var deserialized = DynamicJson.Deserialize(json);
Assert.IsNotNull(deserialized);
Assert.That(deserialized.Name, Is.EqualTo(dog.Name));
}
}
}