Skip to content

Commit 3d3f849

Browse files
committed
merge conflicts
2 parents e263840 + a46abc9 commit 3d3f849

24 files changed

+279
-71
lines changed

RestSharp.MonoDroid/RestSharp.MonoDroid.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
<Compile Include="..\RestSharp\RestResponse.cs">
9797
<Link>RestResponse.cs</Link>
9898
</Compile>
99+
<Compile Include="..\RestSharp\SimpleJson.cs">
100+
<Link>SimpleJson.cs</Link>
101+
</Compile>
99102
<Compile Include="..\RestSharp\Validation\Require.cs">
100103
<Link>Validation\Require.cs</Link>
101104
</Compile>
@@ -126,6 +129,9 @@
126129
<Compile Include="..\RestSharp\Extensions\XmlExtensions.cs">
127130
<Link>Extensions\XmlExtensions.cs</Link>
128131
</Compile>
132+
<Compile Include="..\RestSharp\Extensions\ResponseExtensions.cs">
133+
<Link>Extensions\ResponseExtensions.cs</Link>
134+
</Compile>
129135
<Compile Include="..\RestSharp\Deserializers\DeserializeAsAttribute.cs">
130136
<Link>Deserializers\DeserializeAsAttribute.cs</Link>
131137
</Compile>

RestSharp.MonoTouch/RestSharp.MonoTouch.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@
143143
<Compile Include="..\RestSharp\RestResponse.cs">
144144
<Link>RestResponse.cs</Link>
145145
</Compile>
146+
<Compile Include="..\RestSharp\SimpleJson.cs">
147+
<Link>SimpleJson.cs</Link>
148+
</Compile>
146149
<Compile Include="..\RestSharp\Validation\Require.cs">
147150
<Link>Validation\Require.cs</Link>
148151
</Compile>
@@ -158,6 +161,9 @@
158161
<Compile Include="..\RestSharp\Serializers\SerializeAsAttribute.cs">
159162
<Link>Serializers\SerializeAsAttribute.cs</Link>
160163
</Compile>
164+
<Compile Include="..\RestSharp\Extensions\ResponseExtensions.cs">
165+
<Link>Extensions\ResponseExtensions.cs</Link>
166+
</Compile>
161167
<Compile Include="..\RestSharp\Serializers\XmlSerializer.cs">
162168
<Link>Serializers\XmlSerializer.cs</Link>
163169
</Compile>

RestSharp.Silverlight/RestSharp.Silverlight.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
<Compile Include="..\RestSharp\Extensions\ReflectionExtensions.cs">
104104
<Link>Extensions\ReflectionExtensions.cs</Link>
105105
</Compile>
106+
<Compile Include="..\RestSharp\Extensions\ResponseExtensions.cs">
107+
<Link>Extensions\ResponseExtensions.cs</Link>
108+
</Compile>
106109
<Compile Include="..\RestSharp\Extensions\StringExtensions.cs">
107110
<Link>Extensions\StringExtensions.cs</Link>
108111
</Compile>

RestSharp.Tests/CultureChange.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Threading;
4+
5+
namespace RestSharp.Tests
6+
{
7+
public class CultureChange : IDisposable
8+
{
9+
public CultureInfo PreviousCulture { get; private set; }
10+
11+
public CultureChange(string culture)
12+
{
13+
if (culture == null)
14+
throw new ArgumentNullException("culture");
15+
16+
PreviousCulture = Thread.CurrentThread.CurrentCulture;
17+
18+
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
19+
}
20+
21+
#region IDisposable Members
22+
23+
public void Dispose()
24+
{
25+
if (PreviousCulture != null)
26+
{
27+
Thread.CurrentThread.CurrentCulture = PreviousCulture;
28+
29+
PreviousCulture = null;
30+
}
31+
}
32+
33+
#endregion
34+
}
35+
}

