using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; using Xunit; using Octokit.Tests.Integration.Helpers; public class IssuesLabelsClientTests : IDisposable { private readonly IIssuesLabelsClient _issuesLabelsClient; private readonly IIssuesClient _issuesClient; private readonly RepositoryContext _context; public IssuesLabelsClientTests() { var github = Helper.GetAuthenticatedClient(); _issuesLabelsClient = github.Issue.Labels; _issuesClient = github.Issue; var repoName = Helper.MakeNameWithTimestamp("public-repo"); _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result; } [IntegrationTest] public async Task CanListIssueLabelsForAnIssue() { var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; var newLabel = new NewLabel("test label", "FFFFFF"); var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel); var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.Empty(issueLabelsInfo); var issueUpdate = new IssueUpdate(); issueUpdate.AddLabel(label.Name); var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.NotNull(updated); issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.Single(issueLabelsInfo); Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color); Assert.Equal(newLabel.Description, issueLabelsInfo[0].Description); } [IntegrationTest] public async Task CanListIssueLabelsForAnIssueWithRepositoryId() { var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; var newLabel = new NewLabel("test label", "FFFFFF"); var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel); var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number); Assert.Empty(issueLabelsInfo); var issueUpdate = new IssueUpdate(); issueUpdate.AddLabel(label.Name); var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.NotNull(updated); issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number); Assert.Single(issueLabelsInfo); Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color); Assert.Equal(newLabel.Description, issueLabelsInfo[0].Description); } [IntegrationTest] public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAnIssue() { var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; var newLabel = new NewLabel("test label", "FFFFFF"); var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel); var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.Empty(issueLabelsInfo); var issueUpdate = new IssueUpdate(); issueUpdate.AddLabel(label.Name); var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.NotNull(updated); var options = new ApiOptions { PageCount = 1, PageSize = 1 }; issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options); Assert.Single(issueLabelsInfo); Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color); } [IntegrationTest] public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAnIssueWithRepositoryId() { var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; var newLabel = new NewLabel("test label", "FFFFFF"); var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel); var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number); Assert.Empty(issueLabelsInfo); var issueUpdate = new IssueUpdate(); issueUpdate.AddLabel(label.Name); var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.NotNull(updated); var options = new ApiOptions { PageCount = 1, PageSize = 1 }; issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number, options); Assert.Single(issueLabelsInfo); Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color); } [IntegrationTest] public async Task ReturnsCorrectCountOfIssueLabelsWithStartForAnIssue() { var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewIssue("A test issue") { Body = "A new unassigned issue" }); var issueUpdate = new IssueUpdate(); var labels = new List