Skip to content

Commit 27dea00

Browse files
committed
Re-add a removed test, and some whitespace cleanup.
1 parent 6a93fe5 commit 27dea00

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

RestSharp.Tests/XmlTests.cs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,38 @@ public void Can_Deserialize_Names_With_Dashes_On_Default_Root()
464464
Assert.NotNull(p.Foes);
465465
Assert.Equal(5, p.Foes.Count);
466466
Assert.Equal("Yankees", p.Foes.Team);
467-
}
467+
}
468+
469+
[Fact]
470+
public void Can_Deserialize_Names_With_Underscores_Without_Matching_Case_On_Default_Root ()
471+
{
472+
var doc = CreateLowercaseUnderscoresXml ();
473+
var response = new RestResponse { Content = doc };
474+
475+
var d = new XmlDeserializer ();
476+
var p = d.Deserialize<PersonForXml> (response);
477+
478+
Assert.Equal ("John Sheehan", p.Name);
479+
Assert.Equal (new DateTime (2009, 9, 25, 0, 6, 1), p.StartDate);
480+
Assert.Equal (28, p.Age);
481+
Assert.Equal (long.MaxValue, p.BigNumber);
482+
Assert.Equal (99.9999m, p.Percent);
483+
Assert.Equal (false, p.IsCool);
484+
Assert.Equal (new Guid (GuidString), p.UniqueId);
485+
Assert.Equal (new Uri ("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
486+
Assert.Equal (new Uri ("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
487+
488+
Assert.NotNull (p.Friends);
489+
Assert.Equal (10, p.Friends.Count);
490+
491+
Assert.NotNull (p.BestFriend);
492+
Assert.Equal ("The Fonz", p.BestFriend.Name);
493+
Assert.Equal (1952, p.BestFriend.Since);
494+
495+
Assert.NotNull (p.Foes);
496+
Assert.Equal (5, p.Foes.Count);
497+
Assert.Equal ("Yankees", p.Foes.Team);
498+
}
468499

469500
[Fact]
470501
public void Can_Deserialize_Lower_Cased_Root_Elements_With_Dashes()
@@ -504,11 +535,11 @@ public void Can_Deserialize_Root_Elements_Without_Matching_Case_And_Dashes()
504535
var response = new RestResponse { Content = doc };
505536

506537
var d = new XmlDeserializer();
507-
var p = d.Deserialize<List<IncomingInvoice>>(response);
508-
509-
Assert.NotNull(p);
510-
Assert.Equal(1, p.Count);
511-
Assert.Equal(45, p[0].ConceptId);
538+
var p = d.Deserialize<List<IncomingInvoice>>(response);
539+
540+
Assert.NotNull(p);
541+
Assert.Equal(1, p.Count);
542+
Assert.Equal(45, p[0].ConceptId);
512543
}
513544

514545

@@ -744,11 +775,11 @@ private static string CreateDashesXml()
744775
private static string CreateLowerCasedRootElementWithDashesXml()
745776
{
746777
var doc = new XDocument();
747-
var root = new XElement("incoming-invoices",
748-
new XElement("incoming-invoice",
749-
new XElement("concept-id", 45)
750-
)
751-
);
778+
var root = new XElement("incoming-invoices",
779+
new XElement("incoming-invoice",
780+
new XElement("concept-id", 45)
781+
)
782+
);
752783
doc.Add(root);
753784
return doc.ToString();
754785
}

RestSharp/Deserializers/XmlDeserializer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ private object HandleListDerivative(object x, XElement root, string propName, Ty
268268
if (!elements.Any())
269269
{
270270
elements = root.Descendants().Where(e => e.Name.LocalName.RemoveUnderscoresAndDashes() == name);
271-
}
272-
273-
if (!elements.Any())
274-
{
275-
var lowerName = name.ToLower().AsNamespaced(Namespace);
276-
elements = root.Descendants().Where(e => e.Name.LocalName.RemoveUnderscoresAndDashes() == lowerName);
277-
}
271+
}
272+
273+
if (!elements.Any())
274+
{
275+
var lowerName = name.ToLower().AsNamespaced(Namespace);
276+
elements = root.Descendants().Where(e => e.Name.LocalName.RemoveUnderscoresAndDashes() == lowerName);
277+
}
278278

279279
PopulateListFromElements(t, elements, list);
280280

0 commit comments

Comments
 (0)