mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 11:24:44 +00:00
Merge pull request #1321 from dampir/fix1159
Add ApiOptions overloads to methods on I(Observable)IssuesEventsClient
This commit is contained in:
@@ -17,6 +17,19 @@ namespace Octokit.Reactive
|
||||
/// <returns></returns>
|
||||
IObservable<EventInfo> GetAllForIssue(string owner, string name, int number);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the issue.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-an-issue
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The issue number</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
IObservable<EventInfo> GetAllForIssue(string owner, string name, int number, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the repository.
|
||||
/// </summary>
|
||||
@@ -28,6 +41,18 @@ namespace Octokit.Reactive
|
||||
/// <returns></returns>
|
||||
IObservable<IssueEvent> GetAllForRepository(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-a-repository
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
IObservable<IssueEvent> GetAllForRepository(string owner, string name, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single event
|
||||
/// </summary>
|
||||
|
||||
@@ -29,7 +29,30 @@ namespace Octokit.Reactive
|
||||
/// <returns></returns>
|
||||
public IObservable<EventInfo> GetAllForIssue(string owner, string name, int number)
|
||||
{
|
||||
return _connection.GetAndFlattenAllPages<EventInfo>(ApiUrls.IssuesEvents(owner, name, number));
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return GetAllForIssue(owner, name, number, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the issue.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-an-issue
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The issue number</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<EventInfo> GetAllForIssue(string owner, string name, int number, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<EventInfo>(ApiUrls.IssuesEvents(owner, name, number), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,7 +66,29 @@ namespace Octokit.Reactive
|
||||
/// <returns></returns>
|
||||
public IObservable<IssueEvent> GetAllForRepository(string owner, string name)
|
||||
{
|
||||
return _connection.GetAndFlattenAllPages<IssueEvent>(ApiUrls.IssuesEvents(owner, name));
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return GetAllForRepository(owner, name, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-a-repository
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<IssueEvent> GetAllForRepository(string owner, string name, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<IssueEvent>(ApiUrls.IssuesEvents(owner, name), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -42,6 +42,76 @@ public class IssuesEventsClientTests : IDisposable
|
||||
Assert.Equal(EventInfoState.Closed, issueEventInfo[0].Event);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfEventInfosWithoutStart()
|
||||
{
|
||||
var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
|
||||
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 3,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var eventInfos = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);
|
||||
|
||||
Assert.Equal(3, eventInfos.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfEventInfosWithStart()
|
||||
{
|
||||
var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
|
||||
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 2,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var eventInfos = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);
|
||||
|
||||
Assert.Equal(1, eventInfos.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsDistinctEventInfosBasedOnStartPage()
|
||||
{
|
||||
var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
|
||||
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
|
||||
var startOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var firstPage = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, startOptions);
|
||||
|
||||
var skipStartOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var secondPage = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, skipStartOptions);
|
||||
|
||||
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task CanListIssueEventsForARepository()
|
||||
{
|
||||
@@ -73,6 +143,76 @@ public class IssuesEventsClientTests : IDisposable
|
||||
Assert.Equal(2, issueEvents.Count(issueEvent => issueEvent.Issue.Body == "Everything's coming up Millhouse"));
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfIssueEventsWithoutStart()
|
||||
{
|
||||
var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
|
||||
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 3,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var eventInfos = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
|
||||
|
||||
Assert.Equal(3, eventInfos.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfIssueEventsWithStart()
|
||||
{
|
||||
var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
|
||||
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 2,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var eventInfos = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
|
||||
|
||||
Assert.Equal(1, eventInfos.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsDistinctIssueEventsBasedOnStartPage()
|
||||
{
|
||||
var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
|
||||
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
|
||||
|
||||
var startOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var firstPage = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, startOptions);
|
||||
|
||||
var skipStartOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var secondPage = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, skipStartOptions);
|
||||
|
||||
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task CanRetrieveIssueEventById()
|
||||
{
|
||||
|
||||
@@ -27,7 +27,25 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
await client.GetAllForIssue("fake", "repo", 42);
|
||||
|
||||
connection.Received().GetAll<EventInfo>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/events"));
|
||||
connection.Received().GetAll<EventInfo>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/events"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssuesEventsClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAllForIssue("fake", "repo", 42, options);
|
||||
|
||||
connection.Received().GetAll<EventInfo>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/events"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -35,8 +53,12 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var client = new IssuesEventsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue("owner", "name", 1, null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +72,25 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
await client.GetAllForRepository("fake", "repo");
|
||||
|
||||
connection.Received().GetAll<IssueEvent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"));
|
||||
connection.Received().GetAll<IssueEvent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssuesEventsClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAllForRepository("fake", "repo", options);
|
||||
|
||||
connection.Received().GetAll<IssueEvent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -58,8 +98,12 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var client = new IssuesEventsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -223,6 +223,7 @@
|
||||
<Compile Include="Reactive\ObservablePullRequestReviewCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesEventsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryCommitsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryPagesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Internal;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableIssuesEventsClientTests
|
||||
{
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => new ObservableIssuesEventsClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetForIssueMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var result = new List<EventInfo> { new EventInfo() };
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableIssuesEventsClient(gitHubClient);
|
||||
|
||||
IApiResponse<List<EventInfo>> response = new ApiResponse<List<EventInfo>>(
|
||||
new Response
|
||||
{
|
||||
ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()),
|
||||
}, result);
|
||||
gitHubClient.Connection.Get<List<EventInfo>>(Args.Uri, Args.EmptyDictionary, null)
|
||||
.Returns(Task.FromResult(response));
|
||||
|
||||
var eventInfos = await client.GetAllForIssue("fake", "repo", 42).ToList();
|
||||
|
||||
connection.Received().Get<List<EventInfo>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/events"), Args.EmptyDictionary, null);
|
||||
Assert.Equal(1, eventInfos.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var result = new List<EventInfo> { new EventInfo() };
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableIssuesEventsClient(gitHubClient);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
IApiResponse<List<EventInfo>> response = new ApiResponse<List<EventInfo>>(
|
||||
new Response
|
||||
{
|
||||
ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()),
|
||||
}, result);
|
||||
gitHubClient.Connection.Get<List<EventInfo>>(Args.Uri, Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null)
|
||||
.Returns(Task.FromResult(response));
|
||||
|
||||
var eventInfos = await client.GetAllForIssue("fake", "repo", 42, options).ToList();
|
||||
|
||||
connection.Received().Get<List<EventInfo>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/events"), Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null);
|
||||
Assert.Equal(1, eventInfos.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableIssuesEventsClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue("owner", "name", 1, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetForRepositoryMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var result = new List<IssueEvent> { new IssueEvent() };
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableIssuesEventsClient(gitHubClient);
|
||||
|
||||
IApiResponse<List<IssueEvent>> response = new ApiResponse<List<IssueEvent>>(
|
||||
new Response
|
||||
{
|
||||
ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag1", new RateLimit()),
|
||||
}, result);
|
||||
gitHubClient.Connection.Get<List<IssueEvent>>(Args.Uri, Args.EmptyDictionary, null)
|
||||
.Returns(Task.FromResult(response));
|
||||
|
||||
var issueEvents = await client.GetAllForRepository("fake", "repo").ToList();
|
||||
|
||||
connection.Received().Get<List<IssueEvent>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), Args.EmptyDictionary, null);
|
||||
Assert.Equal(1, issueEvents.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var result = new List<IssueEvent> { new IssueEvent() };
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableIssuesEventsClient(gitHubClient);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
IApiResponse<List<IssueEvent>> response = new ApiResponse<List<IssueEvent>>(
|
||||
new Response
|
||||
{
|
||||
ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag1", new RateLimit()),
|
||||
}, result);
|
||||
gitHubClient.Connection.Get<List<IssueEvent>>(Args.Uri, Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null)
|
||||
.Returns(Task.FromResult(response));
|
||||
|
||||
var issueEvents = await client.GetAllForRepository("fake", "repo", options).ToList();
|
||||
|
||||
connection.Received().Get<List<IssueEvent>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null);
|
||||
Assert.Equal(1, issueEvents.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableIssuesEventsClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssuesEventsClient(gitHubClient);
|
||||
|
||||
client.Get("fake", "repo", 42);
|
||||
|
||||
gitHubClient.Received().Issue.Events.Get("fake", "repo", 42);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableIssuesEventsClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", 1));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,19 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<EventInfo>> GetAllForIssue(string owner, string name, int number);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the issue.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-an-issue
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The issue number</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<EventInfo>> GetAllForIssue(string owner, string name, int number, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the repository.
|
||||
/// </summary>
|
||||
@@ -35,6 +48,18 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<IssueEvent>> GetAllForRepository(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-a-repository
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<IssueEvent>> GetAllForRepository(string owner, string name, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single event
|
||||
/// </summary>
|
||||
|
||||
@@ -32,7 +32,27 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return ApiConnection.GetAll<EventInfo>(ApiUrls.IssuesEvents(owner, name, number));
|
||||
return GetAllForIssue(owner, name, number, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the issue.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-an-issue
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The issue number</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<EventInfo>> GetAllForIssue(string owner, string name, int number, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return ApiConnection.GetAll<EventInfo>(ApiUrls.IssuesEvents(owner, name, number), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,7 +69,26 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return ApiConnection.GetAll<IssueEvent>(ApiUrls.IssuesEvents(owner, name));
|
||||
return GetAllForRepository(owner, name, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all events for the repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/issues/events/#list-events-for-a-repository
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<IssueEvent>> GetAllForRepository(string owner, string name, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return ApiConnection.GetAll<IssueEvent>(ApiUrls.IssuesEvents(owner, name), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user