/
JsonData.cs
191 lines (163 loc) · 6.62 KB
/
JsonData.cs
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
using System;
using System.Linq;
using RestSharp.Tests.SampleClasses;
namespace RestSharp.Tests.TestData
{
public static class JsonData
{
public const string GUID_STRING = "AC1FC4BC-087A-4242-B8EE-C53EBE9887A5";
public static string JsonWithNullValues =
new JsonObject {["Id"] = null, ["StartDate"] = null, ["UniqueId"] = null}.ToString();
public static string JsonWithEmptyValues =
new JsonObject {["Id"] = "", ["StartDate"] = "", ["UniqueId"] = ""}.ToString();
public static string CreateJsonWithoutEmptyValues =
new JsonObject
{
["Id"] = 123,
["StartDate"] = new DateTime(2010, 2, 21, 9, 35, 00, DateTimeKind.Utc),
["UniqueId"] = new Guid(GUID_STRING).ToString()
}.ToString();
public static string JsonStringDictionary =
new JsonObject
{
["Thing1"] = "Thing1", ["Thing2"] = "Thing2", ["ThingRed"] = "ThingRed", ["ThingBlue"] = "ThingBlue"
}.ToString();
public static string DynamicJsonStringDictionary =
new JsonObject
{
["Thing1"] = new JsonArray {"Value1", "Value2"},
["Thing2"] = "Thing2",
["ThingRed"] = new JsonObject {{"Name", "ThingRed"}, {"Color", "Red"}},
["ThingBlue"] = new JsonObject {{"Name", "ThingBlue"}, {"Color", "Blue"}}
}.ToString();
public static readonly string UnixDateJson = new JsonObject {["Value"] = 1309421746}.ToString();
public static readonly string UnixDateMillisecondsJson = new JsonObject {["Value"] = 1309421746000}.ToString();
public static string CreateJsonWithUnderscores()
{
var doc = new JsonObject
{
["name"] = "John Sheehan",
["start_date"] = new DateTime(2009, 9, 25, 0, 6, 1, DateTimeKind.Utc),
["age"] = 28,
["percent"] = 99.9999m,
["big_number"] = long.MaxValue,
["is_cool"] = false,
["ignore"] = "dummy",
["read_only"] = "dummy",
["url"] = "http://example.com",
["url_path"] = "/foo/bar",
["best_friend"] = new JsonObject {{"name", "The Fonz"}, {"since", 1952}}
};
var friendsArray = new JsonArray();
friendsArray.AddRange(
Enumerable.Range(0, 10)
.Select(
i =>
new JsonObject
{
{"name", "Friend" + i},
{"since", DateTime.Now.Year - i}
}
)
);
doc["friends"] = friendsArray;
doc["foes"] =
new JsonObject
{
{"dict1", new JsonObject {{"nickname", "Foe 1"}}},
{"dict2", new JsonObject {{"nickname", "Foe 2"}}}
};
return doc.ToString();
}
public static string CreateJsonWithDashes()
{
var doc = new JsonObject
{
["name"] = "John Sheehan",
["start-date"] = new DateTime(2009, 9, 25, 0, 6, 1, DateTimeKind.Utc),
["age"] = 28,
["percent"] = 99.9999m,
["big-number"] = long.MaxValue,
["is-cool"] = false,
["ignore"] = "dummy",
["read-only"] = "dummy",
["url"] = "http://example.com",
["url-path"] = "/foo/bar",
["best-friend"] = new JsonObject {{"name", "The Fonz"}, {"since", 1952}}
};
var friendsArray = new JsonArray();
friendsArray.AddRange(
Enumerable.Range(0, 10)
.Select(
i =>
new JsonObject
{
{"name", "Friend" + i},
{"since", DateTime.Now.Year - i}
}
)
);
doc["friends"] = friendsArray;
doc["foes"] =
new JsonObject
{
{"dict1", new JsonObject {{"nickname", "Foe 1"}}},
{"dict2", new JsonObject {{"nickname", "Foe 2"}}}
};
return doc.ToString();
}
public static string CreateJsonWithDoubleUppercase()
{
var doc = new JsonObject
{
["personID"] = 435,
};
return doc.ToString();
}
public static string CreateJson()
{
var doc = new JsonObject
{
["Name"] = "John Sheehan",
["StartDate"] = new DateTime(2009, 9, 25, 0, 6, 1, DateTimeKind.Utc),
["Age"] = 28,
["Percent"] = 99.9999m,
["BigNumber"] = long.MaxValue,
["IsCool"] = false,
["Ignore"] = "dummy",
["ReadOnly"] = "dummy",
["Url"] = "http://example.com",
["UrlPath"] = "/foo/bar",
["Order"] = "third",
["Disposition"] = "so_so",
["Guid"] = new Guid(GUID_STRING).ToString(),
["EmptyGuid"] = "",
["BestFriend"] = new JsonObject {{"Name", "The Fonz"}, {"Since", 1952}}
};
var friendsArray = new JsonArray();
for (var i = 0; i < 10; i++)
friendsArray.Add(
new JsonObject
{
{"Name", "Friend" + i},
{"Since", DateTime.Now.Year - i}
}
);
doc["Friends"] = friendsArray;
var foesArray = new JsonObject
{
{"dict1", new JsonObject {{"nickname", "Foe 1"}}},
{"dict2", new JsonObject {{"nickname", "Foe 2"}}}
};
doc["Foes"] = foesArray;
return doc.ToString();
}
public static string CreateIsoDateJson()
=> SimpleJson.SerializeObject(
new Birthdate
{
Value = new DateTime(1910, 9, 25, 9, 30, 25, DateTimeKind.Utc)
}
);
}
}