forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportedIssues.cs
More file actions
196 lines (171 loc) · 5.08 KB
/
Copy pathReportedIssues.cs
File metadata and controls
196 lines (171 loc) · 5.08 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Collections.Generic;
using NUnit.Framework;
using ServiceStack.ServiceInterface.ServiceModel;
namespace ServiceStack.Text.Tests
{
[TestFixture]
public class ReportedIssues
: TestBase
{
[Test]
public void Issue5_Can_serialize_Dictionary_with_null_value()
{
var map = new Dictionary<string, string> {
{"p1","v1"},{"p2","v2"},{"p3",null},
};
Serialize(map);
}
public abstract class CorrelativeDataBase
{
protected CorrelativeDataBase()
{
CorrelationIdentifier = GetNextId();
}
public Guid CorrelationIdentifier { get; set; }
protected static Guid GetNextId()
{
return Guid.NewGuid();
}
}
public sealed class TestObject : CorrelativeDataBase
{
public Type SomeType { get; set; }
public string SomeString { get; set; }
public IEnumerable<Type> SomeTypeList { get; set; }
public IEnumerable<Type> SomeTypeList2 { get; set; }
public IEnumerable<object> SomeObjectList { get; set; }
}
[Test]
public void Serialize_object_with_type_field()
{
var obj = new TestObject
{
SomeType = typeof(string),
SomeString = "Test",
SomeObjectList = new object[0]
};
Serialize(obj, includeXml: false); // xml cannot serialize Type objects.
}
[Test]
public void Serialize_object_with_type_field2()
{
var obj = new TestObject
{
SomeType = typeof(string),
SomeString = "Test",
SomeObjectList = new object[0]
};
var strModel = TypeSerializer.SerializeToString<object>(obj);
Console.WriteLine("Len: " + strModel.Length + ", " + strModel);
var toModel = TypeSerializer.DeserializeFromString<TestObject>(strModel);
}
public class Article
{
public string title { get; set; }
public string url { get; set; }
public string author { get; set; }
public string author_id { get; set; }
public string date { get; set; }
public string type { get; set; }
}
[Test]
public void Serialize_Dictionary_with_backslash_as_last_char()
{
var map = new Dictionary<string, Article>
{
{
"http://www.eurogamer.net/articles/2010-09-14-vanquish-limited-edition-has-7-figurine",
new Article
{
title = "Vanquish Limited Edition has 7\" figurine",
url = "articles/2010-09-14-vanquish-limited-edition-has-7-figurine",
author = "Wesley Yin-Poole",
author_id = "621",
date = "14/09/2010",
type = "news",
}
},
{
"http://www.eurogamer.net/articles/2010-09-14-supercar-challenge-devs-next-detailed",
new Article
{
title = "SuperCar Challenge dev's next detailed",
url = "articles/2010-09-14-supercar-challenge-devs-next-detailed",
author = "Wesley Yin-Poole",
author_id = "621",
date = "14/09/2010",
type = "news",
}
},
{
"http://www.eurogamer.net/articles/2010-09-14-hmv-to-sell-dead-rising-2-a-day-early",
new Article
{
title = "HMV to sell Dead Rising 2 a day early",
url = "articles/2010-09-14-hmv-to-sell-dead-rising-2-a-day-early",
author = "Wesley Yin-Poole",
author_id = "621",
date = "14/09/2010",
type = "News",
}
},
};
Serialize(map);
var json = JsonSerializer.SerializeToString(map);
var fromJson = JsonSerializer.DeserializeFromString<Dictionary<string, Article>>(json);
Assert.That(fromJson, Has.Count.EqualTo(map.Count));
}
public class Item
{
public int type { get; set; }
public int color { get; set; }
}
public class Basket
{
public Basket()
{
Items = new Dictionary<Item, int>();
}
public Dictionary<Item, int> Items { get; set; }
}
[Test]
public void Can_Serialize_Class_with_Typed_Dictionary()
{
var basket = new Basket();
basket.Items.Add(new Item { type = 1, color = 2 }, 10);
basket.Items.Add(new Item { type = 4, color = 1 }, 20);
Serialize(basket);
}
public class Book
{
public UInt64 Id { get; set; }
public UInt64 OwnerUserId { get; set; }
public String Title { get; set; }
public String Description { get; set; }
public UInt16 CategoryId { get; set; }
public DateTime CreatedDateTime { get; set; }
public Byte Icon { get; set; }
public Boolean Canceled { get; set; }
}
public class BookResponse : IHasResponseStatus
{
public Book Book { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
public object GetBook()
{
var response = new BookResponse();
return response;
}
[Test]
public void Does_not_serialize_typeinfo_for_concrete_types()
{
var json = GetBook().ToJson();
Console.WriteLine(json);
Assert.That(json.IndexOf("__"), Is.EqualTo(-1));
var jsv = GetBook().ToJsv();
Assert.That(jsv.IndexOf("__"), Is.EqualTo(-1));
}
}
}