Skip to content

Commit fc4871c

Browse files
committed
Add test for underscore prefix
1 parent d73e3f0 commit fc4871c

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

RestSharp.Tests/JsonTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ public void Can_Deserialize_With_Default_Root_Alternative_Culture()
290290
}
291291
}
292292

293+
[Fact]
294+
public void Can_Deserialize_Names_With_Underscore_Prefix()
295+
{
296+
var data = File.ReadAllText(Path.Combine("SampleData", "underscore_prefix.txt"));
297+
var response = new RestResponse { Content = data };
298+
var json = new JsonDeserializer();
299+
json.RootElement = "User";
300+
301+
var output = json.Deserialize<SOUser>(response);
302+
303+
Assert.Equal("John Sheehan", output.DisplayName);
304+
Assert.Equal(1786, output.Id);
305+
}
306+
293307
[Fact]
294308
public void Can_Deserialize_Names_With_Underscores_With_Default_Root()
295309
{

RestSharp.Tests/RestSharp.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@
112112
<Content Include="SampleData\boolean_from_number.xml">
113113
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
114114
</Content>
115+
<Content Include="SampleData\underscore_prefix.txt">
116+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
117+
</Content>
115118
<Content Include="SampleData\datetimes.txt">
116119
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
117120
</Content>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"User":{
3+
"_id":1786,
4+
"_displayName":"John Sheehan",
5+
"Reputation":18332,
6+
"CreationDate":1219071163,
7+
"_displayName":"John Sheehan",
8+
"EmailHash":"lkdsafadfjsadfkjlsdjflkjdsf",
9+
"Age":"28",
10+
"LastAccessDate":1269715453,
11+
"WebsiteUrl":"http://john-sheehan.com/blog",
12+
"Location":"Minnesota",
13+
"AboutMe":"<h2><a href=\"http://twitter.com/johnsheehan\" rel=\"nofollow\">Follow me on Twitter</a></h2>\r\n\r\n<h2><a href=\"http://john-sheehan.com/blog\" rel=\"nofollow\">Read my blog</a></h2>\r\n\r\n<h2>Visit <a href=\"http://managedassembly.com\" rel=\"nofollow\">managedassembly.com</a> - A community for .NET developers.</h2>\r\n\r\n<p>I am the founder of <a href=\"http://rimsystems.com\" rel=\"nofollow\">RIM Systems</a>, maker of <a href=\"http://snapleague.com\" rel=\"nofollow\">SnapLeague</a>, a web-based league management system for recreational athletics.</p>",
14+
"Views":1639,
15+
"UpVotes":1665,
16+
"DownVotes":427
17+
}
18+
}

RestSharp/Extensions/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ public static IEnumerable<string> GetNameVariants(this string name, CultureInfo
348348
// try name with underscore prefix
349349
yield return name.AddUnderscorePrefix();
350350

351-
// try name with underscore prefix with lower case
352-
yield return name.AddUnderscorePrefix().ToLower(culture);
351+
// try name with underscore prefix, using camel case
352+
yield return name.ToCamelCase(culture).AddUnderscorePrefix();
353353
}
354354
}
355355
}

0 commit comments

Comments
 (0)