Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC][WIP] Step 1: Move The World #985

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3ac8a6c
stubbed a couple of the new classes to encapsulate the HTTP things we…
shiftkey Dec 8, 2015
a6b2a04
HACK: stuff
shiftkey Dec 8, 2015
0adf899
HACK: more obsoletes
shiftkey Dec 8, 2015
eb5d9c6
extract these functions for mapping request/response from HttpClientA…
shiftkey Dec 8, 2015
18a6d73
HACK: better comments on obsolete code
shiftkey Dec 8, 2015
e9c3e0b
stubbed a simple implementation to mimic our current setup
shiftkey Dec 8, 2015
e0aa820
HACK: this is broken on master
shiftkey Dec 8, 2015
9fd8f3a
first pass at swapping in an alternative implementation of the HTTP s…
shiftkey Dec 8, 2015
51d0445
moved these tests over to use the builder functions
shiftkey Dec 8, 2015
a45f714
make new internals visible to integration tests
shiftkey Dec 8, 2015
091c395
test the new implementation
shiftkey Dec 8, 2015
0524e66
removed old implementation of HttpClientAdapter
shiftkey Dec 8, 2015
1e1f9f9
renamed the file
shiftkey Dec 8, 2015
3a7f77a
added a ctor which is friendly to the new way
shiftkey Dec 8, 2015
7ddd624
here's a sample of how creating a new client works
shiftkey Dec 8, 2015
3bb7b40
validate input
shiftkey Dec 8, 2015
9bcb18e
:lipstick: using statements
shiftkey Dec 8, 2015
ef5d528
un-obsolete
shiftkey Dec 8, 2015
3c1c778
noodling on setting the user-agent up front
shiftkey Dec 9, 2015
cb878fe
and a way to validate the user-agent is set
shiftkey Dec 9, 2015
e6b38ae
setup some other properties
shiftkey Dec 9, 2015
2a94d87
centralize setup so we can make ctors a bit more readable
shiftkey Dec 9, 2015
78178a2
rewrite this ctor to compose the HTTP connection
shiftkey Dec 9, 2015
05229d0
rewrite the other ctors to compose the HTTP connection
shiftkey Dec 9, 2015
d3af20c
always be suppressing
shiftkey Dec 9, 2015
e7f08a6
moved server URL munging into HttpClientFactory
shiftkey Dec 9, 2015
b9a52a2
introduced a method for generating the Authorization header value, in…
shiftkey Dec 9, 2015
56670a3
update implementation and test
shiftkey Dec 9, 2015
97d20ef
centralize a bit of this jank
shiftkey Dec 9, 2015
0581dcb
call out some further refactoring tasks
shiftkey Dec 9, 2015
0db04a4
updated sample
shiftkey Dec 9, 2015
3a63347
cheeky R# doesn't think this is necessary
shiftkey Dec 9, 2015
a5ff9cd
some day i'll learn how to computer
shiftkey Dec 9, 2015
fb2c9a1
Merge branch 'http-client-milestone' into http-client-define-interface
shiftkey Dec 20, 2015
624efdb
remove Timeout property as this is poorly supported currently
shiftkey Dec 20, 2015
6578c10
you must specify a UserAgent value when creating a ClientInfo
shiftkey Dec 20, 2015
740bb4e
mark some ctors for obsoletion
shiftkey Dec 20, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Octokit.Reactive/ObservableGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@ public class ObservableGitHubClient : IObservableGitHubClient
{
readonly IGitHubClient _gitHubClient;

[Obsolete("Use OctokitHttpClient.Create to configure your HTTP details, and then call the new ObservableGitHubClient ctor. This will be moved in a future release.")]
public ObservableGitHubClient(ProductHeaderValue productInformation)
: this(new GitHubClient(productInformation))
{
}

[Obsolete("Use OctokitHttpClient.Create to configure your HTTP details, and then call the new ObservableGitHubClient ctor. This will be moved in a future release.")]
public ObservableGitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore)
: this(new GitHubClient(productInformation, credentialStore))
{
}

[Obsolete("Use OctokitHttpClient.Create to configure your HTTP details, and then call the new ObservableGitHubClient ctor. This will be moved in a future release.")]
public ObservableGitHubClient(ProductHeaderValue productInformation, Uri baseAddress)
: this(new GitHubClient(productInformation, baseAddress))
{
}

[Obsolete("Use OctokitHttpClient.Create to configure your HTTP details, and then call the new ObservableGitHubClient ctor. This will be moved in a future release.")]
public ObservableGitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress)
: this(new GitHubClient(productInformation, credentialStore, baseAddress))
{
}