RestSharp.Tests/JsonTests.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ namespace RestSharp.Tests
3030
{
3131
public class JsonTests
3232
{
33-
private const string GuidString = "AC1FC4BC-087A-4242-B8EE-C53EBE9887A5";
33+
private const string AlternativeCulture = "pt-PT";
34+
35+
private const string GuidString = "AC1FC4BC-087A-4242-B8EE-C53EBE9887A5";
3436

3537
[Fact]
3638
public void Can_Deserialize_4sq_Json_With_Root_Element_Specified()
@@ -126,7 +128,7 @@ public void Can_Deserialize_Elements_to_Nullable_Values()
126128
[Fact]
127129
public void Can_Deserialize_Custom_Formatted_Date()
128130
{
129-
var culture = CultureInfo.InvariantCulture;
131+
var culture = CultureInfo.InvariantCulture;
130132
var format = "dd yyyy MMM, hh:mm ss tt";
131133
var date = new DateTime(2010, 2, 8, 11, 11, 11);
132134

@@ -233,6 +235,15 @@ public void Can_Deserialize_With_Default_Root()
233235
Assert.Equal("Foe 2", p.Foes["dict2"].Nickname);
234236
}
235237

238+
[Fact]
239+
public void Can_Deserialize_With_Default_Root_Alternative_Culture()
240+
{
241+
using (new CultureChange(AlternativeCulture))
242+
{
243+
Can_Deserialize_With_Default_Root();
244+
}
245+
}
246+
236247
[Fact]
237248
public void Can_Deserialize_Names_With_Underscores_With_Default_Root()
238249
{
@@ -262,6 +273,15 @@ public void Can_Deserialize_Names_With_Underscores_With_Default_Root()
262273
Assert.Equal("Foe 2", p.Foes["dict2"].Nickname);
263274
}
264275

276+
[Fact]
277+
public void Can_Deserialize_Names_With_Underscores_With_Default_Root_Alternative_Culture()
278+
{
279+
using (new CultureChange(AlternativeCulture))
280+
{
281+
Can_Deserialize_Names_With_Underscores_With_Default_Root();
282+
}
283+
}
284+
265285
[Fact]
266286
public void Can_Deserialize_Names_With_Dashes_With_Default_Root()
267287
{
@@ -291,6 +311,15 @@ public void Can_Deserialize_Names_With_Dashes_With_Default_Root()
291311
Assert.Equal("Foe 2", p.Foes["dict2"].Nickname);
292312
}
293313

314+
[Fact]
315+
public void Can_Deserialize_Names_With_Dashes_With_Default_Root_Alternative_Culture()
316+
{
317+
using (new CultureChange(AlternativeCulture))
318+
{
319+
Can_Deserialize_Names_With_Dashes_With_Default_Root();
320+
}
321+
}
322+
294323
[Fact]
295324
public void Ignore_Protected_Property_That_Exists_In_Data()
296325
{
@@ -313,6 +342,24 @@ public void Ignore_ReadOnly_Property_That_Exists_In_Data()
313342
Assert.Null(p.ReadOnlyProxy);
314343
}
315344

345+
[Fact]
346+
public void Can_Deserialize_TimeSpan()
347+
{
348+
var doc = File.ReadAllText(Path.Combine("SampleData", "timespans.txt"));
349+
var d = new JsonDeserializer();
350+
var response = new RestResponse { Content = doc };
351+
var payload = d.Deserialize<TimeSpanTestStructure>(response);
352+
353+
Assert.Equal(new TimeSpan(468006), payload.Tick);
354+
Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
355+
Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
356+
Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
357+
Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
358+
Assert.Null(payload.NullableWithoutValue);
359+
Assert.NotNull(payload.NullableWithValue);
360+
Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
361+
}
362+
316363
[Fact]
317364
public void Can_Deserialize_Iso_Json_Dates()
318365
{

RestSharp.Tests/RestSharp.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
</Reference>
7979
</ItemGroup>
8080
<ItemGroup>
81+
<Compile Include="CultureChange.cs" />
8182
<Compile Include="JsonTests.cs" />
8283
<Compile Include="Fakes\NullHttp.cs" />
8384
<Compile Include="NamespacedXmlTests.cs" />
@@ -151,6 +152,9 @@
151152
<Content Include="SampleData\Lastfm.xml">
152153
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
153154
</Content>
155+
<Content Include="SampleData\timespans.txt">
156+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
157+
</Content>
154158
<Content Include="SampleData\xmllists.xml">
155159
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
156160
</Content>

RestSharp.Tests/SampleClasses/misc.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ public class DateTimeTestStructure
154154
public DateTimeOffset? NullableDateTimeOffsetWithValue { get; set; }
155155
}
156156

157+
public class TimeSpanTestStructure
158+
{
159+
public TimeSpan Tick { get; set; }
160+
public TimeSpan Millisecond { get; set; }
161+
public TimeSpan Second { get; set; }
162+
public TimeSpan Minute { get; set; }
163+
public TimeSpan Hour { get; set; }
164+
public TimeSpan? NullableWithoutValue { get; set; }
165+
public TimeSpan? NullableWithValue { get; set; }
166+
}
167+
157168
public class JsonEnumsTestStructure
158169
{
159170
public Disposition Upper { get; set; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Tick": "00:00:00.0468006",
3+
"Millisecond": "00:00:00.1250000",
4+
"Second": "00:00:08.0000000",
5+
"Minute": "00:55:02.0000000",
6+
"Hour": "21:30:07.0000000",
7+
"NullableWithoutValue": null,
8+
"NullableWithValue": "21:30:07.0000000",
9+
}

RestSharp.Tests/XmlTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,48 @@ public void Can_Deserialize_Elements_to_Nullable_Values()
254254
Assert.Equal(new Guid(GuidString), output.UniqueId);
255255
}
256256

257+
[Fact]
258+
public void Can_Deserialize_TimeSpan()
259+
{
260+
var culture = CultureInfo.InvariantCulture;
261+
var doc = new XDocument(culture);
262+
263+
TimeSpan? nullTimespan = null;
264+
TimeSpan? nullValueTimeSpan = new TimeSpan(21, 30, 7);
265+
266+
var root = new XElement("Person");
267+
root.Add(new XElement("Tick", new TimeSpan(468006)));
268+
root.Add(new XElement("Millisecond", new TimeSpan(0, 0, 0, 0, 125)));
269+
root.Add(new XElement("Second", new TimeSpan(0, 0, 8)));
270+
root.Add(new XElement("Minute", new TimeSpan(0, 55, 2)));
271+
root.Add(new XElement("Hour", new TimeSpan(21, 30, 7)));
272+
root.Add(new XElement("NullableWithoutValue", nullTimespan));
273+
root.Add(new XElement("NullableWithValue", nullValueTimeSpan));
274+
275+
doc.Add(root);
276+
277+
var xml = new XmlDeserializer
278+
{
279+
Culture = culture,
280+
};
281+
282+
var response = new RestResponse { Content = doc.ToString() };
283+
284+
var d = new XmlDeserializer()
285+
{
286+
Culture = culture,
287+
};
288+
var payload = d.Deserialize<TimeSpanTestStructure>(response);
289+
Assert.Equal(new TimeSpan(468006), payload.Tick);
290+
Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
291+
Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
292+
Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
293+
Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
294+
Assert.Null(payload.NullableWithoutValue);
295+
Assert.NotNull(payload.NullableWithValue);
296+
Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
297+
}
298+
257299
[Fact]
258300
public void Can_Deserialize_Custom_Formatted_Date()
259301
{

RestSharp.WindowsPhone.Mango/RestSharp.WindowsPhone.Mango.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@
186186
<Compile Include="..\restsharp\extensions\StringExtensions.cs">
187187
<Link>Extensions\StringExtensions.cs</Link>
188188
</Compile>
189+
<Compile Include="..\RestSharp\Extensions\ResponseExtensions.cs">
190+
<Link>Extensions\ResponseExtensions.cs</Link>
191+
</Compile>
189192
<Compile Include="..\restsharp\extensions\XmlExtensions.cs">
190193
<Link>Extensions\XmlExtensions.cs</Link>
191194
</Compile>

RestSharp.WindowsPhone/RestSharp.WindowsPhone.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@
176176
<Compile Include="..\restsharp\extensions\ReflectionExtensions.cs">
177177
<Link>Extensions\ReflectionExtensions.cs</Link>
178178
</Compile>
179+
<Compile Include="..\RestSharp\Extensions\ResponseExtensions.cs">
180+
<Link>Extensions\ResponseExtensions.cs</Link>
181+
</Compile>
179182
<Compile Include="..\RestSharp\Extensions\StringExtensions.cs">
180183
<Link>Extensions\StringExtensions.cs</Link>
181184
</Compile>

RestSharp/Deserializers/DotNetXmlDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class DotNetXmlDeserializer : IDeserializer
3030

3131
public string RootElement { get; set; }
3232

33-
public T Deserialize<T>(RestResponse response) where T : new()
33+
public T Deserialize<T>(IRestResponse response)
3434
{
3535
if (string.IsNullOrEmpty(response.Content))
3636
{

RestSharp/Deserializers/IDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace RestSharp.Deserializers
1818
{
1919
public interface IDeserializer
2020
{
21-
T Deserialize<T>(RestResponse response) where T : new();
21+
T Deserialize<T>(IRestResponse response);
2222
string RootElement { get; set; }
2323
string Namespace { get; set; }
2424
string DateFormat { get; set; }

0 commit comments

Comments
 (0)