Skip to content

Commit ea73617

Browse files
committed
Tabified
1 parent 23baec8 commit ea73617

File tree

5 files changed

+121
-122
lines changed

5 files changed

+121
-122
lines changed

RestSharp.Tests/SerializerTests.cs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ namespace RestSharp.Tests
2626
{
2727
public class SerializerTests
2828
{
29-
public SerializerTests()
30-
{
31-
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
32-
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InstalledUICulture;
33-
}
29+
public SerializerTests()
30+
{
31+
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
32+
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InstalledUICulture;
33+
}
3434

3535
[Fact]
3636
public void Serializes_Properties_In_Specified_Order() {
@@ -85,25 +85,25 @@ public void Can_serialize_simple_POCO_With_DateFormat_Specified() {
8585
Assert.Equal(expected.ToString(), doc.ToString());
8686
}
8787

88-
[Fact]
89-
public void Can_serialize_simple_POCO_With_XmlFormat_Specified()
90-
{
91-
var poco = new Person
92-
{
93-
Name = "Foo",
94-
Age = 50,
95-
Price = 19.95m,
96-
StartDate = new DateTime(2009, 12, 18, 10, 2, 23),
97-
IsCool = false
98-
};
99-
100-
var xml = new XmlSerializer();
101-
xml.DateFormat = DateFormat.Iso8601;
102-
var doc = xml.Serialize(poco);
103-
var expected = GetSimplePocoXDocWithXmlProperty();
104-
105-
Assert.Equal(expected.ToString(), doc.ToString());
106-
}
88+
[Fact]
89+
public void Can_serialize_simple_POCO_With_XmlFormat_Specified()
90+
{
91+
var poco = new Person
92+
{
93+
Name = "Foo",
94+
Age = 50,
95+
Price = 19.95m,
96+
StartDate = new DateTime(2009, 12, 18, 10, 2, 23),
97+
IsCool = false
98+
};
99+
100+
var xml = new XmlSerializer();
101+
xml.DateFormat = DateFormat.Iso8601;
102+
var doc = xml.Serialize(poco);
103+
var expected = GetSimplePocoXDocWithXmlProperty();
104+
105+
Assert.Equal(expected.ToString(), doc);
106+
}
107107

108108
[Fact]
109109
public void Can_serialize_simple_POCO_With_Different_Root_Element() {
@@ -171,7 +171,7 @@ public void Can_serialize_a_list_which_is_the_root_element()
171171
}
172172
};
173173

174-
var xml = new XmlSerializer();
174+
var xml = new XmlSerializer();
175175
var doc = xml.Serialize(pocoList);
176176
var expected = GetPeopleXDoc(CultureInfo.InvariantCulture);
177177

@@ -185,7 +185,7 @@ private class Person
185185
public decimal Price { get; set; }
186186
public DateTime StartDate { get; set; }
187187
public List<Item> Items { get; set; }
188-
public bool? IsCool {get;set;}
188+
public bool? IsCool {get;set;}
189189
}
190190

191191
private class Item
@@ -248,20 +248,20 @@ private XDocument GetSimplePocoXDocWithIsoDate() {
248248
return doc;
249249
}
250250

251-
private XDocument GetSimplePocoXDocWithXmlProperty()
252-
{
253-
var doc = new XDocument();
254-
var root = new XElement("Person");
255-
root.Add(new XElement("Name", "Foo"),
256-
new XElement("Age", 50),
257-
new XElement("Price", 19.95m),
258-
new XElement("StartDate", new DateTime(2009, 12, 18, 10, 2, 23).ToString("s")),
259-
new XElement("IsCool", false));
251+
private XDocument GetSimplePocoXDocWithXmlProperty()
252+
{
253+
var doc = new XDocument();
254+
var root = new XElement("Person");
255+
root.Add(new XElement("Name", "Foo"),
256+
new XElement("Age", 50),
257+
new XElement("Price", 19.95m),
258+
new XElement("StartDate", new DateTime(2009, 12, 18, 10, 2, 23).ToString("s")),
259+
new XElement("IsCool", false));
260260

261-
doc.Add(root);
261+
doc.Add(root);
262262

263-
return doc;
264-
}
263+
return doc;
264+
}
265265

266266
private XDocument GetSimplePocoXDocWithRoot() {
267267
var doc = new XDocument();
@@ -317,17 +317,17 @@ private XDocument GetPeopleXDoc(CultureInfo culture)
317317
items.Add(new XElement("Item", new XElement("Name", "Three"), new XElement("Value", 3)));
318318
element.Add(new XElement("Name", "Foo"),
319319
new XElement("Age", 50),
320-
new XElement("Price", 19.95m.ToString(culture)),
321-
new XElement("StartDate", new DateTime(2009, 12, 18, 10, 2, 23).ToString(culture)));
320+
new XElement("Price", 19.95m.ToString(culture)),
321+
new XElement("StartDate", new DateTime(2009, 12, 18, 10, 2, 23).ToString(culture)));
322322

323323
element.Add(items);
324324
root.Add(element);
325325
element = new XElement("Person");
326326

327327
element.Add(new XElement("Name", "Bar"),
328328
new XElement("Age", 23),
329-
new XElement("Price", 23.23m.ToString(culture)),
330-
new XElement("StartDate", new DateTime(2009, 12, 23, 10, 23, 23).ToString(culture)));
329+
new XElement("Price", 23.23m.ToString(culture)),
330+
new XElement("StartDate", new DateTime(2009, 12, 23, 10, 23, 23).ToString(culture)));
331331

