Skip to content

Commit b364992

Browse files
committed
merging upstream
2 parents 9c44254 + 8ab0bd4 commit b364992

27 files changed

+1731
-1564
lines changed

RestSharp.IntegrationTests/oAuth1Tests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using System.Xml.Serialization;
4+
using RestSharp.Authenticators.OAuth;
35
using Xunit;
46
using System.Net;
57
using RestSharp.Contrib;
@@ -160,5 +162,14 @@ public void Can_Authenticate_Netflix_With_OAuth()
160162
Assert.NotNull(queueResponse.Data);
161163
Assert.Equal(2, queueResponse.Data.Items.Count);
162164
}
165+
166+
[Fact]
167+
public void Properly_Encodes_Parameter_Names()
168+
{
169+
var postData = new WebParameterCollection { { "name[first]", "Chuck" }, { "name[last]", "Testa" }};
170+
var sortedParams = OAuthTools.SortParametersExcludingSignature(postData);
171+
172+
Assert.Equal("name%5Bfirst%5D", sortedParams[0].Name);
173+
}
163174
}
164175
}

RestSharp.Tests/SampleClasses/ListSamples.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public class NestedListSample
1818
public List<Image> Images { get; set; }
1919
}
2020

21+
public class EmptyListSample
22+
{
23+
public List<image> images { get; set; }
24+
public List<Image> Images { get; set; }
25+
}
26+
2127
public class Image
2228
{
2329
public string Src { get; set; }

RestSharp.Tests/XmlTests.cs

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@ public void Can_Deserialize_Nested_List_Items_With_Matching_Class_Name()
180180
Assert.Equal(4, output.images.Count);
181181
}
182182

183+
[Fact]
184+
public void Can_Deserialize_Nested_List_Without_Elements_To_Empty_List()
185+
{
186+
var doc = CreateXmlWithEmptyNestedList();
187+
188+
var xml = new XmlDeserializer();
189+
var output = xml.Deserialize<EmptyListSample>(new RestResponse { Content = doc });
190+
191+
Assert.NotNull(output.images);
192+
Assert.NotNull(output.Images);
193+
Assert.Empty(output.images);
194+
Assert.Empty(output.Images);
195+
}
196+
197+
[Fact]
198+
public void Can_Deserialize_Inline_List_Without_Elements_To_Empty_List()
199+
{
200+
var doc = CreateXmlWithEmptyInlineList();
201+
202+
var xml = new XmlDeserializer();
203+
var output = xml.Deserialize<EmptyListSample>(new RestResponse { Content = doc });
204+
205+
Assert.NotNull(output.images);
206+
Assert.NotNull(output.Images);
207+
Assert.Empty(output.images);
208+
Assert.Empty(output.Images);
209+
}
210+
183211
[Fact]
184212
public void Can_Deserialize_Empty_Elements_to_Nullable_Values()
185213
{
@@ -447,38 +475,38 @@ public void Can_Deserialize_Google_Weather_Xml()
447475
var response = new RestResponse { Content = doc.ToString() };
448476

449477
var d = new XmlDeserializer();
450-
var output = d.Deserialize<SampleClasses.xml_api_reply>(response);
478+
var output = d.Deserialize<SampleClasses.xml_api_reply>(response);
451479

452480
Assert.NotEmpty(output.weather);
453481
Assert.Equal(4, output.weather.Count);
454482
Assert.Equal("Sunny", output.weather[0].condition.data);
455483
}
456484

457-
[Fact]
458-
public void Can_Deserialize_Boolean_From_Number()
459-
{
460-
var xmlpath = PathFor("boolean_from_number.xml");
461-
var doc = XDocument.Load(xmlpath);
462-
var response = new RestResponse { Content = doc.ToString() };
485+
[Fact]
486+
public void Can_Deserialize_Boolean_From_Number()
487+
{
488+
var xmlpath = PathFor("boolean_from_number.xml");
489+
var doc = XDocument.Load(xmlpath);
490+
var response = new RestResponse { Content = doc.ToString() };
463491

464-
var d = new XmlDeserializer();
465-
var output = d.Deserialize<SampleClasses.BooleanTest>(response);
492+
var d = new XmlDeserializer();
493+
var output = d.Deserialize<SampleClasses.BooleanTest>(response);
466494

467-
Assert.True(output.Value);
468-
}
495+
Assert.True(output.Value);
496+
}
469497

470-
[Fact]
471-
public void Can_Deserialize_Boolean_From_String()
472-
{
473-
var xmlpath = PathFor("boolean_from_string.xml");
474-
var doc = XDocument.Load(xmlpath);
475-
var response = new RestResponse { Content = doc.ToString() };
498+
[Fact]
499+
public void Can_Deserialize_Boolean_From_String()
500+
{
501+
var xmlpath = PathFor("boolean_from_string.xml");
502+
var doc = XDocument.Load(xmlpath);
503+
var response = new RestResponse { Content = doc.ToString() };
476504

477-
var d = new XmlDeserializer();
478-
var output = d.Deserialize<SampleClasses.BooleanTest>(response);
505+
var d = new XmlDeserializer();
506+
var output = d.Deserialize<SampleClasses.BooleanTest>(response);
479507

480-
Assert.True(output.Value);
481-
}
508+
Assert.True(output.Value);
509+
}
482510

483511
private static string CreateUnderscoresXml()
484512
{
@@ -703,5 +731,27 @@ private static string CreateXmlWithoutEmptyValues()
703731

704732
return doc.ToString();
705733
}
734+
735+
private static string CreateXmlWithEmptyNestedList()
736+
{
737+
var doc = new XDocument();
738+
var root = new XElement("EmptyListSample");
739+
740+
root.Add(new XElement("Images"));
741+
742+
doc.Add(root);
743+
744+
return doc.ToString();
745+
}
746+
747+
private static string CreateXmlWithEmptyInlineList()
748+
{
749+
var doc = new XDocument();
750+
var root = new XElement("EmptyListSample");
751+
752+
doc.Add(root);
753+
754+
return doc.ToString();
755+
}
706756
}
707757
}

0 commit comments

Comments
 (0)