Skip to content

Commit

Permalink
Fixed indentation
Browse files Browse the repository at this point in the history
RestSharp uses tabs instead of spaces. Oy!
  • Loading branch information
haacked committed Sep 7, 2013
1 parent c398ea1 commit ec4405a
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 127 deletions.
150 changes: 75 additions & 75 deletions RestSharp.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,47 +254,47 @@ public void Can_Deserialize_Elements_to_Nullable_Values()
Assert.Equal(new Guid(GuidString), output.UniqueId);
}

[Fact]
public void Can_Deserialize_TimeSpan()
{
var culture = CultureInfo.InvariantCulture;
var doc = new XDocument(culture);

TimeSpan? nullTimespan = null;
TimeSpan? nullValueTimeSpan = new TimeSpan(21, 30, 7);

var root = new XElement("Person");
root.Add(new XElement("Tick", new TimeSpan(468006)));
root.Add(new XElement("Millisecond", new TimeSpan(0, 0, 0, 0, 125)));
root.Add(new XElement("Second", new TimeSpan(0, 0, 8)));
root.Add(new XElement("Minute", new TimeSpan(0, 55, 2)));
root.Add(new XElement("Hour", new TimeSpan(21, 30, 7)));
root.Add(new XElement("NullableWithoutValue", nullTimespan));
root.Add(new XElement("NullableWithValue", nullValueTimeSpan));

doc.Add(root);

var xml = new XmlDeserializer
{
Culture = culture,
};

var response = new RestResponse { Content = doc.ToString() };

var d = new XmlDeserializer()
{
Culture = culture,
};
var payload = d.Deserialize<TimeSpanTestStructure>(response);
Assert.Equal(new TimeSpan(468006), payload.Tick);
Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
Assert.Null(payload.NullableWithoutValue);
Assert.NotNull(payload.NullableWithValue);
Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
}
[Fact]
public void Can_Deserialize_TimeSpan()
{
var culture = CultureInfo.InvariantCulture;
var doc = new XDocument(culture);

TimeSpan? nullTimespan = null;
TimeSpan? nullValueTimeSpan = new TimeSpan(21, 30, 7);

var root = new XElement("Person");
root.Add(new XElement("Tick", new TimeSpan(468006)));
root.Add(new XElement("Millisecond", new TimeSpan(0, 0, 0, 0, 125)));
root.Add(new XElement("Second", new TimeSpan(0, 0, 8)));
root.Add(new XElement("Minute", new TimeSpan(0, 55, 2)));
root.Add(new XElement("Hour", new TimeSpan(21, 30, 7)));
root.Add(new XElement("NullableWithoutValue", nullTimespan));
root.Add(new XElement("NullableWithValue", nullValueTimeSpan));

doc.Add(root);

var xml = new XmlDeserializer
{
Culture = culture,
};

var response = new RestResponse { Content = doc.ToString() };

var d = new XmlDeserializer()
{
Culture = culture,
};
var payload = d.Deserialize<TimeSpanTestStructure>(response);
Assert.Equal(new TimeSpan(468006), payload.Tick);
Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
Assert.Null(payload.NullableWithoutValue);
Assert.NotNull(payload.NullableWithValue);
Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
}

[Fact]
public void Can_Deserialize_Custom_Formatted_Date()
Expand Down Expand Up @@ -496,8 +496,8 @@ public void Can_Deserialize_Names_With_Underscores_Without_Matching_Case_On_Defa
Assert.Equal (5, p.Foes.Count);
Assert.Equal ("Yankees", p.Foes.Team);
}
[Fact]
[Fact]
public void Can_Deserialize_Lower_Cased_Root_Elements_With_Dashes()
{
var doc = CreateDashesXml();
Expand Down Expand Up @@ -642,40 +642,40 @@ public void Can_Deserialize_Mixture_Of_Empty_Elements_With_Attributes_And_Popula
Assert.Equal(new Guid(GuidString), output.UniqueId);
}

[Fact]
public void Can_Deserialize_DateTimeOffset()
{
var culture = CultureInfo.InvariantCulture;
var doc = new XDocument(culture);
DateTimeOffset DateTimeOffset = new DateTimeOffset(2013, 02, 08, 9, 18, 22, TimeSpan.FromHours(10));
DateTimeOffset? NullableDateTimeOffsetWithValue = new DateTimeOffset(2013, 02, 08, 9, 18, 23, TimeSpan.FromHours(10));
[Fact]
public void Can_Deserialize_DateTimeOffset()
{
var culture = CultureInfo.InvariantCulture;
var doc = new XDocument(culture);
DateTimeOffset DateTimeOffset = new DateTimeOffset(2013, 02, 08, 9, 18, 22, TimeSpan.FromHours(10));
DateTimeOffset? NullableDateTimeOffsetWithValue = new DateTimeOffset(2013, 02, 08, 9, 18, 23, TimeSpan.FromHours(10));

var root = new XElement("Dates");
root.Add(new XElement("DateTimeOffset", DateTimeOffset));
root.Add(new XElement("NullableDateTimeOffsetWithNull", string.Empty));
root.Add(new XElement("NullableDateTimeOffsetWithValue", NullableDateTimeOffsetWithValue));
doc.Add(root);
var root = new XElement("Dates");
root.Add(new XElement("DateTimeOffset", DateTimeOffset));
root.Add(new XElement("NullableDateTimeOffsetWithNull", string.Empty));
root.Add(new XElement("NullableDateTimeOffsetWithValue", NullableDateTimeOffsetWithValue));
doc.Add(root);

var xml = new XmlDeserializer
{
Culture = culture,
};
var xml = new XmlDeserializer
{
Culture = culture,
};

var response = new RestResponse { Content = doc.ToString() };
var response = new RestResponse { Content = doc.ToString() };

var d = new XmlDeserializer()
{
Culture = culture,
};
var payload = d.Deserialize<DateTimeTestStructure>(response);
Assert.Equal(DateTimeOffset, payload.DateTimeOffset);
Assert.Null(payload.NullableDateTimeOffsetWithNull);
var d = new XmlDeserializer()
{
Culture = culture,
};
var payload = d.Deserialize<DateTimeTestStructure>(response);
Assert.Equal(DateTimeOffset, payload.DateTimeOffset);
Assert.Null(payload.NullableDateTimeOffsetWithNull);

Assert.True(payload.NullableDateTimeOffsetWithValue.HasValue);
Assert.Equal(NullableDateTimeOffsetWithValue, payload.NullableDateTimeOffsetWithValue);
}
Assert.True(payload.NullableDateTimeOffsetWithValue.HasValue);
Assert.Equal(NullableDateTimeOffsetWithValue, payload.NullableDateTimeOffsetWithValue);
}