332332
element.Add(items);
333333

RestSharp.Tests/XmlTests.cs

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,9 @@ public void Can_Deserialize_Empty_Elements_to_Nullable_Values()
225225
[Fact]
226226
public void Can_Deserialize_Elements_to_Nullable_Values()
227227
{
228-
var culture = CultureInfo.InvariantCulture;
229-
var doc = CreateXmlWithoutEmptyValues(culture);
230-
231-
var xml = new XmlDeserializer() {Culture = culture};
228+
var culture = CultureInfo.InvariantCulture;
229+
var doc = CreateXmlWithoutEmptyValues(culture);
230+
var xml = new XmlDeserializer() {Culture = culture};
232231
var output = xml.Deserialize<NullableValues>(new RestResponse { Content = doc });
233232

234233
Assert.NotNull(output.Id);
@@ -243,24 +242,24 @@ public void Can_Deserialize_Elements_to_Nullable_Values()
243242
[Fact]
244243
public void Can_Deserialize_Custom_Formatted_Date()
245244
{
246-
var culture = CultureInfo.InvariantCulture;
245+
var culture = CultureInfo.InvariantCulture;
247246
var format = "dd yyyy MMM, hh:mm ss tt zzz";
248247
var date = new DateTime(2010, 2, 8, 11, 11, 11);
249248

250249
var doc = new XDocument();
251250

252251
var root = new XElement("Person");
253-
root.Add(new XElement("StartDate", date.ToString(format, culture)));
252+
root.Add(new XElement("StartDate", date.ToString(format, culture)));
254253

255254
doc.Add(root);
256255

257-
var xml = new XmlDeserializer
258-
{
259-
DateFormat = format,
260-
Culture = culture
261-
};
256+
var xml = new XmlDeserializer
257+
{
258+
DateFormat = format,
259+
Culture = culture
260+
};
262261

263-
var response = new RestResponse { Content = doc.ToString() };
262+
var response = new RestResponse { Content = doc.ToString() };
264263
var output = xml.Deserialize<PersonForXml>(response);
265264

266265
Assert.Equal(date, output.StartDate);
@@ -515,31 +514,31 @@ public void Can_Deserialize_Boolean_From_String()
515514
Assert.True(output.Value);
516515
}
517516

518-
[Fact]
519-
public void Can_Deserialize_Empty_Elements_With_Attributes_to_Nullable_Values()
520-
{
521-
var doc = CreateXmlWithAttributesAndNullValues();
517+
[Fact]
518+
public void Can_Deserialize_Empty_Elements_With_Attributes_to_Nullable_Values()
519+
{
520+
var doc = CreateXmlWithAttributesAndNullValues();
522521

523-
var xml = new XmlDeserializer();
524-
var output = xml.Deserialize<NullableValues>(new RestResponse { Content = doc });
522+
var xml = new XmlDeserializer();
523+
var output = xml.Deserialize<NullableValues>(new RestResponse {Content = doc});
525524

526-
Assert.Null(output.Id);
527-
Assert.Null(output.StartDate);
528-
Assert.Null(output.UniqueId);
529-
}
525+
Assert.Null(output.Id);
526+
Assert.Null(output.StartDate);
527+
Assert.Null(output.UniqueId);
528+
}
530529

531-
[Fact]
532-
public void Can_Deserialize_Mixture_Of_Empty_Elements_With_Attributes_And_Populated_Elements()
533-
{
534-
var doc = CreateXmlWithAttributesAndNullValuesAndPopulatedValues();
530+
[Fact]
531+
public void Can_Deserialize_Mixture_Of_Empty_Elements_With_Attributes_And_Populated_Elements()
532+
{
533+
var doc = CreateXmlWithAttributesAndNullValuesAndPopulatedValues();
535534

536-
var xml = new XmlDeserializer();
537-
var output = xml.Deserialize<NullableValues>(new RestResponse { Content = doc });
535+
var xml = new XmlDeserializer();
536+
var output = xml.Deserialize<NullableValues>(new RestResponse {Content = doc});
538537

539-
Assert.Null(output.Id);
540-
Assert.Null(output.StartDate);
541-
Assert.Equal(new Guid(GuidString), output.UniqueId);
542-
}
538+
Assert.Null(output.Id);
539+
Assert.Null(output.StartDate);
540+
Assert.Equal(new Guid(GuidString), output.UniqueId);
541+
}
543542

544543
private static string CreateUnderscoresXml()
545544
{
@@ -757,9 +756,9 @@ private static string CreateXmlWithoutEmptyValues(CultureInfo culture)
757756
var root = new XElement("NullableValues");
758757

759758
root.Add(new XElement("Id", 123),
760-
new XElement("StartDate", new DateTime(2010, 2, 21, 9, 35, 00).ToString(culture)),
761-
new XElement("UniqueId", new Guid(GuidString))
762-
);
759+
new XElement("StartDate", new DateTime(2010, 2, 21, 9, 35, 00).ToString(culture)),
760+
new XElement("UniqueId", new Guid(GuidString))
761+
);
763762

764763
doc.Add(root);
765764

@@ -788,38 +787,38 @@ private static string CreateXmlWithEmptyInlineList()
788787
return doc.ToString();
789788
}
790789

