mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 04:40:54 +00:00
rewrite the setup of responses to use a standard helper function (#2177)
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
using static Octokit.Internal.TestSetup;
|
||||
|
||||
namespace Octokit.Tests.Http
|
||||
{
|
||||
public class ApiConnectionTests
|
||||
@@ -18,7 +20,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task MakesGetRequestForItem()
|
||||
{
|
||||
var getUri = new Uri("anything", UriKind.Relative);
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.OK));
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Get<object>(Args.Uri, null, null).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -34,7 +36,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var getUri = new Uri("anything", UriKind.Relative);
|
||||
const string accepts = "custom/accepts";
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.OK));
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Get<object>(Args.Uri, null, Args.String).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -61,7 +63,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task MakesHtmlRequest()
|
||||
{
|
||||
var getUri = new Uri("anything", UriKind.Relative);
|
||||
IApiResponse<string> response = new ApiResponse<string>(new Response(), "<html />");
|
||||
IApiResponse<string> response = new ApiResponse<string>(CreateResponse(HttpStatusCode.OK), "<html />");
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetHtml(Args.Uri, null).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -87,7 +89,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var getAllUri = new Uri("anything", UriKind.Relative);
|
||||
IApiResponse<List<object>> response = new ApiResponse<List<object>>(
|
||||
new Response(),
|
||||
CreateResponse(HttpStatusCode.OK),
|
||||
new List<object> { new object(), new object() });
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Get<List<object>>(Args.Uri, Args.EmptyDictionary, null).Returns(Task.FromResult(response));
|
||||
@@ -124,7 +126,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var patchUri = new Uri("anything", UriKind.Relative);
|
||||
var sentData = new object();
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response(), new object());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.OK), new object());
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Patch<object>(Args.Uri, Args.Object).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -141,7 +143,7 @@ namespace Octokit.Tests.Http
|
||||
var patchUri = new Uri("anything", UriKind.Relative);
|
||||
var sentData = new object();
|
||||
var accepts = "custom/accepts";
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.OK));
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Patch<object>(Args.Uri, Args.Object, Args.String).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -184,7 +186,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var postUri = new Uri("anything", UriKind.Relative);
|
||||
var sentData = new object();
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response(), new object());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.OK), new object());
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Post<object>(Args.Uri, Args.Object, null, null).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -199,7 +201,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task MakesUploadRequest()
|
||||
{
|
||||
var uploadUrl = new Uri("anything", UriKind.Relative);
|
||||
IApiResponse<string> response = new ApiResponse<string>(new Response(), "the response");
|
||||
IApiResponse<string> response = new ApiResponse<string>(CreateResponse(HttpStatusCode.OK), "the response");
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Post<string>(Args.Uri, Arg.Any<Stream>(), Args.String, Args.String)
|
||||
.Returns(Task.FromResult(response));
|
||||
@@ -237,7 +239,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var putUri = new Uri("anything", UriKind.Relative);
|
||||
var sentData = new object();
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.OK));
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Put<object>(Args.Uri, Args.Object).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -253,7 +255,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var putUri = new Uri("anything", UriKind.Relative);
|
||||
var sentData = new object();
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.OK));
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.Put<object>(Args.Uri, Args.Object, "two-factor").Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -319,8 +321,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
|
||||
|
||||
const HttpStatusCode statusCode = HttpStatusCode.PartialContent;
|
||||
IApiResponse<object> response = new ApiResponse<object>(new Response(statusCode, null, new Dictionary<string, string>(), "application/json"), new object());
|
||||
IApiResponse<object> response = new ApiResponse<object>(CreateResponse(HttpStatusCode.PartialContent), new object());
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
@@ -334,8 +335,7 @@ namespace Octokit.Tests.Http
|
||||
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
|
||||
|
||||
var result = new[] { new object() };
|
||||
const HttpStatusCode statusCode = HttpStatusCode.OK;
|
||||
var httpResponse = new Response(statusCode, null, new Dictionary<string, string>(), "application/json");
|
||||
var httpResponse = CreateResponse(HttpStatusCode.OK);
|
||||
IApiResponse<IReadOnlyList<object>> response = new ApiResponse<IReadOnlyList<object>>(httpResponse, result);
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetResponse<IReadOnlyList<object>>(queuedOperationUrl, Args.CancellationToken)
|
||||
@@ -352,8 +352,7 @@ namespace Octokit.Tests.Http
|
||||
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
|
||||
|
||||
var result = new[] { new object() };
|
||||
const HttpStatusCode statusCode = HttpStatusCode.NoContent;
|
||||
var httpResponse = new Response(statusCode, null, new Dictionary<string, string>(), "application/json");
|
||||
var httpResponse = CreateResponse(HttpStatusCode.NoContent);
|
||||
IApiResponse<IReadOnlyList<object>> response = new ApiResponse<IReadOnlyList<object>>(
|
||||
httpResponse, result);
|
||||
var connection = Substitute.For<IConnection>();
|
||||
@@ -371,10 +370,8 @@ namespace Octokit.Tests.Http
|
||||
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
|
||||
|
||||
var result = new[] { new object() };
|
||||
IApiResponse<IReadOnlyList<object>> firstResponse = new ApiResponse<IReadOnlyList<object>>(
|
||||
new Response(HttpStatusCode.Accepted, null, new Dictionary<string, string>(), "application/json"), result);
|
||||
IApiResponse<IReadOnlyList<object>> completedResponse = new ApiResponse<IReadOnlyList<object>>(
|
||||
new Response(HttpStatusCode.OK, null, new Dictionary<string, string>(), "application/json"), result);
|
||||
IApiResponse<IReadOnlyList<object>> firstResponse = new ApiResponse<IReadOnlyList<object>>(CreateResponse(HttpStatusCode.Accepted), result);
|
||||
IApiResponse<IReadOnlyList<object>> completedResponse = new ApiResponse<IReadOnlyList<object>>(CreateResponse(HttpStatusCode.OK), result);
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetResponse<IReadOnlyList<object>>(queuedOperationUrl, Args.CancellationToken)
|
||||
.Returns(x => Task.FromResult(firstResponse),
|
||||
@@ -394,8 +391,7 @@ namespace Octokit.Tests.Http
|
||||
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
|
||||
|
||||
var result = new[] { new object() };
|
||||
IApiResponse<IReadOnlyList<object>> accepted = new ApiResponse<IReadOnlyList<object>>(
|
||||
new Response(HttpStatusCode.Accepted, null, new Dictionary<string, string>(), "application/json"), result);
|
||||
IApiResponse<IReadOnlyList<object>> accepted = new ApiResponse<IReadOnlyList<object>>(CreateResponse(HttpStatusCode.Accepted), result);
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetResponse<IReadOnlyList<object>>(queuedOperationUrl, Args.CancellationToken)
|
||||
.Returns(x => Task.FromResult(accepted));
|
||||
|
||||
@@ -10,6 +10,8 @@ using NSubstitute;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
using static Octokit.Internal.TestSetup;
|
||||
|
||||
namespace Octokit.Tests.Http
|
||||
{
|
||||
public class ConnectionTests
|
||||
@@ -23,7 +25,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task SendsProperlyFormattedRequest()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -45,7 +47,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task CanMakeMultipleRequestsWithSameConnection()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -71,7 +73,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
{ "X-Accepted-OAuth-Scopes", "user" }
|
||||
};
|
||||
IResponse response = new Response(headers);
|
||||
var response = CreateResponse(HttpStatusCode.OK, headers);
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
@@ -89,7 +91,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task ThrowsAuthorizationExceptionExceptionForUnauthorizedResponse()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(HttpStatusCode.Unauthorized, null, new Dictionary<string, string>(), "application/json");
|
||||
var response = CreateResponse(HttpStatusCode.Unauthorized);
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -113,7 +115,7 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
var headers = new Dictionary<string, string> { { headerKey, otpHeaderValue } };
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(HttpStatusCode.Unauthorized, null, headers, "application/json");
|
||||
var response = CreateResponse(HttpStatusCode.Unauthorized, headers);
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -139,7 +141,7 @@ namespace Octokit.Tests.Http
|
||||
TwoFactorType expectedFactorType)
|
||||
{
|
||||
var headers = new Dictionary<string, string> { { headerKey, otpHeaderValue } };
|
||||
IResponse response = new Response(HttpStatusCode.Unauthorized, null, headers, "application/json");
|
||||
var response = CreateResponse(HttpStatusCode.Unauthorized, headers);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
@@ -158,12 +160,10 @@ namespace Octokit.Tests.Http
|
||||
public async Task ThrowsApiValidationExceptionFor422Response()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
(HttpStatusCode)422,
|
||||
@"{""errors"":[{""code"":""custom"",""field"":""key"",""message"":""key is " +
|
||||
@"already in use"",""resource"":""PublicKey""}],""message"":""Validation Failed""}",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json"
|
||||
@"already in use"",""resource"":""PublicKey""}],""message"":""Validation Failed""}"
|
||||
);
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
@@ -183,12 +183,11 @@ namespace Octokit.Tests.Http
|
||||
public async Task ThrowsRateLimitExceededExceptionForForbidderResponse()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.Forbidden,
|
||||
"{\"message\":\"API rate limit exceeded. " +
|
||||
"See http://developer.github.com/v3/#rate-limiting for details.\"}",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
"See http://developer.github.com/v3/#rate-limiting for details.\"}");
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -207,12 +206,11 @@ namespace Octokit.Tests.Http
|
||||
public async Task ThrowsLoginAttemptsExceededExceptionForForbiddenResponse()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.Forbidden,
|
||||
"{\"message\":\"Maximum number of login attempts exceeded\"," +
|
||||
"\"documentation_url\":\"http://developer.github.com/v3\"}",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
"\"documentation_url\":\"http://developer.github.com/v3\"}");
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -231,11 +229,9 @@ namespace Octokit.Tests.Http
|
||||
public async Task ThrowsNotFoundExceptionForFileNotFoundResponse()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.NotFound,
|
||||
"GONE BYE BYE!",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
"GONE BYE BYE!");
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
@@ -254,11 +250,10 @@ namespace Octokit.Tests.Http
|
||||
public async Task ThrowsForbiddenExceptionForUnknownForbiddenResponse()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.Forbidden,
|
||||
"YOU SHALL NOT PASS!",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
"YOU SHALL NOT PASS!");
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -278,12 +273,11 @@ namespace Octokit.Tests.Http
|
||||
var messageText = "blahblahblah this does not matter because we are testing the URL";
|
||||
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.Forbidden,
|
||||
"{\"message\":\"" + messageText + "\"," +
|
||||
"\"documentation_url\":\"https://developer.github.com/v3/#abuse-rate-limits\"}",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
"\"documentation_url\":\"https://developer.github.com/v3/#abuse-rate-limits\"}");
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -301,12 +295,11 @@ namespace Octokit.Tests.Http
|
||||
var messageText = "You have triggered an abuse detection mechanism. Please wait a few minutes before you try again.";
|
||||
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.Forbidden,
|
||||
"{\"message\":\"" + messageText + "\"," +
|
||||
"\"documentation_url\":\"https://ThisURLDoesNotMatter.com\"}",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
"\"documentation_url\":\"https://ThisURLDoesNotMatter.com\"}");
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -330,12 +323,12 @@ namespace Octokit.Tests.Http
|
||||
{ "Retry-After", "45" }
|
||||
};
|
||||
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.Forbidden,
|
||||
"{\"message\":\"" + messageText + "\"," +
|
||||
"\"documentation_url\":\"https://ThisURLDoesNotMatter.com\"}",
|
||||
headerDictionary,
|
||||
"application/json");
|
||||
headerDictionary);
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -355,12 +348,11 @@ namespace Octokit.Tests.Http
|
||||
string messageText = string.Empty;
|
||||
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response(
|
||||
var response = CreateResponse(
|
||||
HttpStatusCode.Forbidden,
|
||||
"{\"message\":\"" + messageText + "\"," +
|
||||
"\"documentation_url\":\"https://developer.github.com/v3/#abuse-rate-limits\"}",
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
"\"documentation_url\":\"https://developer.github.com/v3/#abuse-rate-limits\"}");
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -381,7 +373,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task SendsProperlyFormattedRequestWithProperAcceptHeader()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -412,7 +404,7 @@ namespace Octokit.Tests.Http
|
||||
var serializer = Substitute.For<IJsonSerializer>();
|
||||
serializer.Serialize(body).Returns(expectedData);
|
||||
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
httpClient.Send(Args.Request, Args.CancellationToken)
|
||||
.Returns(Task.FromResult(response));
|
||||
@@ -439,7 +431,8 @@ namespace Octokit.Tests.Http
|
||||
public async Task RunsConfiguredAppWithAcceptsOverride()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -462,7 +455,7 @@ namespace Octokit.Tests.Http
|
||||
var serializer = Substitute.For<IJsonSerializer>();
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
serializer.Serialize(body).Returns(expectedBody);
|
||||
|
||||
@@ -492,7 +485,7 @@ namespace Octokit.Tests.Http
|
||||
var serializer = Substitute.For<IJsonSerializer>();
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
serializer.Serialize(body).Returns(expectedBody);
|
||||
|
||||
@@ -522,7 +515,7 @@ namespace Octokit.Tests.Http
|
||||
var serializer = Substitute.For<IJsonSerializer>();
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
serializer.Serialize(body).Returns(expectedBody);
|
||||
|
||||
@@ -553,7 +546,7 @@ namespace Octokit.Tests.Http
|
||||
var serializer = Substitute.For<IJsonSerializer>();
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
serializer.Serialize(body).Returns(expectedBody);
|
||||
|
||||
@@ -586,7 +579,7 @@ namespace Octokit.Tests.Http
|
||||
var serializer = Substitute.For<IJsonSerializer>();
|
||||
var data = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
serializer.Serialize(body).Returns(data);
|
||||
|
||||
@@ -613,7 +606,8 @@ namespace Octokit.Tests.Http
|
||||
public async Task SendsProperlyFormattedPostRequestWithCorrectHeaders()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -641,7 +635,8 @@ namespace Octokit.Tests.Http
|
||||
public async Task SetsAcceptsHeader()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -668,7 +663,7 @@ namespace Octokit.Tests.Http
|
||||
public async Task SendsProperlyFormattedDeleteRequest()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
var response = CreateResponse(HttpStatusCode.OK);
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
@@ -815,10 +810,9 @@ namespace Octokit.Tests.Http
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
|
||||
// We really only care about the ApiInfo property...
|
||||
var expectedResponse = new Response(HttpStatusCode.OK, null, new Dictionary<string, string>(), "application/json")
|
||||
{
|
||||
ApiInfo = apiInfo
|
||||
};
|
||||
var expectedResponse = Substitute.For<IResponse>();
|
||||
expectedResponse.StatusCode.Returns(HttpStatusCode.OK);
|
||||
expectedResponse.ApiInfo.Returns(apiInfo);
|
||||
|
||||
httpClient.Send(Arg.Any<IRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IResponse>(expectedResponse));
|
||||
|
||||
@@ -6,6 +6,8 @@ using System.Net;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
using static Octokit.Internal.TestSetup;
|
||||
|
||||
namespace Octokit.Tests.Http
|
||||
{
|
||||
public class JsonHttpPipelineTests
|
||||
@@ -107,11 +109,10 @@ namespace Octokit.Tests.Http
|
||||
public void DeserializesResponse()
|
||||
{
|
||||
const string data = "works";
|
||||
var httpResponse = new Response(
|
||||
var httpResponse = CreateResponse(
|
||||
HttpStatusCode.OK,
|
||||
SimpleJson.SerializeObject(data),
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
SimpleJson.SerializeObject(data));
|
||||
|
||||
var jsonPipeline = new JsonHttpPipeline();
|
||||
|
||||
var response = jsonPipeline.DeserializeResponse<string>(httpResponse);
|
||||
@@ -124,7 +125,7 @@ namespace Octokit.Tests.Http
|
||||
public void IgnoresResponsesNotIdentifiedAsJsonWhenNotDeserializingToString()
|
||||
{
|
||||
const string data = "works";
|
||||
var httpResponse = new Response(
|
||||
var httpResponse = CreateResponse(
|
||||
HttpStatusCode.OK,
|
||||
SimpleJson.SerializeObject(data),
|
||||
new Dictionary<string, string>(),
|
||||
@@ -141,11 +142,9 @@ namespace Octokit.Tests.Http
|
||||
{
|
||||
const string data = "{\"name\":\"Haack\"}";
|
||||
var jsonPipeline = new JsonHttpPipeline();
|
||||
var httpResponse = new Response(
|
||||
var httpResponse = CreateResponse(
|
||||
HttpStatusCode.OK,
|
||||
data,
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
data);
|
||||
|
||||
var response = jsonPipeline.DeserializeResponse<List<SomeObject>>(httpResponse);
|
||||
|
||||
@@ -175,11 +174,10 @@ namespace Octokit.Tests.Http
|
||||
""sha"": ""object-sha"",
|
||||
""url"": ""object-url""
|
||||
}}";
|
||||
var httpResponse = new Response(
|
||||
var httpResponse = CreateResponse(
|
||||
HttpStatusCode.OK,
|
||||
data,
|
||||
new Dictionary<string, string>(),
|
||||
"application/json");
|
||||
data);
|
||||
|
||||
var jsonPipeline = new JsonHttpPipeline();
|
||||
|
||||
var response = jsonPipeline.DeserializeResponse<GitTag>(httpResponse);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
#if !NO_SERIALIZABLE
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
#endif
|
||||
using Xunit;
|
||||
@@ -104,7 +104,8 @@ namespace Octokit.Tests.Http
|
||||
[Fact]
|
||||
public void EnsuresHeadersNotNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new RateLimit(null));
|
||||
IDictionary<string, string> dictionary = null;
|
||||
Assert.Throws<ArgumentNullException>(() => new RateLimit(dictionary));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,4 +128,4 @@ namespace Octokit.Tests.Http
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Octokit.Internal;
|
||||
using System.Net;
|
||||
using Xunit;
|
||||
|
||||
using static Octokit.Internal.TestSetup;
|
||||
|
||||
namespace Octokit.Tests.Http
|
||||
{
|
||||
public class ResponseTests
|
||||
@@ -10,7 +12,7 @@ namespace Octokit.Tests.Http
|
||||
[Fact]
|
||||
public void InitializesAllRequiredProperties()
|
||||
{
|
||||
var r = new Response();
|
||||
var r = CreateResponse(HttpStatusCode.OK);
|
||||
|
||||
Assert.NotNull(r.Headers);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user