Skip to content

Commit

Permalink
Add IssuesEventsClient implementation and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knunery committed Nov 3, 2013
1 parent 4868b0e commit 5ef086d
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 23 deletions.
93 changes: 74 additions & 19 deletions Octokit.Tests.Integration/IssuesEventsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
Expand All @@ -9,38 +10,92 @@
public class IssuesEventsClientTests
{
readonly IGitHubClient _gitHubClient;
readonly IIssuesEventsClient _issuesEventsClientClient;
readonly IIssuesClient _issuesClient;
readonly Repository _repository;
readonly string _owner;
readonly string _repositoryOwner;
readonly string _repositoryName;

public IssuesEventsClientTests()
{
_gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
_issuesEventsClientClient = _gitHubClient.Issue.Events;
_issuesClient = _gitHubClient.Issue;
var repoName = Helper.MakeNameWithTimestamp("public-repo");

_repository = _gitHubClient.Repository.Create(new NewRepository { Name = repoName }).Result;
_owner = _repository.Owner.Login;
_repositoryOwner = _repository.Owner.Login;
_repositoryName = _repository.Name;
}

//[IntegrationTest]
//public async Task CanListEventsForAnIssue()
//{
// throw new NotImplementedException();
//}

//[IntegrationTest]
//public async Task CanListEventsForARepository()
//{
// throw new NotImplementedException();
//}

//[IntegrationTest]
//public async Task CanRetrieveOneEvent()
//{
// throw new NotImplementedException();
//}
[IntegrationTest]
public async Task CanListEventInfoForAnIssue()
{
var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
var issue = await _issuesClient.Create(_repositoryOwner, _repositoryName, newIssue);

var issueEventInfo = await _issuesEventsClientClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number);
Assert.Empty(issueEventInfo);

var closed = _issuesClient.Update(_repositoryOwner, _repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed);
issueEventInfo = await _issuesEventsClientClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number);

Assert.Equal(1, issueEventInfo.Count);
Assert.Equal(EventInfoState.Closed, issueEventInfo[0].InfoState);
}

[IntegrationTest]
public async Task CanListIssueEventsForARepository()
{
// create 2 new issues
var newIssue1 = new NewIssue("A test issue1") { Body = "Everything's coming up Millhouse" };
var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" };

var issue1 = await _issuesClient.Create(_repositoryOwner, _repository.Name, newIssue1);
Thread.Sleep(1000);
var issue2 = await _issuesClient.Create(_repositoryOwner, _repository.Name, newIssue2);
Thread.Sleep(1000);

// close and open issue1
var closed1 = _issuesClient.Update(_repositoryOwner, _repository.Name, issue1.Number,new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed1);
var reopened1 = _issuesClient.Update(_repositoryOwner, _repository.Name, issue1.Number, new IssueUpdate { State = ItemState.Open })
.Result;
Assert.NotNull(reopened1);

// close issue2
var closed2 = _issuesClient.Update(_repositoryOwner, _repository.Name, issue2.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed2);

var issueEvents = await _issuesEventsClientClient.GetForRepository(_repositoryOwner, _repositoryName);

Assert.Equal(3, issueEvents.Count);
Assert.Equal(2, issueEvents.Count(issueEvent => issueEvent.Issue.Body == "Everything's coming up Millhouse"));
}

[IntegrationTest]
public async Task CanRetrieveIssueEventById()
{
var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
var issue = await _issuesClient.Create(_repositoryOwner, _repositoryName, newIssue);
var closed = _issuesClient.Update(_repositoryOwner, _repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed);
var issueEvents = await _issuesEventsClientClient.GetForRepository(_repositoryOwner, _repositoryName);
int issueEventId = issueEvents[0].Id;

var issueEventLookupById = await _issuesEventsClientClient.Get(_repositoryOwner, _repositoryName, issueEventId);

Assert.Equal(issueEventId, issueEventLookupById.Id);
Assert.Equal(issueEvents[0].InfoState, issueEventLookupById.InfoState);
}

