mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
Fixed merge conflicts
This commit is contained in:
@@ -262,6 +262,19 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:<2014-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheCreatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchUsersRequest("github");
|
||||
request.Created = DateRange.Between(new DateTime(2014, 1, 1), new DateTime(2014, 2, 1));
|
||||
client.SearchUsers(request);
|
||||
connection.Received().Get<SearchUsersResult>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "search/users"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:2014-01-01..2014-02-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheFollowersQualifier_GreaterThan()
|
||||
{
|
||||
@@ -546,6 +559,17 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:<=2011-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheCreatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchRepositoriesRequest("github");
|
||||
request.Created = DateRange.Between(new DateTime(2011, 1, 1), new DateTime(2012, 11, 11));
|
||||
client.SearchRepo(request);
|
||||
connection.Received().Get<SearchRepositoryResult>(Arg.Is<Uri>(u => u.ToString() == "search/repositories"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:2011-01-01..2012-11-11"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUpdatedQualifier()
|
||||
@@ -599,6 +623,18 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+pushed:<=2013-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUpdatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchRepositoriesRequest("github");
|
||||
request.Updated = DateRange.Between(new DateTime(2012, 4, 30), new DateTime(2012, 7, 4));
|
||||
client.SearchRepo(request);
|
||||
connection.Received().Get<SearchRepositoryResult>(Arg.Is<Uri>(u => u.ToString() == "search/repositories"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+pushed:2012-04-30..2012-07-04"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUserQualifier()
|
||||
{
|
||||
@@ -995,6 +1031,21 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+created:<=2014-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheCreatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchIssuesRequest("something");
|
||||
request.Created = DateRange.Between(new DateTime(2014, 1, 1), new DateTime(2014, 2, 2));
|
||||
|
||||
client.SearchIssues(request);
|
||||
|
||||
connection.Received().Get<SearchIssuesResult>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+created:2014-01-01..2014-02-02"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUpdatedQualifier_GreaterThan()
|
||||
{
|
||||
|
||||
@@ -152,6 +152,22 @@ namespace Octokit.Tests.Clients
|
||||
Args.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AllowsEmptyBody()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
|
||||
var client = new TeamsClient(apiConnection);
|
||||
|
||||
await client.AddMembership(1, "user");
|
||||
|
||||
connection.Received().Put<Dictionary<string, string>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "teams/1/memberships/user"),
|
||||
Arg.Is<object>(u => u == RequestBody.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullOrEmptyLogin()
|
||||
{
|
||||
|
||||
@@ -349,7 +349,8 @@ namespace Octokit.Tests.Http
|
||||
[Fact]
|
||||
public async Task MakesPutRequestWithData()
|
||||
{
|
||||
string data = SimpleJson.SerializeObject(new object());
|
||||
var body = new object();
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
@@ -359,20 +360,21 @@ namespace Octokit.Tests.Http
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), new object());
|
||||
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), body);
|
||||
|
||||
httpClient.Received(1).Send(Arg.Is<IRequest>(req =>
|
||||
req.BaseAddress == _exampleUri &&
|
||||
(string)req.Body == data &&
|
||||
(string)req.Body == expectedBody &&
|
||||
req.Method == HttpMethod.Put &&
|
||||
req.ContentType == "application/x-www-form-urlencoded" &&
|
||||
req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MakesPutRequestWithDataAndTwoFactor()
|
||||
public async Task MakesPutRequestWithNoData()
|
||||
{
|
||||
string data = SimpleJson.SerializeObject(new object());
|
||||
var body = RequestBody.Empty;
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
@@ -382,16 +384,65 @@ namespace Octokit.Tests.Http
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), new object(), "two-factor");
|
||||
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), body);
|
||||
|
||||
Console.WriteLine(expectedBody);
|
||||
|
||||
httpClient.Received(1).Send(Arg.Is<IRequest>(req =>
|
||||
req.BaseAddress == _exampleUri &&
|
||||
(string)req.Body == data &&
|
||||
(string)req.Body == expectedBody &&
|
||||
req.Method == HttpMethod.Put &&
|
||||
req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MakesPutRequestWithDataAndTwoFactor()
|
||||
{
|
||||
var body = new object();
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
Substitute.For<ICredentialStore>(),
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), body, "two-factor");
|
||||
|
||||
httpClient.Received(1).Send(Arg.Is<IRequest>(req =>
|
||||
req.BaseAddress == _exampleUri &&
|
||||
(string)req.Body == expectedBody &&
|
||||
req.Method == HttpMethod.Put &&
|
||||
req.Headers["X-GitHub-OTP"] == "two-factor" &&
|
||||
req.ContentType == "application/x-www-form-urlencoded" &&
|
||||
req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MakesPutRequestWithNoDataAndTwoFactor()
|
||||
{
|
||||
var body = RequestBody.Empty;
|
||||
var expectedBody = SimpleJson.SerializeObject(body);
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse response = new Response();
|
||||
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
|
||||
_exampleUri,
|
||||
Substitute.For<ICredentialStore>(),
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), body, "two-factor");
|
||||
|
||||
httpClient.Received(1).Send(Arg.Is<IRequest>(req =>
|
||||
req.BaseAddress == _exampleUri &&
|
||||
(string)req.Body == expectedBody &&
|
||||
req.Method == HttpMethod.Put &&
|
||||
req.Headers["X-GitHub-OTP"] == "two-factor" &&
|
||||
req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class ThePostMethod
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Octokit
|
||||
|
||||
try
|
||||
{
|
||||
response = await ApiConnection.Put<Dictionary<string, string>>(endpoint, null);
|
||||
response = await ApiConnection.Put<Dictionary<string, string>>(endpoint, RequestBody.Empty);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Container for the static <see cref="Empty"/> method that represents an
|
||||
/// intentional empty request body to avoid overloading <code>null</code>.
|
||||
/// </summary>
|
||||
public static class RequestBody
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible")]
|
||||
public static object Empty = new object();
|
||||
}
|
||||
}
|
||||
@@ -301,6 +301,16 @@ namespace Octokit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matches repositories with regards to both the <param name="from"/> and <param name="to"/> dates.
|
||||
/// </summary>
|
||||
/// <param name="from">earlier date of the two</param>
|
||||
/// <param name="to">latter date of the two</param>
|
||||
public DateRange(DateTime from, DateTime to)
|
||||
{
|
||||
query = string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd}..{1:yyyy-MM-dd}", from, to);
|
||||
}
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get { return String.Format(CultureInfo.InvariantCulture, "Query: {0}", query); }
|
||||
@@ -350,6 +360,18 @@ namespace Octokit
|
||||
return new DateRange(date, SearchQualifierOperator.GreaterThanOrEqualTo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// helper method to create a bounded Date Comparison
|
||||
/// e.g. 2015-08-01..2015-10-31
|
||||
/// </summary>
|
||||
/// <param name="from">earlier date of the two</param>
|
||||
/// <param name="to">latter date of the two</param>
|
||||
/// <returns><see cref="DateRange"/></returns>
|
||||
public static DateRange Between(DateTime from, DateTime to)
|
||||
{
|
||||
return new DateRange(from, to);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return query;
|
||||
|
||||
@@ -399,6 +399,7 @@
|
||||
<Compile Include="Models\Response\ResourceRateLimit.cs" />
|
||||
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
|
||||
<Compile Include="Exceptions\RepositoryFormatException.cs" />
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Http\IApiInfoProvider.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -415,6 +415,7 @@
|
||||
<Compile Include="Models\Response\ResourceRateLimit.cs" />
|
||||
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
|
||||
<Compile Include="Exceptions\RepositoryFormatException.cs" />
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Http\IApiInfoProvider.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
|
||||
@@ -408,6 +408,7 @@
|
||||
<Compile Include="Models\Response\ResourceRateLimit.cs" />
|
||||
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
|
||||
<Compile Include="Exceptions\RepositoryFormatException.cs" />
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Http\IApiInfoProvider.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
|
||||
|
||||
@@ -398,6 +398,7 @@
|
||||
<Compile Include="Models\Response\ResourceRateLimit.cs" />
|
||||
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
|
||||
<Compile Include="Exceptions\RepositoryFormatException.cs" />
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Http\IApiInfoProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -402,6 +402,7 @@
|
||||
<Compile Include="Models\Response\ResourceRateLimit.cs" />
|
||||
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
|
||||
<Compile Include="Exceptions\RepositoryFormatException.cs" />
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Http\IApiInfoProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
<Compile Include="Http\HttpMessageHandlerFactory.cs" />
|
||||
<Compile Include="Http\IApiInfoProvider.cs" />
|
||||
<Compile Include="Http\ProductHeaderValue.cs" />
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Models\Request\GistFileUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewMerge.cs" />
|
||||
<Compile Include="Models\Request\PublicRepositoryRequest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user