Skip to content

Commit 6a93fe5

Browse files
committed
Merge branch 'master' of https://github.com/zidad/RestSharp into zidad-master
2 parents 85d4693 + 322d37b commit 6a93fe5

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

RestSharp.Tests/SampleClasses/misc.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public class PersonForXml
5050
public Disposition Disposition { get; set; }
5151

5252
}
53+
54+
public class IncomingInvoice
55+
{
56+
public int ConceptId { get; set; }
57+
}
5358

5459
public class PersonForJson
5560
{

RestSharp.Tests/XmlTests.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,12 @@ 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-
}
468-
469-
[Fact]
470-
public void Can_Deserialize_Names_With_Underscores_Without_Matching_Case_On_Default_Root()
467+
}
468+
469+
[Fact]
470+
public void Can_Deserialize_Lower_Cased_Root_Elements_With_Dashes()
471471
{
472-
var doc = CreateLowercaseUnderscoresXml();
472+
var doc = CreateDashesXml();
473473
var response = new RestResponse { Content = doc };
474474

475475
var d = new XmlDeserializer();
@@ -497,6 +497,20 @@ public void Can_Deserialize_Names_With_Underscores_Without_Matching_Case_On_Defa
497497
Assert.Equal("Yankees", p.Foes.Team);
498498
}
499499

500+
[Fact]
501+
public void Can_Deserialize_Root_Elements_Without_Matching_Case_And_Dashes()
502+
{
503+
var doc = CreateLowerCasedRootElementWithDashesXml();
504+
var response = new RestResponse { Content = doc };
505+
506+
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);
512+
}
513+
500514

501515
[Fact]
502516
public void Can_Deserialize_Eventful_Xml()
@@ -726,6 +740,18 @@ private static string CreateDashesXml()
726740
doc.Add(root);
727741
return doc.ToString();
728742
}
743+
744+
private static string CreateLowerCasedRootElementWithDashesXml()
745+
{
746+
var doc = new XDocument();
747+
var root = new XElement("incoming-invoices",
748+
new XElement("incoming-invoice",
749+
new XElement("concept-id", 45)
750+
)
751+
);
752+
doc.Add(root);
753+
return doc.ToString();
754+
}
729755

730756
private static string CreateElementsXml()
731757
{

RestSharp/Deserializers/XmlDeserializer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ private object HandleListDerivative(object x, XElement root, string propName, Ty
252252
var elements = root.Descendants(t.Name.AsNamespaced(Namespace));
253253

254254
var name = t.Name;
255+
255256
if (!elements.Any())
256257
{
257258
var lowerName = name.ToLower().AsNamespaced(Namespace);
@@ -267,7 +268,13 @@ private object HandleListDerivative(object x, XElement root, string propName, Ty
267268
if (!elements.Any())
268269
{
269270
elements = root.Descendants().Where(e => e.Name.LocalName.RemoveUnderscoresAndDashes() == name);
270-
}
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+
}
271278

272279
PopulateListFromElements(t, elements, list);
273280

0 commit comments

Comments
 (0)