public void Dispose()
{
Expand Down
7 changes: 7 additions & 0 deletions Octokit/Clients/IIssuesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ public interface IIssuesClient
{
IAssigneesClient Assignee { get; }

/// <summary>
/// Client for reading various event information associated with issues/pull requests.
/// This is useful both for display on issue/pull request information pages and also to
/// determine who should be notified of comments.
/// </summary>
IIssuesEventsClient Events { get; }

/// <summary>
/// Client for managing milestones.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Octokit/Clients/IIssuesEventsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IIssuesEventsClient
/// <param name="name">The name of the repository</param>
/// <param name="number">The issue number</param>
/// <returns></returns>
Task<IReadOnlyList<IssueEvent>> GetForIssue(string owner, string name, int number);
Task<IReadOnlyList<EventInfo>> GetForIssue(string owner, string name, int number);

/// <summary>
/// Gets all events for the repository.
Expand All @@ -37,7 +37,7 @@ public interface IIssuesEventsClient
/// </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="number">The event id</param>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
Expand Down
2 changes: 2 additions & 0 deletions Octokit/Clients/IssuesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public class IssuesClient : ApiClient, IIssuesClient
public IssuesClient(IApiConnection apiConnection) : base(apiConnection)
{
Assignee = new AssigneesClient(apiConnection);
Events = new IssuesEventsClient(apiConnection);
Milestone = new MilestonesClient(apiConnection);
}

public IAssigneesClient Assignee { get; private set; }
public IIssuesEventsClient Events { get; private set; }
public IMilestonesClient Milestone { get; private set; }

/// <summary>
Expand Down
39 changes: 39 additions & 0 deletions Octokit/Clients/IssuesEventsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
#if NET_45
using System.Collections.Generic;
#endif
using System.Threading.Tasks;

namespace Octokit
{
public class IssuesEventsClient : ApiClient, IIssuesEventsClient
{
public IssuesEventsClient(IApiConnection apiConnection) : base(apiConnection)
{
}

public Task<IReadOnlyList<EventInfo>> GetForIssue(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return ApiConnection.GetAll<EventInfo>(ApiUrls.IssuesEvents(owner, name, number));
}

public Task<IReadOnlyList<IssueEvent>> GetForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return ApiConnection.GetAll<IssueEvent>(ApiUrls.IssuesEvents(owner, name));
}

public Task<IssueEvent> Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return ApiConnection.Get<IssueEvent>(ApiUrls.IssuesEvent(owner, name, number));
}
}
}
31 changes: 29 additions & 2 deletions Octokit/Models/Response/IssueEvent.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
namespace Octokit
using System;

namespace Octokit
{
public class IssueEvent
{
public EventInfo EventInfo { get; set; }
/// <summary>
/// The id of the issue/pull request event.
/// </summary>
public int Id { get; set; }

public Uri Url { get; set; }

/// <summary>
/// Always the User that generated the event
/// </summary>
public Actor Actor { get; set; }

/// <summary>
/// Identifies the actual type of Event that occurred
/// </summary>
public EventInfoState InfoState { get; set; }

/// <summary>
/// The String SHA of a commit that referenced this Issue
/// </summary>
public string CommitId { get; set; }

/// <summary>
/// Date the event occurred for the issue/pull request.
/// </summary>
public DateTimeOffset CreatedAt { get; set; }

public Issue Issue { get; set; }
}
Expand Down
5 changes: 5 additions & 0 deletions Octokit/Octokit-netcore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Clients\IAuthorizationsClient.cs" />
<Compile Include="Clients\ICommitStatusClient.cs" />
<Compile Include="Clients\IIssuesClient.cs" />
<Compile Include="Clients\IIssuesEventsClient.cs" />
<Compile Include="Clients\IMilestonesClient.cs" />
<Compile Include="Clients\IMiscellaneousClient.cs" />
<Compile Include="Clients\INotificationsClient.cs" />
Expand All @@ -61,6 +62,7 @@
<Compile Include="Clients\IRepositoriesClient.cs" />
<Compile Include="Clients\ISshKeysClient.cs" />
<Compile Include="Clients\IssuesClient.cs" />
<Compile Include="Clients\IssuesEventsClient.cs" />
<Compile Include="Clients\IUsersClient.cs" />
<Compile Include="Clients\MilestonesClient.cs" />
<Compile Include="Clients\MiscellaneousClient.cs" />
Expand Down Expand Up @@ -136,13 +138,16 @@
<Compile Include="Models\Request\SshKeyUpdate.cs" />
<Compile Include="Models\Request\UserUpdate.cs" />
<Compile Include="Models\Response\Account.cs" />
<Compile Include="Models\Response\Actor.cs" />
<Compile Include="Models\Response\ApiError.cs" />
<Compile Include="Models\Response\ApiErrorDetail.cs" />
<Compile Include="Models\Response\Application.cs" />
<Compile Include="Models\Response\Authorization.cs" />
<Compile Include="Models\Response\CommitStatus.cs" />
<Compile Include="Models\Response\EmailAddress.cs" />
<Compile Include="Models\Response\EventInfo.cs" />
<Compile Include="Models\Response\Issue.cs" />
<Compile Include="Models\Response\IssueEvent.cs" />
<Compile Include="Models\Response\Label.cs" />
<Compile Include="Models\Response\Milestone.cs" />
<Compile Include="Models\Response\Notification.cs" />
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="Clients\IIssuesEventsClient.cs" />
<Compile Include="Clients\ICommitStatusClient.cs" />
<Compile Include="Clients\IssuesClient.cs" />
<Compile Include="Clients\IssuesEventsClient.cs" />
<Compile Include="Clients\MilestonesClient.cs" />
<Compile Include="Exceptions\NotFoundException.cs" />
<Compile Include="Clients\IAssigneesClient.cs" />
Expand Down

0 comments on commit 5ef086d

Please sign in to comment.