diff --git a/Octokit.Reactive/Clients/IObservableIssuesLabelsClient.cs b/Octokit.Reactive/Clients/IObservableIssuesLabelsClient.cs
index ec84de51..71619750 100644
--- a/Octokit.Reactive/Clients/IObservableIssuesLabelsClient.cs
+++ b/Octokit.Reactive/Clients/IObservableIssuesLabelsClient.cs
@@ -13,10 +13,23 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the issue
/// The list of labels
- IObservable GetAllForIssue(string owner, string repo, int number);
+ IObservable GetAllForIssue(string owner, string name, int number);
+
+ ///
+ /// Gets all labels for the issue.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the issue
+ /// Options for changing the API response
+ /// The list of labels
+ IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options);
///
/// Gets all labels for the repository.
@@ -25,111 +38,21 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The list of labels
- IObservable GetAllForRepository(string owner, string repo);
+ IObservable GetAllForRepository(string owner, string name);
///
- /// Gets a single Label by name.
+ /// Gets all labels for the repository.
///
///
- /// See the API documentation for more information.
+ /// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
- /// The name of the label
- /// The label
- [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
- Justification = "Method makes a network request")]
- IObservable Get(string owner, string repo, string name);
-
- ///
- /// Deletes a label.
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The name of the label
- ///
- IObservable Delete(string owner, string repo, string name);
-
- ///
- /// Creates a label.
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The data for the label to be created
- /// The created label
- IObservable Create(string owner, string repo, NewLabel newLabel);
-
- ///
- /// Updates a label.
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The name of the label
- /// The data for the label to be updated
- /// The updated label
- IObservable Update(string owner, string repo, string name, LabelUpdate labelUpdate);
-
- ///
- /// Adds a label to an issue
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The number of the issue
- /// The names of the labels to add
- ///
- IObservable AddToIssue(string owner, string repo, int number, string[] labels);
-
- ///
- /// Removes a label from an issue
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The number of the issue
- /// The name of the label to remove
- ///
- IObservable RemoveFromIssue(string owner, string repo, int number, string label);
-
- ///
- /// Replaces all labels on the specified issues with the provided labels
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The number of the issue
- /// The names of the labels to set
- ///
- IObservable ReplaceAllForIssue(string owner, string repo, int number, string[] labels);
-
- ///
- /// Removes all labels from an issue
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The number of the issue
- ///
- IObservable RemoveAllFromIssue(string owner, string repo, int number);
+ /// The name of the repository
+ /// Options for changing the API response
+ /// The list of labels
+ IObservable GetAllForRepository(string owner, string name, ApiOptions options);
///
/// Gets labels for every issue in a milestone
@@ -138,9 +61,124 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the milestone
///
- IObservable GetAllForMilestone(string owner, string repo, int number);
+ IObservable GetAllForMilestone(string owner, string name, int number);
+
+ ///
+ /// Gets labels for every issue in a milestone
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the milestone
+ /// Options for changing the API response
+ ///
+ IObservable GetAllForMilestone(string owner, string name, int number, ApiOptions options);
+
+ ///
+ /// Gets a single Label by name.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the label
+ /// The label
+ [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
+ Justification = "Method makes a network request")]
+ IObservable Get(string owner, string name, string labelName);
+
+ ///
+ /// Deletes a label.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the label
+ ///
+ IObservable Delete(string owner, string name, string labelName);
+
+ ///
+ /// Creates a label.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The data for the label to be created
+ /// The created label
+ IObservable Create(string owner, string name, NewLabel newLabel);
+
+ ///
+ /// Updates a label.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the label
+ /// The data for the label to be updated
+ /// The updated label
+ IObservable Update(string owner, string name, string labelName, LabelUpdate labelUpdate);
+
+ ///
+ /// Adds a label to an issue
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the issue
+ /// The names of the labels to add
+ ///
+ IObservable AddToIssue(string owner, string name, int number, string[] labels);
+
+ ///
+ /// Removes a label from an issue
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the issue
+ /// The name of the label to remove
+ ///
+ IObservable RemoveFromIssue(string owner, string name, int number, string labelName);
+
+ ///
+ /// Replaces all labels on the specified issues with the provided labels
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the issue
+ /// The names of the labels to set
+ ///
+ IObservable ReplaceAllForIssue(string owner, string name, int number, string[] labels);
+
+ ///
+ /// Removes all labels from an issue
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the issue
+ ///
+ IObservable RemoveAllFromIssue(string owner, string name, int number);
}
}
diff --git a/Octokit.Reactive/Clients/ObservableIssuesLabelsClient.cs b/Octokit.Reactive/Clients/ObservableIssuesLabelsClient.cs
index cf6bb5c7..3134a420 100644
--- a/Octokit.Reactive/Clients/ObservableIssuesLabelsClient.cs
+++ b/Octokit.Reactive/Clients/ObservableIssuesLabelsClient.cs
@@ -26,12 +26,35 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the issue
/// The list of labels
- public IObservable GetAllForIssue(string owner, string repo, int number)
+ public IObservable GetAllForIssue(string owner, string name, int number)
{
- return _connection.GetAndFlattenAllPages(ApiUrls.IssueLabels(owner, repo, number));
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+
+ return GetAllForIssue(owner, name, number, ApiOptions.None);
+ }
+
+ ///
+ /// Gets all labels for the issue.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the issue
+ /// Options for changing the API response
+ /// The list of labels
+ public IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(options, "options");
+
+ return _connection.GetAndFlattenAllPages(ApiUrls.IssueLabels(owner, name, number), options);
}
///
@@ -41,11 +64,71 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The list of labels
- public IObservable GetAllForRepository(string owner, string repo)
+ public IObservable GetAllForRepository(string owner, string name)
{
- return _connection.GetAndFlattenAllPages(ApiUrls.Labels(owner, repo));
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+
+ return GetAllForRepository(owner, name, ApiOptions.None);
+ }
+
+ ///
+ /// Gets all labels for the repository.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// Options for changing the API response
+ /// The list of labels
+ public IObservable GetAllForRepository(string owner, string name, ApiOptions options)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(options, "options");
+
+ return _connection.GetAndFlattenAllPages(ApiUrls.Labels(owner, name), options);
+ }
+
+ ///
+ /// Gets labels for every issue in a milestone
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the milestone
+ ///
+ public IObservable GetAllForMilestone(string owner, string name, int number)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+
+ return GetAllForMilestone(owner, name, number, ApiOptions.None);
+ }
+
+ ///
+ /// Gets labels for every issue in a milestone
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the milestone
+ /// Options for changing the API response
+ ///
+ public IObservable GetAllForMilestone(string owner, string name, int number, ApiOptions options)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(options, "options");
+
+ return _connection.GetAndFlattenAllPages(ApiUrls.MilestoneLabels(owner, name, number), options);
}
///
@@ -55,12 +138,16 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
- /// The name of the label
+ /// The name of the repository
+ /// The name of the label
/// The label
- public IObservable Get(string owner, string repo, string name)
+ public IObservable Get(string owner, string name, string labelName)
{
- return _client.Get(owner, repo, name).ToObservable();
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
+
+ return _client.Get(owner, name, labelName).ToObservable();
}
///
@@ -70,12 +157,16 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
- /// The name of the label
+ /// The name of the repository
+ /// The name of the label
///
- public IObservable Delete(string owner, string repo, string name)
+ public IObservable Delete(string owner, string name, string labelName)
{
- return _client.Delete(owner, repo, name).ToObservable();
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
+
+ return _client.Delete(owner, name, labelName).ToObservable();
}
///
@@ -85,12 +176,16 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The data for the label to be created
/// The created label
- public IObservable Create(string owner, string repo, NewLabel newLabel)
+ public IObservable Create(string owner, string name, NewLabel newLabel)
{
- return _client.Create(owner, repo, newLabel).ToObservable();
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(newLabel, "newLabel");
+
+ return _client.Create(owner, name, newLabel).ToObservable();
}
///
@@ -100,13 +195,18 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
- /// The name of the label
+ /// The name of the repository
+ /// The name of the label
/// The data for the label to be updated
/// The updated label
- public IObservable Update(string owner, string repo, string name, LabelUpdate labelUpdate)
+ public IObservable Update(string owner, string name, string labelName, LabelUpdate labelUpdate)
{
- return _client.Update(owner, repo, name, labelUpdate).ToObservable();
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(labelName, "labelName");
+ Ensure.ArgumentNotNull(labelUpdate, "labelUpdate");
+
+ return _client.Update(owner, name, labelName, labelUpdate).ToObservable();
}
///
@@ -116,13 +216,17 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the issue
/// The names of the labels to add
///
- public IObservable AddToIssue(string owner, string repo, int number, string[] labels)
+ public IObservable AddToIssue(string owner, string name, int number, string[] labels)
{
- return _client.AddToIssue(owner, repo, number, labels)
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(labels, "labels");
+
+ return _client.AddToIssue(owner, name, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: POST is not compatible with GetAndFlattenPages
}
@@ -135,13 +239,17 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the issue
- /// The name of the label to remove
+ /// The name of the label to remove
///
- public IObservable RemoveFromIssue(string owner, string repo, int number, string label)
+ public IObservable RemoveFromIssue(string owner, string name, int number, string labelName)
{
- return _client.RemoveFromIssue(owner, repo, number, label).ToObservable();
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
+
+ return _client.RemoveFromIssue(owner, name, number, labelName).ToObservable();
}
///
@@ -151,13 +259,17 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the issue
/// The names of the labels to set
///
- public IObservable ReplaceAllForIssue(string owner, string repo, int number, string[] labels)
+ public IObservable ReplaceAllForIssue(string owner, string name, int number, string[] labels)
{
- return _client.ReplaceAllForIssue(owner, repo, number, labels)
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(labels, "labels");
+
+ return _client.ReplaceAllForIssue(owner, name, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: PUT is not compatible with GetAndFlattenPages
}
@@ -169,27 +281,15 @@ namespace Octokit.Reactive
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the issue
///
- public IObservable RemoveAllFromIssue(string owner, string repo, int number)
+ public IObservable RemoveAllFromIssue(string owner, string name, int number)
{
- return _client.RemoveAllFromIssue(owner, repo, number).ToObservable();
- }
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
- ///
- /// Gets labels for every issue in a milestone
- ///
- ///
- /// See the API documentation for more information.
- ///
- /// The owner of the repository
- /// The name of the repository
- /// The number of the milestone
- ///
- public IObservable GetAllForMilestone(string owner, string repo, int number)
- {
- return _connection.GetAndFlattenAllPages(ApiUrls.MilestoneLabels(owner, repo, number));
+ return _client.RemoveAllFromIssue(owner, name, number).ToObservable();
}
}
}
\ No newline at end of file
diff --git a/Octokit.Tests.Integration/Clients/IssuesLabelsClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesLabelsClientTests.cs
index e6e2e8a6..4205b44c 100644
--- a/Octokit.Tests.Integration/Clients/IssuesLabelsClientTests.cs
+++ b/Octokit.Tests.Integration/Clients/IssuesLabelsClientTests.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
@@ -17,13 +19,14 @@ public class IssuesLabelsClientTests : IDisposable
_issuesLabelsClient = github.Issue.Labels;
_issuesClient = github.Issue;
+
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_context = github.CreateRepositoryContext(new NewRepository(repoName)).Result;
}
[IntegrationTest]
- public async Task CanListLabelsForAnIssue()
+ public async Task CanListIssueLabelsForAnIssue()
{
var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
var newLabel = new NewLabel("test label", "FFFFFF");
@@ -38,12 +41,117 @@ public class IssuesLabelsClientTests : IDisposable
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.Equal(1, issueLabelsInfo.Count);
Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
}
+ [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.Equal(1, issueLabelsInfo.Count);
+ 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();
+
+ for (int i = 0; i < 2; i++)
+ {
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("test label " + (i + 1), "FFFFF" + (i+1)));
+ labels.Add(label);
+ issueUpdate.AddLabel(label.Name);
+ }
+
+ var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
+ Assert.Empty(issueLabelsInfo);
+
+ var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
+ Assert.NotNull(updated);
+
+ var options = new ApiOptions
+ {
+ PageCount = 1,
+ PageSize = 1,
+ StartPage = 2
+ };
+
+ issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);
+
+ Assert.Equal(1, issueLabelsInfo.Count);
+ Assert.Equal(labels.Last().Color, issueLabelsInfo.First().Color);
+ }
+
+ [IntegrationTest]
+ public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForAnIssue()
+ {
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewIssue("A test issue") { Body = "A new unassigned issue" });
+ var issueUpdate = new IssueUpdate();
+
+ for (int i = 0; i < 2; i++)
+ {
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("test label " + (i + 1), "FFFFF" + (i + 1)));
+ issueUpdate.AddLabel(label.Name);
+ }
+
+ var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
+ Assert.Empty(issueLabelsInfo);
+
+ var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
+ Assert.NotNull(updated);
+
+ var startOptions = new ApiOptions
+ {
+ PageCount = 1,
+ PageSize = 1,
+ StartPage = 1
+ };
+
+ var firstPage = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, startOptions);
+
+ var skipStartOptions = new ApiOptions
+ {
+ PageSize = 1,
+ PageCount = 1,
+ StartPage = 2
+ };
+
+ var secondPage = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, skipStartOptions);
+
+ Assert.Equal(1, firstPage.Count);
+ Assert.Equal(1, secondPage.Count);
+ Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
+ }
+
[IntegrationTest]
public async Task CanListIssueLabelsForARepository()
{
@@ -60,6 +168,241 @@ public class IssuesLabelsClientTests : IDisposable
Assert.Equal(originalIssueLabels.Count + 2, issueLabels.Count);
}
+ [IntegrationTest]
+ public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForARepository()
+ {
+ for (int i = 0; i < 2; i++)
+ {
+ int k = i + 1;
+ var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
+ var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
+
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
+
+ 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
+ };
+
+ var issueLabelsInfo = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
+
+ Assert.Equal(1, issueLabelsInfo.Count);
+ }
+
+ [IntegrationTest]
+ public async Task ReturnsCorrectCountOfIssueLabelsWithStartForARepository()
+ {
+ for (int i = 0; i < 2; i++)
+ {
+ int k = i + 1;
+ var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
+ var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
+
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
+
+ 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,
+ StartPage = 2
+ };
+
+ var issueLabelsInfo = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
+
+ Assert.Equal(1, issueLabelsInfo.Count);
+ }
+
+ [IntegrationTest]
+ public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForARepository()
+ {
+ for (int i = 0; i < 2; i++)
+ {
+ int k = i + 1;
+ var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
+ var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
+
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
+
+ var issueUpdate = new IssueUpdate();
+ issueUpdate.AddLabel(label.Name);
+ var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
+ Assert.NotNull(updated);
+ }
+
+ var startOptions = new ApiOptions
+ {
+ PageCount = 1,
+ PageSize = 1,
+ StartPage = 1
+ };
+
+ var firstPage = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, startOptions);
+
+ var skipStartOptions = new ApiOptions
+ {
+ PageSize = 1,
+ PageCount = 1,
+ StartPage = 2
+ };
+
+ var secondPage = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, skipStartOptions);
+
+ Assert.Equal(1, firstPage.Count);
+ Assert.Equal(1, secondPage.Count);
+ Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
+ }
+
+ [IntegrationTest]
+ public async Task CanListLabelsForAnMilestone()
+ {
+ var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
+ var newLabel = new NewLabel("test label", "FFFFFF");
+ var newMilestone = new NewMilestone("New Milestone");
+
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
+ var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
+
+ var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number);
+ Assert.Empty(issueLabelsInfo);
+
+ var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
+ issueUpdate.AddLabel(label.Name);
+
+ var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
+ Assert.NotNull(updated);
+
+ issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number);
+
+ Assert.Equal(1, issueLabelsInfo.Count);
+ Assert.Equal(label.Color, issueLabelsInfo[0].Color);
+ }
+
+ [IntegrationTest]
+ public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAMilestone()
+ {
+ var newMilestone = new NewMilestone("New Milestone");
+ var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
+
+ for (int i = 0; i < 2; i++)
+ {
+ int k = i + 1;
+ var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
+ var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
+
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
+
+ var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
+ 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
+ };
+
+ var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, options);
+
+ Assert.Equal(1, issueLabelsInfo.Count);
+ }
+
+ [IntegrationTest]
+ public async Task ReturnsCorrectCountOfIssueLabelsWithStartForAMilestone()
+ {
+ var newMilestone = new NewMilestone("New Milestone");
+ var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
+
+ for (int i = 0; i < 2; i++)
+ {
+ int k = i + 1;
+ var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
+ var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
+
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
+
+ var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
+ 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,
+ StartPage = 2
+ };
+
+ var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, options);
+
+ Assert.Equal(1, issueLabelsInfo.Count);
+ }
+
+ [IntegrationTest]
+ public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForAMilestone()
+ {
+ var newMilestone = new NewMilestone("New Milestone");
+ var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
+
+ for (int i = 0; i < 2; i++)
+ {
+ int k = i + 1;
+ var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
+ var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
+
+ var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
+ var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
+
+ var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
+ issueUpdate.AddLabel(label.Name);
+ var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
+ Assert.NotNull(updated);
+ }
+
+ var startOptions = new ApiOptions
+ {
+ PageCount = 1,
+ PageSize = 1,
+ StartPage = 1
+ };
+
+ var firstPage = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, startOptions);
+
+ var skipStartOptions = new ApiOptions
+ {
+ PageSize = 1,
+ PageCount = 1,
+ StartPage = 2
+ };
+
+ var secondPage = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, skipStartOptions);
+
+ Assert.Equal(1, firstPage.Count);
+ Assert.Equal(1, secondPage.Count);
+ Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
+ }
+
[IntegrationTest]
public async Task CanRetrieveIssueLabelByName()
{
diff --git a/Octokit.Tests/Clients/IssuesLabelsClientTests.cs b/Octokit.Tests/Clients/IssuesLabelsClientTests.cs
index d614af4c..2a5dbd35 100644
--- a/Octokit.Tests/Clients/IssuesLabelsClientTests.cs
+++ b/Octokit.Tests/Clients/IssuesLabelsClientTests.cs
@@ -28,7 +28,25 @@ namespace Octokit.Tests.Clients
await client.GetAllForIssue("fake", "repo", 42);
- connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/labels"));
+ connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Args.ApiOptions);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithApiOptions()
+ {
+ var connection = Substitute.For();
+ var client = new IssuesLabelsClient(connection);
+
+ var options = new ApiOptions
+ {
+ PageCount = 1,
+ StartPage = 1,
+ PageSize = 1
+ };
+
+ await client.GetAllForIssue("fake", "repo", 42, options);
+
+ connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/labels"), options);
}
[Fact]
@@ -36,9 +54,16 @@ namespace Octokit.Tests.Clients
{
var client = new IssuesLabelsClient(Substitute.For());
- await Assert.ThrowsAsync(() => client.Get(null, "name", "label"));
- await Assert.ThrowsAsync(() => client.Get("owner", null, "label"));
- await Assert.ThrowsAsync(() => client.Get("owner", "name", null));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null));
+
+ await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1, ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None));
}
}
@@ -52,7 +77,25 @@ namespace Octokit.Tests.Clients
await client.GetAllForRepository("fake", "repo");
- connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/labels"));
+ connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/labels"), Args.ApiOptions);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithApiOptions()
+ {
+ var connection = Substitute.For();
+ var client = new IssuesLabelsClient(connection);
+
+ var options = new ApiOptions
+ {
+ PageCount = 1,
+ StartPage = 1,
+ PageSize = 1
+ };
+
+ await client.GetAllForRepository("fake", "repo", options);
+
+ connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/labels"), options);
}
[Fact]
@@ -60,21 +103,77 @@ namespace Octokit.Tests.Clients
{
var client = new IssuesLabelsClient(Substitute.For());
- await Assert.ThrowsAsync(() => client.Get(null, "name", "label"));
- await Assert.ThrowsAsync(() => client.Get("owner", null, "label"));
- await Assert.ThrowsAsync(() => client.Get("owner", "name", null));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name"));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null));
+
+ await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name"));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", ""));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None));
+ }
+ }
+
+ public class TheGetForMilestoneMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new IssuesLabelsClient(connection);
+
+ await client.GetAllForMilestone("fake", "repo", 42);
+
+ connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones/42/labels"), Args.ApiOptions);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithApiOptions()
+ {
+ var connection = Substitute.For();
+ var client = new IssuesLabelsClient(connection);
+
+ var options = new ApiOptions
+ {
+ PageCount = 1,
+ StartPage = 1,
+ PageSize = 1
+ };
+
+ await client.GetAllForMilestone("fake", "repo", 42, options);
+
+ connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones/42/labels"), options);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new IssuesLabelsClient(Substitute.For());
+
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone(null, "name", 42));
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone("owner", null, 42));
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone(null, "name", 42, ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone("owner", null, 42, ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone("owner", "name", 42, null));
+
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone("", "name", 42));
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone("owner", "", 42));
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone("", "name", 42, ApiOptions.None));
+ await Assert.ThrowsAsync(() => client.GetAllForMilestone("owner", "", 42, ApiOptions.None));
}
}
public class TheGetMethod
{
[Fact]
- public void RequestsCorrectUrl()
+ public async Task RequestsCorrectUrl()
{
var connection = Substitute.For();
var client = new IssuesLabelsClient(connection);
- client.Get("fake", "repo", "label");
+ await client.Get("fake", "repo", "label");
connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/labels/label"));
}
@@ -86,6 +185,11 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync(() => client.Get(null, "name", "label"));
await Assert.ThrowsAsync(() => client.Get("owner", null, "label"));
+ await Assert.ThrowsAsync(() => client.Get("owner", "name", null));
+
+ await Assert.ThrowsAsync(() => client.Get("", "name", "label"));
+ await Assert.ThrowsAsync(() => client.Get("owner", "", "label"));
+ await Assert.ThrowsAsync(() => client.Get("owner", "name", ""));
}
}
@@ -112,6 +216,9 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync(() => client.AddToIssue(null, "name", 42, labels));
await Assert.ThrowsAsync(() => client.AddToIssue("owner", null, 42, labels));
await Assert.ThrowsAsync(() => client.AddToIssue("owner", "name", 42, null));
+
+ await Assert.ThrowsAsync(() => client.AddToIssue("", "name", 42, labels));
+ await Assert.ThrowsAsync(() => client.AddToIssue("owner", "", 42, labels));
}
}
@@ -136,6 +243,10 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync(() => client.RemoveFromIssue(null, "name", 42, "label"));
await Assert.ThrowsAsync(() => client.RemoveFromIssue("owner", null, 42, "label"));
await Assert.ThrowsAsync(() => client.RemoveFromIssue("owner", "name", 42, null));
+
+ await Assert.ThrowsAsync(() => client.RemoveFromIssue("", "name", 42, "label"));
+ await Assert.ThrowsAsync(() => client.RemoveFromIssue("owner", "", 42, "label"));
+ await Assert.ThrowsAsync(() => client.RemoveFromIssue("owner", "name", 42, ""));
}
}
@@ -162,6 +273,9 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync(() => client.ReplaceAllForIssue(null, "name", 42, labels));
await Assert.ThrowsAsync(() => client.ReplaceAllForIssue("owner", null, 42, labels));
await Assert.ThrowsAsync(() => client.ReplaceAllForIssue("owner", "name", 42, null));
+
+ await Assert.ThrowsAsync(() => client.ReplaceAllForIssue("", "name", 42, labels));
+ await Assert.ThrowsAsync(() => client.ReplaceAllForIssue("owner", "", 42, labels));
}
}
@@ -185,29 +299,9 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync(() => client.RemoveAllFromIssue(null, "name", 42));
await Assert.ThrowsAsync(() => client.RemoveAllFromIssue("owner", null, 42));
- }
- }
- public class TheGetForMilestoneMethod
- {
- [Fact]
- public void GetsCorrectUrl()
- {
- var connection = Substitute.For();
- var client = new IssuesLabelsClient(connection);
-
- client.GetAllForMilestone("fake", "repo", 42);
-
- connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones/42/labels"));
- }
-
- [Fact]
- public async Task EnsuresNonNullArguments()
- {
- var client = new IssuesLabelsClient(Substitute.For());
-
- await Assert.ThrowsAsync(() => client.GetAllForMilestone(null, "name", 42));
- await Assert.ThrowsAsync(() => client.GetAllForMilestone("owner", null, 42));
+ await Assert.ThrowsAsync(() => client.RemoveAllFromIssue("", "name", 42));
+ await Assert.ThrowsAsync(() => client.RemoveAllFromIssue("owner", "", 42));
}
}
}
diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj
index 67e4dc85..87cd858a 100644
--- a/Octokit.Tests/Octokit.Tests.csproj
+++ b/Octokit.Tests/Octokit.Tests.csproj
@@ -207,6 +207,7 @@
+
diff --git a/Octokit.Tests/Reactive/ObservableIssuesLabelsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesLabelsClientTests.cs
new file mode 100644
index 00000000..589d4e68
--- /dev/null
+++ b/Octokit.Tests/Reactive/ObservableIssuesLabelsClientTests.cs
@@ -0,0 +1,317 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using NSubstitute;
+using Octokit.Reactive;
+using Xunit;
+
+namespace Octokit.Tests.Reactive
+{
+ public class ObservableIssuesLabelsClientTests
+ {
+ public class TheCtor
+ {
+ [Fact]
+ public void EnsuresNonNullArguments()
+ {
+ Assert.Throws(
+ () => new ObservableIssuesLabelsClient(null));
+ }
+ }
+
+ public class TheGetForIssueMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.GetAllForIssue("fake", "repo", 42);
+
+ connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Args.EmptyDictionary, null);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithApiOptions()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ var options = new ApiOptions
+ {
+ PageCount = 1,
+ StartPage = 1,
+ PageSize = 1
+ };
+
+ client.GetAllForIssue("fake", "repo", 42, options);
+
+ connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Arg.Is>(d => d.Count == 2), null);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.GetAllForIssue(null, "name", 1));
+ Assert.Throws(() => client.GetAllForIssue("owner", null, 1));
+ Assert.Throws(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None));
+ Assert.Throws(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None));
+ Assert.Throws(() => client.GetAllForIssue("owner", "name", 1, null));
+
+ Assert.Throws(() => client.GetAllForIssue("", "name", 1));
+ Assert.Throws(() => client.GetAllForIssue("owner", "", 1));
+ Assert.Throws(() => client.GetAllForIssue("", "name", 1, ApiOptions.None));
+ Assert.Throws(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None));
+ }
+ }
+
+ public class TheGetForRepositoryMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.GetAllForRepository("fake", "repo");
+
+ connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/labels"), Args.EmptyDictionary, null);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithApiOptions()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ var options = new ApiOptions
+ {
+ PageCount = 1,
+ StartPage = 1,
+ PageSize = 1
+ };
+
+ client.GetAllForRepository("fake", "repo", options);
+
+ connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/labels"), Arg.Is>(d => d.Count == 2), null);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.GetAllForRepository(null, "name"));
+ Assert.Throws(() => client.GetAllForRepository("owner", null));
+ Assert.Throws(() => client.GetAllForRepository(null, "name", ApiOptions.None));
+ Assert.Throws(() => client.GetAllForRepository("owner", null, ApiOptions.None));
+ Assert.Throws(() => client.GetAllForRepository("owner", "name", null));
+
+ Assert.Throws(() => client.GetAllForRepository("", "name"));
+ Assert.Throws(() => client.GetAllForRepository("owner", ""));
+ Assert.Throws(() => client.GetAllForRepository("", "name", ApiOptions.None));
+ Assert.Throws(() => client.GetAllForRepository("owner", "", ApiOptions.None));
+ }
+ }
+
+ public class TheGetForMilestoneMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.GetAllForMilestone("fake", "repo", 42);
+
+ connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones/42/labels"), Args.EmptyDictionary, null);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithApiOptions()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ var options = new ApiOptions
+ {
+ PageCount = 1,
+ StartPage = 1,
+ PageSize = 1
+ };
+
+ client.GetAllForMilestone("fake", "repo", 42, options);
+
+ connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones/42/labels"), Arg.Is>(d => d.Count == 2), null);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.GetAllForMilestone(null, "name", 42));
+ Assert.Throws(() => client.GetAllForMilestone("owner", null, 42));
+ Assert.Throws(() => client.GetAllForMilestone(null, "name", 42, ApiOptions.None));
+ Assert.Throws(() => client.GetAllForMilestone("owner", null, 42, ApiOptions.None));
+ Assert.Throws(() => client.GetAllForMilestone("owner", "name", 42, null));
+
+ Assert.Throws(() => client.GetAllForMilestone("", "name", 42));
+ Assert.Throws(() => client.GetAllForMilestone("owner", "", 42));
+ Assert.Throws(() => client.GetAllForMilestone("", "name", 42, ApiOptions.None));
+ Assert.Throws(() => client.GetAllForMilestone("owner", "", 42, ApiOptions.None));
+ }
+ }
+
+ public class TheGetMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var gitHubClient = Substitute.For();
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.Get("fake", "repo", "label");
+
+ gitHubClient.Issue.Labels.Received().Get("fake", "repo", "label");
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.Get(null, "name", "label"));
+ Assert.Throws(() => client.Get("owner", null, "label"));
+ Assert.Throws(() => client.Get("owner", "name", null));
+
+ Assert.Throws(() => client.Get("", "name", "label"));
+ Assert.Throws(() => client.Get("owner", "", "label"));
+ Assert.Throws(() => client.Get("owner", "name", ""));
+ }
+ }
+
+ public class TheAddToIssueMethod
+ {
+ readonly string[] labels = { "foo", "bar" };
+
+ [Fact]
+ public void PostsToCorrectUrl()
+ {
+ var gitHubClient = Substitute.For();
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.AddToIssue("fake", "repo", 42, labels);
+
+ gitHubClient.Issue.Labels.Received().AddToIssue("fake", "repo", 42, labels);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.AddToIssue(null, "name", 42, labels));
+ Assert.Throws(() => client.AddToIssue("owner", null, 42, labels));
+ Assert.Throws(() => client.AddToIssue("owner", "name", 42, null));
+
+ Assert.Throws(() => client.AddToIssue("", "name", 42, labels));
+ Assert.Throws(() => client.AddToIssue("owner", "", 42, labels));
+ }
+ }
+
+ public class TheRemoveFromIssueMethod
+ {
+ [Fact]
+ public void DeleteCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.RemoveFromIssue("fake", "repo", 42, "label");
+
+ connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/labels/label"));
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.RemoveFromIssue(null, "name", 42, "label"));
+ Assert.Throws(() => client.RemoveFromIssue("owner", null, 42, "label"));
+ Assert.Throws(() => client.RemoveFromIssue("owner", "name", 42, null));
+
+ Assert.Throws(() => client.RemoveFromIssue("", "name", 42, "label"));
+ Assert.Throws(() => client.RemoveFromIssue("owner", "", 42, "label"));
+ Assert.Throws(() => client.RemoveFromIssue("owner", "name", 42, ""));
+ }
+ }
+
+ public class TheReplaceForIssueMethod
+ {
+ readonly string[] labels = { "foo", "bar" };
+
+ [Fact]
+ public void PutsToCorrectUrl()
+ {
+ var gitHubClient = Substitute.For();
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.ReplaceAllForIssue("fake", "repo", 42, labels);
+
+ gitHubClient.Issue.Labels.Received().ReplaceAllForIssue("fake", "repo", 42, labels);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.ReplaceAllForIssue(null, "name", 42, labels));
+ Assert.Throws(() => client.ReplaceAllForIssue("owner", null, 42, labels));
+ Assert.Throws(() => client.ReplaceAllForIssue("owner", "name", 42, null));
+
+ Assert.Throws(() => client.ReplaceAllForIssue("", "name", 42, labels));
+ Assert.Throws(() => client.ReplaceAllForIssue("owner", "", 42, labels));
+ }
+ }
+
+ public class TheRemoveAllFromIssueMethod
+ {
+ [Fact]
+ public void DeletesCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var gitHubClient = new GitHubClient(connection);
+ var client = new ObservableIssuesLabelsClient(gitHubClient);
+
+ client.RemoveAllFromIssue("fake", "repo", 42);
+
+ connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/labels"));
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new ObservableIssuesLabelsClient(Substitute.For());
+
+ Assert.Throws(() => client.RemoveAllFromIssue(null, "name", 42));
+ Assert.Throws(() => client.RemoveAllFromIssue("owner", null, 42));
+
+ Assert.Throws(() => client.RemoveAllFromIssue("", "name", 42));
+ Assert.Throws(() => client.RemoveAllFromIssue("owner", "", 42));
+ }
+ }
+ }
+}
diff --git a/Octokit/Clients/IIssuesLabelsClient.cs b/Octokit/Clients/IIssuesLabelsClient.cs
index 3f4169db..3ec1fcd1 100644
--- a/Octokit/Clients/IIssuesLabelsClient.cs
+++ b/Octokit/Clients/IIssuesLabelsClient.cs
@@ -13,10 +13,23 @@ namespace Octokit
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The number of the issue
/// The list of labels
- Task> GetAllForIssue(string owner, string repo, int number);
+ Task> GetAllForIssue(string owner, string name, int number);
+
+ ///
+ /// Gets all labels for the issue.
+ ///
+ ///
+ /// See the API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The number of the issue
+ /// Options for changing the API response
+ /// The list of labels
+ Task> GetAllForIssue(string owner, string name, int number, ApiOptions options);
///
/// Gets all labels for the repository.
@@ -25,111 +38,21 @@ namespace Octokit
/// See the API documentation for more information.
///
/// The owner of the repository
- /// The name of the repository
+ /// The name of the repository
/// The list of labels
- Task> GetAllForRepository(string owner, string repo);
+ Task> GetAllForRepository(string owner, string name);
///
- /// Gets a single Label by name.
+ /// Gets all labels for the repository.
///
///
- /// See the