[Obsolete("Use OctokitHttpClient.Create to configure your HTTP details, and then call the new ObservableGitHubClient ctor. This will be moved in a future release.")]
public ObservableGitHubClient(IGitHubClient gitHubClient)
{
Ensure.ArgumentNotNull(gitHubClient, "githubClient");
Expand Down
26 changes: 23 additions & 3 deletions Octokit.Tests.Integration/Clients/GitHubClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Octokit.Internal;
using Xunit;

public class GitHubClientTests
{
public class Monkey
{
[IntegrationTest]
public void Setup()
{
var info = new ClientInfo("my-cool-app")
{
Credentials = new InMemoryCredentialStore(new Credentials("my-token-here")),
Server = new Uri("https://my-cool-enterprise.com")
};

var http = HttpClientFactory.Create(info);

var productHeader = new ProductHeaderValue("my-cool-app");
var connection = new Connection(productHeader, http);

// TODO: we probably need to guard here that we have enough
// information to use this client against the GitHub API
var github = new GitHubClient(connection);
}
}

public class TheLastApiInfoProperty
{
[IntegrationTest]
Expand Down
15 changes: 10 additions & 5 deletions Octokit.Tests.Integration/HttpClientAdapterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Octokit.Tests.Integration;
using Xunit;
Expand All @@ -14,18 +15,20 @@ public class TheSendAsyncMethod
[IntegrationTest]
public async Task CanDownloadImage()
{
var httpClient = new HttpClientAdapter(HttpMessageHandlerFactory.CreateDefault);
var httpClient = HttpClientFactory.Create();
var request = new Request
{
BaseAddress = new Uri("https://github.global.ssl.fastly.net/", UriKind.Absolute),
Endpoint = new Uri("/images/icons/emoji/poop.png?v=5", UriKind.RelativeOrAbsolute),
Method = HttpMethod.Get
};

var response = await httpClient.Send(request, CancellationToken.None);
var message = HttpRequestBuilder.Create(request);

var response = await httpClient.SendAsync(message, CancellationToken.None);

// Spot check some of dem bytes.
var imageBytes = (byte[])response.Body;
var imageBytes = await response.Content.ReadAsByteArrayAsync();
Assert.Equal(137, imageBytes[0]);
Assert.Equal(80, imageBytes[1]);
Assert.Equal(78, imageBytes[2]);
Expand All @@ -35,7 +38,7 @@ public async Task CanDownloadImage()
[IntegrationTest]
public async Task CanCancelARequest()
{
var httpClient = new HttpClientAdapter(HttpMessageHandlerFactory.CreateDefault);
var httpClient = HttpClientFactory.Create();
var request = new Request
{
BaseAddress = new Uri("https://github.global.ssl.fastly.net/", UriKind.Absolute),
Expand All @@ -44,7 +47,9 @@ public async Task CanCancelARequest()
Timeout = TimeSpan.FromMilliseconds(10)
};

var response = httpClient.Send(request, CancellationToken.None);
var message = HttpRequestBuilder.Create(request);

var response = httpClient.SendAsync(message, CancellationToken.None);

await Task.Delay(TimeSpan.FromSeconds(2));

Expand Down
15 changes: 11 additions & 4 deletions Octokit.Tests/Clients/EventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NSubstitute;
Expand Down Expand Up @@ -509,10 +511,15 @@ public async Task DeserializesStarredEventCorrectly()

private EventsClient GetTestingEventsClient(JsonObject response)
{
var responseString = response.ToString();
var httpClientMock = Substitute.For<IHttpClient>();
httpClientMock.Send(Arg.Is((IRequest r) => r.Endpoint.ToString().Contains("events")), Arg.Any<CancellationToken>()).Returns(Task.FromResult(
new Response(HttpStatusCode.Accepted, responseString, new Dictionary<string, string>(), "application/json") as IResponse));
var responseMessage = new HttpResponseMessage(HttpStatusCode.Accepted);
responseMessage.Content = new StringContent(response.ToString(), Encoding.UTF8, "application/json");

var httpClientMock = Substitute.For<HttpClient>();


httpClientMock
.SendAsync(Arg.Is<HttpRequestMessage>(r => r.RequestUri.ToString().Contains("events")), Arg.Any<CancellationToken>())
.Returns(Task.FromResult(responseMessage));

return new EventsClient(new ApiConnection(new Connection(new ProductHeaderValue("mock"), httpClientMock)));
}
Expand Down
12 changes: 9 additions & 3 deletions Octokit.Tests/GitHubClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ public void IsRetrievedFromCredentialStore()
{
var credentialStore = Substitute.For<ICredentialStore>();
credentialStore.GetCredentials().Returns(Task.Factory.StartNew(() => new Credentials("foo", "bar")));
var client = new GitHubClient(new ProductHeaderValue("OctokitTests"), credentialStore);

Assert.Equal("foo", client.Credentials.Login);
Assert.Equal("bar", client.Credentials.Password);
var info = new ClientInfo("Octokit-Tests")
{
Credentials = credentialStore
};

var http = HttpClientFactory.Create(info);

Assert.Equal("Basic", http.DefaultRequestHeaders.Authorization.Scheme);
Assert.NotEmpty(http.DefaultRequestHeaders.Authorization.Parameter);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Octokit.Tests/Helpers/Arg.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using NSubstitute;
using Octokit.Internal;
Expand Down Expand Up @@ -33,6 +34,11 @@ public static IRequest Request
get { return Arg.Any<IRequest>(); }
}

public static HttpRequestMessage HttpRequest
{
get { return Arg.Any<HttpRequestMessage>(); }
}

public static object Object
{
get { return Arg.Any<object>(); }
Expand Down
Loading