diff --git a/Octokit.Tests/Clients/BlobClientTests.cs b/Octokit.Tests/Clients/BlobClientTests.cs index a92bb08f..9d96819f 100644 --- a/Octokit.Tests/Clients/BlobClientTests.cs +++ b/Octokit.Tests/Clients/BlobClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; @@ -74,11 +76,11 @@ namespace Octokit.Tests.Clients "\"sha\": \"3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15\"," + "\"size\": 100" + "}"; - var httpResponse = new Response - { - Body = blobResponseJson, - ContentType = "application/json" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + blobResponseJson, + new Dictionary(), + "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index f298dea7..2d569757 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit; @@ -196,11 +198,12 @@ public class IssueCommentsClientTests "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; - var httpResponse = new Response - { - Body = issueResponseJson, - ContentType = "application/json" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + issueResponseJson, + new Dictionary(), + "application/json"); + var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index 61b05288..f8915d22 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; @@ -219,11 +220,12 @@ namespace Octokit.Tests.Clients "ed_events\",\"type\":\"User\",\"site_admin\":false},\"labels\":[],\"state\":\"open\",\"assignee" + "\":null,\"milestone\":null,\"comments\":0,\"created_at\":\"2013-10-22T17:02:48Z\",\"updated_at\"" + ":\"2013-10-22T17:02:48Z\",\"closed_at\":null,\"body\":\"A new unassigned issue\",\"closed_by\":null}"; - var httpResponse = new Response - { - Body = issueResponseJson, - ContentType = "application/json" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + issueResponseJson, + new Dictionary(), + "application/json"); + var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); diff --git a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs index 09e9ade8..04eb3836 100644 --- a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit; @@ -205,12 +207,12 @@ public class RepositoryCommentsClientTests "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; + var httpResponse = new Response( + HttpStatusCode.OK, + commitCommentResponseJson, + new Dictionary(), + "application/json"); - var httpResponse = new Response - { - Body = commitCommentResponseJson, - ContentType = "application/json" - }; var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); diff --git a/Octokit.Tests/Clients/TreesClientTests.cs b/Octokit.Tests/Clients/TreesClientTests.cs index 76354451..0f7aa1eb 100644 --- a/Octokit.Tests/Clients/TreesClientTests.cs +++ b/Octokit.Tests/Clients/TreesClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; @@ -119,11 +121,11 @@ namespace Octokit.Tests "}" + "]" + "}"; - var httpResponse = new Response - { - Body = issueResponseJson, - ContentType = "application/json" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + issueResponseJson, + new Dictionary(), + "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); diff --git a/Octokit.Tests/Http/JsonHttpPipelineTests.cs b/Octokit.Tests/Http/JsonHttpPipelineTests.cs index 48f407d9..be4b19ea 100644 --- a/Octokit.Tests/Http/JsonHttpPipelineTests.cs +++ b/Octokit.Tests/Http/JsonHttpPipelineTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using Octokit.Internal; using Xunit; @@ -106,11 +107,11 @@ namespace Octokit.Tests.Http public void DeserializesResponse() { const string data = "works"; - var httpResponse = new Response - { - Body = SimpleJson.SerializeObject(data), - ContentType = "application/json" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + SimpleJson.SerializeObject(data), + new Dictionary(), + "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); @@ -123,11 +124,11 @@ namespace Octokit.Tests.Http public void IgnoresResponsesNotIdentifiedAsJsonWhenNotDeserializingToString() { const string data = "works"; - var httpResponse = new Response - { - Body = SimpleJson.SerializeObject(data), - ContentType = "text/html" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + SimpleJson.SerializeObject(data), + new Dictionary(), + "text/html"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); @@ -140,11 +141,11 @@ namespace Octokit.Tests.Http { const string data = "{\"name\":\"Haack\"}"; var jsonPipeline = new JsonHttpPipeline(); - var httpResponse = new Response - { - Body = data, - ContentType = "application/json" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + data, + new Dictionary(), + "application/json"); var response = jsonPipeline.DeserializeResponse>(httpResponse); @@ -174,12 +175,11 @@ namespace Octokit.Tests.Http ""sha"": ""object-sha"", ""url"": ""object-url"" }}"; - - var httpResponse = new Response - { - Body = data, - ContentType = "application/json" - }; + var httpResponse = new Response( + HttpStatusCode.OK, + data, + new Dictionary(), + "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse(httpResponse); diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index b2540cec..1b513d3d 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -88,12 +88,11 @@ namespace Octokit.Internal } } - return new Response(responseMessage.Headers.ToDictionary(h => h.Key, h => h.Value.First())) - { - Body = responseBody, - StatusCode = responseMessage.StatusCode, - ContentType = contentType, - }; + return new Response( + responseMessage.StatusCode, + responseBody, + responseMessage.Headers.ToDictionary(h => h.Key, h => h.Value.First()), + contentType); } protected virtual HttpRequestMessage BuildRequestMessage(IRequest request) diff --git a/Octokit/Http/Response.cs b/Octokit/Http/Response.cs index dc8437c5..0d01ce79 100644 --- a/Octokit/Http/Response.cs +++ b/Octokit/Http/Response.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; +using System.Net.Http; using Octokit.Internal; namespace Octokit.Internal @@ -19,10 +21,21 @@ namespace Octokit.Internal ApiInfo = ApiInfoParser.ParseResponseHeaders(headers); } + public Response(HttpStatusCode statusCode, object body, IDictionary headers, string contentType) + { + Ensure.ArgumentNotNull(headers, "headers"); + + StatusCode = statusCode; + Body = body; + Headers = headers; + ApiInfo = ApiInfoParser.ParseResponseHeaders(headers); + ContentType = contentType; + } + public object Body { get; set; } public IDictionary Headers { get; private set; } public ApiInfo ApiInfo { get; private set; } public HttpStatusCode StatusCode { get; set; } - public string ContentType { get; set; } + public string ContentType { get; private set; } } } \ No newline at end of file