forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicObjectTests.cs
More file actions
69 lines (57 loc) · 1.79 KB
/
DynamicObjectTests.cs
File metadata and controls
69 lines (57 loc) · 1.79 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace ServiceStack.Text.Tests
{
[TestFixture]
public class DynamicObjectTests
: TestBase
{
public class UrlStatus
{
public int Status { get; set; }
public string Url { get; set; }
}
[Test]
public void Dictionary_Object_UrlStatus()
{
var urlStatus = new UrlStatus {
Status = 301,
Url = "http://www.ehow.com/how_5615409_create-pdfs-using-bean.html",
};
var map = new Dictionary<string, object>
{
{"Status","OK"},
{"Url","http://www.ehow.com/m/how_5615409_create-pdfs-using-bean.html"},
{"Parent Url","http://www.ehow.com/mobilearticle35.xml"},
{"Redirect Chai", urlStatus},
};
var json = JsonSerializer.SerializeToString(map);
var fromJson = JsonSerializer.DeserializeFromString<Dictionary<string, object>>(json);
Assert.That(fromJson["Status"], Is.EqualTo(map["Status"]));
Assert.That(fromJson["Url"], Is.EqualTo(map["Url"]));
Assert.That(fromJson["Parent Url"], Is.EqualTo(map["Parent Url"]));
var actualStatus = (UrlStatus)fromJson["Redirect Chai"];
Assert.That(actualStatus.Status, Is.EqualTo(urlStatus.Status));
Assert.That(actualStatus.Url, Is.EqualTo(urlStatus.Url));
Console.WriteLine("JSON: " + json);
}
public class PocoWithKvp
{
public KeyValuePair<string, string>[] Values { get; set; }
}
[Test]
public void Can_Serailize_KVP_array()
{
var kvpArray = new[] {
new KeyValuePair<string, string>("Key", "Foo"),
new KeyValuePair<string, string>("Value", "Bar"),
};
var dto = new PocoWithKvp {
Values = kvpArray
};
Console.WriteLine(dto.ToJson());
Serialize(dto, includeXml: false);
}
}
}