private static string CreateUnderscoresXml()
{
Expand Down Expand Up @@ -806,10 +806,10 @@ private static string CreateDashesXml()
doc.Add(root);
return doc.ToString();
}
private static string CreateLowerCasedRootElementWithDashesXml()
private static string CreateLowerCasedRootElementWithDashesXml()
{
var doc = new XDocument();
var doc = new XDocument();
var root = new XElement("incoming-invoices",
new XElement("incoming-invoice",
new XElement("concept-id", 45)
Expand Down
104 changes: 52 additions & 52 deletions RestSharp/Deserializers/XmlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ private void Map(object x, XElement root)
// check for nullable and extract underlying type
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
// if the value is empty, set the property to null...
if (value == null || String.IsNullOrEmpty(value.ToString()))
{
prop.SetValue(x, null, null);
continue;
}
type = type.GetGenericArguments()[0];
// if the value is empty, set the property to null...
if (value == null || String.IsNullOrEmpty(value.ToString()))
{
prop.SetValue(x, null, null);
continue;
}
type = type.GetGenericArguments()[0];
}

if (type == typeof(bool))
Expand Down Expand Up @@ -170,33 +170,33 @@ private void Map(object x, XElement root)

prop.SetValue(x, value, null);
}
else if (type == typeof(DateTimeOffset))
{
var toConvert = value.ToString();
if (!string.IsNullOrEmpty(toConvert))
{
DateTimeOffset deserialisedValue;
try
{
deserialisedValue = XmlConvert.ToDateTimeOffset(toConvert);
prop.SetValue(x, deserialisedValue, null);
}
catch (Exception)
{
object result;
if (TryGetFromString(toConvert, out result, type))
{
prop.SetValue(x, result, null);
}
else
{
//fallback to parse
deserialisedValue = DateTimeOffset.Parse(toConvert);
prop.SetValue(x, deserialisedValue, null);
}
}
}
}
else if (type == typeof(DateTimeOffset))
{
var toConvert = value.ToString();
if (!string.IsNullOrEmpty(toConvert))
{
DateTimeOffset deserialisedValue;
try
{
deserialisedValue = XmlConvert.ToDateTimeOffset(toConvert);
prop.SetValue(x, deserialisedValue, null);
}
catch (Exception)
{
object result;
if (TryGetFromString(toConvert, out result, type))
{
prop.SetValue(x, result, null);
}
else
{
//fallback to parse
deserialisedValue = DateTimeOffset.Parse(toConvert);
prop.SetValue(x, deserialisedValue, null);
}
}
}
}
else if (type == typeof(Decimal))
{
value = Decimal.Parse(value.ToString(), Culture);
Expand All @@ -207,12 +207,12 @@ private void Map(object x, XElement root)
var raw = value.ToString();
value = string.IsNullOrEmpty(raw) ? Guid.Empty : new Guid(value.ToString());
prop.SetValue(x, value, null);
}
else if (type == typeof(TimeSpan))
{
var timeSpan = XmlConvert.ToTimeSpan(value.ToString());
prop.SetValue(x, timeSpan, null);
}
}
else if (type == typeof(TimeSpan))
{
var timeSpan = XmlConvert.ToTimeSpan(value.ToString());
prop.SetValue(x, timeSpan, null);
}
else if (type.IsGenericType)
{
var t = type.GetGenericArguments()[0];
Expand Down Expand Up @@ -242,7 +242,7 @@ private void Map(object x, XElement root)
object result;
if (TryGetFromString(value.ToString(), out result, type))
{
prop.SetValue(x, result, null);
prop.SetValue(x, result, null);
}
else
{
Expand All @@ -261,17 +261,17 @@ private void Map(object x, XElement root)
}
}

private static bool TryGetFromString(string inputString, out object result, Type type)
{
var converter = TypeDescriptor.GetConverter(type);
if (converter.CanConvertFrom(typeof(string)))
{
result = (converter.ConvertFromInvariantString(inputString));
return true;
}
result = null;
return false;
}
private static bool TryGetFromString(string inputString, out object result, Type type)
{
var converter = TypeDescriptor.GetConverter(type);
if (converter.CanConvertFrom(typeof(string)))
{
result = (converter.ConvertFromInvariantString(inputString));
return true;
}
result = null;
return false;
}

private void PopulateListFromElements(Type t, IEnumerable<XElement> elements, IList list)
{
Expand Down

0 comments on commit ec4405a

Please sign in to comment.