Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Commit

Permalink
Created a small test for issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
fubar-coder committed Mar 16, 2015
1 parent 326d140 commit 5cca8db
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions RestSharp.Portable.Test/IssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;

using Newtonsoft.Json;

using Xunit;

namespace RestSharp.Portable.Test
Expand Down Expand Up @@ -91,11 +94,47 @@ public void TestIssue19()
}
}

[Fact(DisplayName = "Issue 23")]
public async Task TestIssue23()
{
using (var client = new RestClient("http://httpbin.org/"))
{
var req = new RestRequest("/post", HttpMethod.Post);
var param = new Parameter
{
Value = new
{
Parameter1 = "param1",
},
Type = ParameterType.RequestBody,
};

{
var content = req.GetBodyContent(param);
var s = await content.ReadAsStringAsync();
Assert.Equal("{\"Parameter1\":\"param1\"}", s);
}

{
req.AddBody(param.Value);
var content = client.GetContent(req);
var s = await content.ReadAsStringAsync();
Assert.Equal("{\"Parameter1\":\"param1\"}", s);
}

var response = await client.Execute<PostResponse>(req);
var responseJson = JsonConvert.SerializeObject(response.Data.Json, Formatting.None);
Assert.Equal("{\"Parameter1\":\"param1\"}", responseJson);
}
}

// ReSharper disable once ClassNeverInstantiated.Local
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local", Justification = "ReSharper bug")]
private class PostResponse
{
public Dictionary<string, string> Form { get; set; }

public object Json { get; set; }
}
}
}

0 comments on commit 5cca8db

Please sign in to comment.