791-
private static string CreateXmlWithAttributesAndNullValues()
792-
{
793-
var doc = new XDocument();
794-
var root = new XElement("NullableValues");
790+
private static string CreateXmlWithAttributesAndNullValues()
791+
{
792+
var doc = new XDocument();
793+
var root = new XElement("NullableValues");
795794

796-
var idElement = new XElement("Id", null);
797-
idElement.SetAttributeValue("SomeAttribute", "SomeAttribute_Value");
798-
root.Add(idElement,
799-
new XElement("StartDate", null),
800-
new XElement("UniqueId", null)
801-
);
795+
var idElement = new XElement("Id", null);
796+
idElement.SetAttributeValue("SomeAttribute", "SomeAttribute_Value");
797+
root.Add(idElement,
798+
new XElement("StartDate", null),
799+
new XElement("UniqueId", null)
800+
);
802801

803-
doc.Add(root);
802+
doc.Add(root);
804803

805-
return doc.ToString();
806-
}
804+
return doc.ToString();
805+
}
807806

808-
private static string CreateXmlWithAttributesAndNullValuesAndPopulatedValues()
809-
{
810-
var doc = new XDocument();
811-
var root = new XElement("NullableValues");
807+
private static string CreateXmlWithAttributesAndNullValuesAndPopulatedValues()
808+
{
809+
var doc = new XDocument();
810+
var root = new XElement("NullableValues");
812811

813-
var idElement = new XElement("Id", null);
814-
idElement.SetAttributeValue("SomeAttribute", "SomeAttribute_Value");
815-
root.Add(idElement,
816-
new XElement("StartDate", null),
817-
new XElement("UniqueId", new Guid(GuidString))
818-
);
812+
var idElement = new XElement("Id", null);
813+
idElement.SetAttributeValue("SomeAttribute", "SomeAttribute_Value");
814+
root.Add(idElement,
815+
new XElement("StartDate", null),
816+
new XElement("UniqueId", new Guid(GuidString))
817+
);
819818

820-
doc.Add(root);
819+
doc.Add(root);
821820

822-
return doc.ToString();
823-
}
821+
return doc.ToString();
822+
}
824823
}
825824
}

RestSharp/Deserializers/JsonDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void Map(object x, JToken json)
153153
}
154154
else if (type == typeof(Decimal))
155155
{
156-
var dec = Decimal.Parse(value.AsString(Culture), Culture);
156+
var dec = Decimal.Parse(value.AsString(Culture), Culture);
157157
prop.SetValue(x, dec, null);
158158
}
159159
else if (type == typeof(Guid))

RestSharp/Extensions/MiscExtensions.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ public static string AsString(this JToken token)
8383
return token.Type == JTokenType.String ? token.Value<string>() : token.ToString();
8484
}
8585

86-
/// <summary>
87-
/// Gets string value from JToken
88-
/// </summary>
89-
/// <param name="token"></param>
90-
/// <returns></returns>
91-
public static string AsString(this JToken token, CultureInfo culture)
92-
{
93-
var value = token as JValue;
94-
if (value != null)
95-
{
96-
return (string)value.Value.ChangeType(typeof(string), culture);
97-
}
86+
/// <summary>
87+
/// Gets string value from JToken
88+
/// </summary>
89+
/// <param name="token"></param>
90+
/// <returns></returns>
91+
public static string AsString(this JToken token, CultureInfo culture)
92+
{
93+
var value = token as JValue;
94+
if (value != null)
95+
{
96+
return (string) value.Value.ChangeType(typeof (string), culture);
97+
}
9898

99-
return token.Type == JTokenType.String ? token.Value<string>() : token.ToString();
100-
}
99+
return token.Type == JTokenType.String ? token.Value<string>() : token.ToString();
100+
}
101101

102102
/// <summary>
103103
/// Converts a byte array to a string, using its byte order mark to convert it to the right encoding.

RestSharp/Extensions/ReflectionExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ public static object ChangeType(this object source, Type newType)
7272
#endif
7373
}
7474

75-
public static object ChangeType(this object source, Type newType, CultureInfo culture)
76-
{
75+
public static object ChangeType(this object source, Type newType, CultureInfo culture)
76+
{
7777
#if FRAMEWORK
78-
return Convert.ChangeType(source, newType, culture);
78+
return Convert.ChangeType(source, newType, culture);
7979
#else
8080
return Convert.ChangeType(source, newType, null);
8181
#endif
82-
}
82+
}
8383

8484
/// <summary>
8585
/// Find a value from a System.Enum by trying several possible variants

0 commit comments

Comments
 (0)