PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/Octokit.Tests.Integration/Clients/IssuesLabelsClientTests.cs

https://gitlab.com/WoomyNightClub/GitHub-API-.NET
C# | 1020 lines | 780 code | 240 blank | 0 comment | 16 complexity | ce9766fa207ed19d28df045aeb36a8fe MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Octokit;
  6. using Octokit.Tests.Integration;
  7. using Xunit;
  8. using Octokit.Tests.Integration.Helpers;
  9. public class IssuesLabelsClientTests : IDisposable
  10. {
  11. private readonly IIssuesLabelsClient _issuesLabelsClient;
  12. private readonly IIssuesClient _issuesClient;
  13. private readonly RepositoryContext _context;
  14. public IssuesLabelsClientTests()
  15. {
  16. var github = Helper.GetAuthenticatedClient();
  17. _issuesLabelsClient = github.Issue.Labels;
  18. _issuesClient = github.Issue;
  19. var repoName = Helper.MakeNameWithTimestamp("public-repo");
  20. _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result;
  21. }
  22. [IntegrationTest]
  23. public async Task CanListIssueLabelsForAnIssue()
  24. {
  25. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  26. var newLabel = new NewLabel("test label", "FFFFFF");
  27. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  28. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  29. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  30. Assert.Empty(issueLabelsInfo);
  31. var issueUpdate = new IssueUpdate();
  32. issueUpdate.AddLabel(label.Name);
  33. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  34. Assert.NotNull(updated);
  35. issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  36. Assert.Equal(1, issueLabelsInfo.Count);
  37. Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
  38. }
  39. [IntegrationTest]
  40. public async Task CanListIssueLabelsForAnIssueWithRepositoryId()
  41. {
  42. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  43. var newLabel = new NewLabel("test label", "FFFFFF");
  44. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  45. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  46. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  47. Assert.Empty(issueLabelsInfo);
  48. var issueUpdate = new IssueUpdate();
  49. issueUpdate.AddLabel(label.Name);
  50. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  51. Assert.NotNull(updated);
  52. issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  53. Assert.Equal(1, issueLabelsInfo.Count);
  54. Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
  55. }
  56. [IntegrationTest]
  57. public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAnIssue()
  58. {
  59. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  60. var newLabel = new NewLabel("test label", "FFFFFF");
  61. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  62. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  63. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  64. Assert.Empty(issueLabelsInfo);
  65. var issueUpdate = new IssueUpdate();
  66. issueUpdate.AddLabel(label.Name);
  67. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  68. Assert.NotNull(updated);
  69. var options = new ApiOptions
  70. {
  71. PageCount = 1,
  72. PageSize = 1
  73. };
  74. issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);
  75. Assert.Equal(1, issueLabelsInfo.Count);
  76. Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
  77. }
  78. [IntegrationTest]
  79. public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAnIssueWithRepositoryId()
  80. {
  81. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  82. var newLabel = new NewLabel("test label", "FFFFFF");
  83. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  84. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  85. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  86. Assert.Empty(issueLabelsInfo);
  87. var issueUpdate = new IssueUpdate();
  88. issueUpdate.AddLabel(label.Name);
  89. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  90. Assert.NotNull(updated);
  91. var options = new ApiOptions
  92. {
  93. PageCount = 1,
  94. PageSize = 1
  95. };
  96. issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number, options);
  97. Assert.Equal(1, issueLabelsInfo.Count);
  98. Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
  99. }
  100. [IntegrationTest]
  101. public async Task ReturnsCorrectCountOfIssueLabelsWithStartForAnIssue()
  102. {
  103. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewIssue("A test issue") { Body = "A new unassigned issue" });
  104. var issueUpdate = new IssueUpdate();
  105. var labels = new List<Label>();
  106. for (int i = 0; i < 2; i++)
  107. {
  108. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("test label " + (i + 1), "FFFFF" + (i+1)));
  109. labels.Add(label);
  110. issueUpdate.AddLabel(label.Name);
  111. }
  112. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  113. Assert.Empty(issueLabelsInfo);
  114. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  115. Assert.NotNull(updated);
  116. var options = new ApiOptions
  117. {
  118. PageCount = 1,
  119. PageSize = 1,
  120. StartPage = 2
  121. };
  122. issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);
  123. Assert.Equal(1, issueLabelsInfo.Count);
  124. Assert.Equal(labels.Last().Color, issueLabelsInfo.First().Color);
  125. }
  126. [IntegrationTest]
  127. public async Task ReturnsCorrectCountOfIssueLabelsWithStartForAnIssueWithRepositoryId()
  128. {
  129. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewIssue("A test issue") { Body = "A new unassigned issue" });
  130. var issueUpdate = new IssueUpdate();
  131. var labels = new List<Label>();
  132. for (int i = 0; i < 2; i++)
  133. {
  134. var label = await _issuesLabelsClient.Create(_context.Repository.Id, new NewLabel("test label " + (i + 1), "FFFFF" + (i+1)));
  135. labels.Add(label);
  136. issueUpdate.AddLabel(label.Name);
  137. }
  138. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  139. Assert.Empty(issueLabelsInfo);
  140. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  141. Assert.NotNull(updated);
  142. var options = new ApiOptions
  143. {
  144. PageCount = 1,
  145. PageSize = 1,
  146. StartPage = 2
  147. };
  148. issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number, options);
  149. Assert.Equal(1, issueLabelsInfo.Count);
  150. Assert.Equal(labels.Last().Color, issueLabelsInfo.First().Color);
  151. }
  152. [IntegrationTest]
  153. public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForAnIssue()
  154. {
  155. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewIssue("A test issue") { Body = "A new unassigned issue" });
  156. var issueUpdate = new IssueUpdate();
  157. for (int i = 0; i < 2; i++)
  158. {
  159. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("test label " + (i + 1), "FFFFF" + (i + 1)));
  160. issueUpdate.AddLabel(label.Name);
  161. }
  162. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  163. Assert.Empty(issueLabelsInfo);
  164. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  165. Assert.NotNull(updated);
  166. var startOptions = new ApiOptions
  167. {
  168. PageCount = 1,
  169. PageSize = 1,
  170. StartPage = 1
  171. };
  172. var firstPage = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, startOptions);
  173. var skipStartOptions = new ApiOptions
  174. {
  175. PageSize = 1,
  176. PageCount = 1,
  177. StartPage = 2
  178. };
  179. var secondPage = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, skipStartOptions);
  180. Assert.Equal(1, firstPage.Count);
  181. Assert.Equal(1, secondPage.Count);
  182. Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
  183. }
  184. [IntegrationTest]
  185. public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForAnIssueWithRepositoryId()
  186. {
  187. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, new NewIssue("A test issue") { Body = "A new unassigned issue" });
  188. var issueUpdate = new IssueUpdate();
  189. for (int i = 0; i < 2; i++)
  190. {
  191. var label = await _issuesLabelsClient.Create(_context.Repository.Id, new NewLabel("test label " + (i + 1), "FFFFF" + (i + 1)));
  192. issueUpdate.AddLabel(label.Name);
  193. }
  194. var issueLabelsInfo = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  195. Assert.Empty(issueLabelsInfo);
  196. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  197. Assert.NotNull(updated);
  198. var startOptions = new ApiOptions
  199. {
  200. PageCount = 1,
  201. PageSize = 1,
  202. StartPage = 1
  203. };
  204. var firstPage = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number, startOptions);
  205. var skipStartOptions = new ApiOptions
  206. {
  207. PageSize = 1,
  208. PageCount = 1,
  209. StartPage = 2
  210. };
  211. var secondPage = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number, skipStartOptions);
  212. Assert.Equal(1, firstPage.Count);
  213. Assert.Equal(1, secondPage.Count);
  214. Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
  215. }
  216. [IntegrationTest]
  217. public async Task CanListIssueLabelsForARepository()
  218. {
  219. var newLabel1 = new NewLabel("test label 1", "FFFFFF");
  220. var newLabel2 = new NewLabel("test label 2", "FFFFFF");
  221. var originalIssueLabels = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
  222. await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel1);
  223. await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel2);
  224. var issueLabels = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
  225. Assert.Equal(originalIssueLabels.Count + 2, issueLabels.Count);
  226. }
  227. [IntegrationTest]
  228. public async Task CanListIssueLabelsForARepositoryWithRepositoryId()
  229. {
  230. var newLabel1 = new NewLabel("test label 1", "FFFFFF");
  231. var newLabel2 = new NewLabel("test label 2", "FFFFFF");
  232. var originalIssueLabels = await _issuesLabelsClient.GetAllForRepository(_context.Repository.Id);
  233. await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel1);
  234. await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel2);
  235. var issueLabels = await _issuesLabelsClient.GetAllForRepository(_context.Repository.Id);
  236. Assert.Equal(originalIssueLabels.Count + 2, issueLabels.Count);
  237. }
  238. [IntegrationTest]
  239. public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForARepository()
  240. {
  241. for (int i = 0; i < 2; i++)
  242. {
  243. int k = i + 1;
  244. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  245. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  246. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  247. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  248. var issueUpdate = new IssueUpdate();
  249. issueUpdate.AddLabel(label.Name);
  250. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  251. Assert.NotNull(updated);
  252. }
  253. var options = new ApiOptions
  254. {
  255. PageCount = 1,
  256. PageSize = 1
  257. };
  258. var issueLabelsInfo = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
  259. Assert.Equal(1, issueLabelsInfo.Count);
  260. }
  261. [IntegrationTest]
  262. public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForARepositoryWithRepositoryId()
  263. {
  264. for (int i = 0; i < 2; i++)
  265. {
  266. int k = i + 1;
  267. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  268. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  269. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  270. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  271. var issueUpdate = new IssueUpdate();
  272. issueUpdate.AddLabel(label.Name);
  273. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  274. Assert.NotNull(updated);
  275. }
  276. var options = new ApiOptions
  277. {
  278. PageCount = 1,
  279. PageSize = 1
  280. };
  281. var issueLabelsInfo = await _issuesLabelsClient.GetAllForRepository(_context.Repository.Id, options);
  282. Assert.Equal(1, issueLabelsInfo.Count);
  283. }
  284. [IntegrationTest]
  285. public async Task ReturnsCorrectCountOfIssueLabelsWithStartForARepository()
  286. {
  287. for (int i = 0; i < 2; i++)
  288. {
  289. int k = i + 1;
  290. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  291. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  292. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  293. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  294. var issueUpdate = new IssueUpdate();
  295. issueUpdate.AddLabel(label.Name);
  296. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  297. Assert.NotNull(updated);
  298. }
  299. var options = new ApiOptions
  300. {
  301. PageCount = 1,
  302. PageSize = 1,
  303. StartPage = 2
  304. };
  305. var issueLabelsInfo = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
  306. Assert.Equal(1, issueLabelsInfo.Count);
  307. }
  308. [IntegrationTest]
  309. public async Task ReturnsCorrectCountOfIssueLabelsWithStartForARepositoryWithRepositoryId()
  310. {
  311. for (int i = 0; i < 2; i++)
  312. {
  313. int k = i + 1;
  314. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  315. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  316. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  317. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  318. var issueUpdate = new IssueUpdate();
  319. issueUpdate.AddLabel(label.Name);
  320. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  321. Assert.NotNull(updated);
  322. }
  323. var options = new ApiOptions
  324. {
  325. PageCount = 1,
  326. PageSize = 1,
  327. StartPage = 2
  328. };
  329. var issueLabelsInfo = await _issuesLabelsClient.GetAllForRepository(_context.Repository.Id, options);
  330. Assert.Equal(1, issueLabelsInfo.Count);
  331. }
  332. [IntegrationTest]
  333. public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForARepository()
  334. {
  335. for (int i = 0; i < 2; i++)
  336. {
  337. int k = i + 1;
  338. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  339. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  340. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  341. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  342. var issueUpdate = new IssueUpdate();
  343. issueUpdate.AddLabel(label.Name);
  344. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  345. Assert.NotNull(updated);
  346. }
  347. var startOptions = new ApiOptions
  348. {
  349. PageCount = 1,
  350. PageSize = 1,
  351. StartPage = 1
  352. };
  353. var firstPage = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, startOptions);
  354. var skipStartOptions = new ApiOptions
  355. {
  356. PageSize = 1,
  357. PageCount = 1,
  358. StartPage = 2
  359. };
  360. var secondPage = await _issuesLabelsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, skipStartOptions);
  361. Assert.Equal(1, firstPage.Count);
  362. Assert.Equal(1, secondPage.Count);
  363. Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
  364. }
  365. [IntegrationTest]
  366. public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForARepositoryWithRepositoryId()
  367. {
  368. for (int i = 0; i < 2; i++)
  369. {
  370. int k = i + 1;
  371. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  372. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  373. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  374. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  375. var issueUpdate = new IssueUpdate();
  376. issueUpdate.AddLabel(label.Name);
  377. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  378. Assert.NotNull(updated);
  379. }
  380. var startOptions = new ApiOptions
  381. {
  382. PageCount = 1,
  383. PageSize = 1,
  384. StartPage = 1
  385. };
  386. var firstPage = await _issuesLabelsClient.GetAllForRepository(_context.Repository.Id, startOptions);
  387. var skipStartOptions = new ApiOptions
  388. {
  389. PageSize = 1,
  390. PageCount = 1,
  391. StartPage = 2
  392. };
  393. var secondPage = await _issuesLabelsClient.GetAllForRepository(_context.Repository.Id, skipStartOptions);
  394. Assert.Equal(1, firstPage.Count);
  395. Assert.Equal(1, secondPage.Count);
  396. Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
  397. }
  398. [IntegrationTest]
  399. public async Task CanListLabelsForAnMilestone()
  400. {
  401. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  402. var newLabel = new NewLabel("test label", "FFFFFF");
  403. var newMilestone = new NewMilestone("New Milestone");
  404. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  405. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  406. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  407. var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number);
  408. Assert.Empty(issueLabelsInfo);
  409. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  410. issueUpdate.AddLabel(label.Name);
  411. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  412. Assert.NotNull(updated);
  413. issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number);
  414. Assert.Equal(1, issueLabelsInfo.Count);
  415. Assert.Equal(label.Color, issueLabelsInfo[0].Color);
  416. }
  417. [IntegrationTest]
  418. public async Task CanListLabelsForAnMilestoneWithRepositoryId()
  419. {
  420. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  421. var newLabel = new NewLabel("test label", "FFFFFF");
  422. var newMilestone = new NewMilestone("New Milestone");
  423. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  424. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  425. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  426. var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number);
  427. Assert.Empty(issueLabelsInfo);
  428. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  429. issueUpdate.AddLabel(label.Name);
  430. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  431. Assert.NotNull(updated);
  432. issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number);
  433. Assert.Equal(1, issueLabelsInfo.Count);
  434. Assert.Equal(label.Color, issueLabelsInfo[0].Color);
  435. }
  436. [IntegrationTest]
  437. public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAMilestone()
  438. {
  439. var newMilestone = new NewMilestone("New Milestone");
  440. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  441. for (int i = 0; i < 2; i++)
  442. {
  443. int k = i + 1;
  444. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  445. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  446. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  447. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  448. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  449. issueUpdate.AddLabel(label.Name);
  450. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  451. Assert.NotNull(updated);
  452. }
  453. var options = new ApiOptions
  454. {
  455. PageCount = 1,
  456. PageSize = 1
  457. };
  458. var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, options);
  459. Assert.Equal(1, issueLabelsInfo.Count);
  460. }
  461. [IntegrationTest]
  462. public async Task ReturnsCorrectCountOfIssueLabelsWithoutStartForAMilestoneWithRepositoryId()
  463. {
  464. var newMilestone = new NewMilestone("New Milestone");
  465. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  466. for (int i = 0; i < 2; i++)
  467. {
  468. int k = i + 1;
  469. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  470. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  471. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  472. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  473. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  474. issueUpdate.AddLabel(label.Name);
  475. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  476. Assert.NotNull(updated);
  477. }
  478. var options = new ApiOptions
  479. {
  480. PageCount = 1,
  481. PageSize = 1
  482. };
  483. var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number, options);
  484. Assert.Equal(1, issueLabelsInfo.Count);
  485. }
  486. [IntegrationTest]
  487. public async Task ReturnsCorrectCountOfIssueLabelsWithStartForAMilestone()
  488. {
  489. var newMilestone = new NewMilestone("New Milestone");
  490. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  491. for (int i = 0; i < 2; i++)
  492. {
  493. int k = i + 1;
  494. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  495. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  496. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  497. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  498. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  499. issueUpdate.AddLabel(label.Name);
  500. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  501. Assert.NotNull(updated);
  502. }
  503. var options = new ApiOptions
  504. {
  505. PageCount = 1,
  506. PageSize = 1,
  507. StartPage = 2
  508. };
  509. var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, options);
  510. Assert.Equal(1, issueLabelsInfo.Count);
  511. }
  512. [IntegrationTest]
  513. public async Task ReturnsCorrectCountOfIssueLabelsWithStartForAMilestoneWithRepositoryId()
  514. {
  515. var newMilestone = new NewMilestone("New Milestone");
  516. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  517. for (int i = 0; i < 2; i++)
  518. {
  519. int k = i + 1;
  520. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  521. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  522. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  523. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  524. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  525. issueUpdate.AddLabel(label.Name);
  526. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  527. Assert.NotNull(updated);
  528. }
  529. var options = new ApiOptions
  530. {
  531. PageCount = 1,
  532. PageSize = 1,
  533. StartPage = 2
  534. };
  535. var issueLabelsInfo = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number, options);
  536. Assert.Equal(1, issueLabelsInfo.Count);
  537. }
  538. [IntegrationTest]
  539. public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForAMilestone()
  540. {
  541. var newMilestone = new NewMilestone("New Milestone");
  542. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  543. for (int i = 0; i < 2; i++)
  544. {
  545. int k = i + 1;
  546. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  547. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  548. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  549. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  550. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  551. issueUpdate.AddLabel(label.Name);
  552. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  553. Assert.NotNull(updated);
  554. }
  555. var startOptions = new ApiOptions
  556. {
  557. PageCount = 1,
  558. PageSize = 1,
  559. StartPage = 1
  560. };
  561. var firstPage = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, startOptions);
  562. var skipStartOptions = new ApiOptions
  563. {
  564. PageSize = 1,
  565. PageCount = 1,
  566. StartPage = 2
  567. };
  568. var secondPage = await _issuesLabelsClient.GetAllForMilestone(_context.RepositoryOwner, _context.RepositoryName, milestone.Number, skipStartOptions);
  569. Assert.Equal(1, firstPage.Count);
  570. Assert.Equal(1, secondPage.Count);
  571. Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
  572. }
  573. [IntegrationTest]
  574. public async Task ReturnsDistinctIssueLabelsBasedOnStartPageForAMilestoneWithRepositoryId()
  575. {
  576. var newMilestone = new NewMilestone("New Milestone");
  577. var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone);
  578. for (int i = 0; i < 2; i++)
  579. {
  580. int k = i + 1;
  581. var newIssue = new NewIssue("A test issue " + k) { Body = "A new unassigned issue " + k };
  582. var newLabel = new NewLabel("test label " + k, "FFFFF" + k);
  583. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  584. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  585. var issueUpdate = new IssueUpdate { Milestone = milestone.Number };
  586. issueUpdate.AddLabel(label.Name);
  587. var updated = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate);
  588. Assert.NotNull(updated);
  589. }
  590. var startOptions = new ApiOptions
  591. {
  592. PageCount = 1,
  593. PageSize = 1,
  594. StartPage = 1
  595. };
  596. var firstPage = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number, startOptions);
  597. var skipStartOptions = new ApiOptions
  598. {
  599. PageSize = 1,
  600. PageCount = 1,
  601. StartPage = 2
  602. };
  603. var secondPage = await _issuesLabelsClient.GetAllForMilestone(_context.Repository.Id, milestone.Number, skipStartOptions);
  604. Assert.Equal(1, firstPage.Count);
  605. Assert.Equal(1, secondPage.Count);
  606. Assert.NotEqual(firstPage.First().Color, secondPage.First().Color);
  607. }
  608. [IntegrationTest]
  609. public async Task CanRetrieveIssueLabelByName()
  610. {
  611. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  612. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  613. Assert.NotNull(label);
  614. var issueLabelLookupByName = await _issuesLabelsClient.Get(_context.RepositoryOwner, _context.RepositoryName, label.Name);
  615. Assert.Equal(label.Name, issueLabelLookupByName.Name);
  616. Assert.Equal(label.Color, issueLabelLookupByName.Color);
  617. }
  618. [IntegrationTest]
  619. public async Task CanRetrieveIssueLabelByNameWithRepositoryId()
  620. {
  621. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  622. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  623. Assert.NotNull(label);
  624. var issueLabelLookupByName = await _issuesLabelsClient.Get(_context.Repository.Id, label.Name);
  625. Assert.Equal(label.Name, issueLabelLookupByName.Name);
  626. Assert.Equal(label.Color, issueLabelLookupByName.Color);
  627. }
  628. [IntegrationTest]
  629. public async Task CanDeleteIssueLabelByName()
  630. {
  631. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  632. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  633. Assert.NotNull(label);
  634. var issueLabelLookupByName = await _issuesLabelsClient.Get(_context.RepositoryOwner, _context.RepositoryName, label.Name);
  635. Assert.Equal(label.Name, issueLabelLookupByName.Name);
  636. Assert.Equal(label.Color, issueLabelLookupByName.Color);
  637. await _issuesLabelsClient.Delete(_context.RepositoryOwner, _context.RepositoryName, label.Name);
  638. await Assert.ThrowsAsync<NotFoundException>(() => _issuesLabelsClient.Get(_context.RepositoryOwner, _context.RepositoryName, label.Name));
  639. }
  640. [IntegrationTest]
  641. public async Task CanDeleteIssueLabelByNameWithRepositoryId()
  642. {
  643. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  644. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  645. Assert.NotNull(label);
  646. var issueLabelLookupByName = await _issuesLabelsClient.Get(_context.Repository.Id, label.Name);
  647. Assert.Equal(label.Name, issueLabelLookupByName.Name);
  648. Assert.Equal(label.Color, issueLabelLookupByName.Color);
  649. await _issuesLabelsClient.Delete(_context.RepositoryOwner, _context.RepositoryName, label.Name);
  650. await Assert.ThrowsAsync<NotFoundException>(() => _issuesLabelsClient.Get(_context.RepositoryOwner, _context.RepositoryName, label.Name));
  651. }
  652. [IntegrationTest]
  653. public async Task CanAddToIssue()
  654. {
  655. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  656. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  657. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  658. Assert.NotNull(label);
  659. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  660. Assert.NotNull(issue);
  661. await _issuesLabelsClient.AddToIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new []{ label.Name });
  662. var labels = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  663. Assert.NotEmpty(labels);
  664. Assert.Equal(label.Name, labels[0].Name);
  665. Assert.Equal(label.Color, labels[0].Color);
  666. }
  667. [IntegrationTest]
  668. public async Task CanAddToIssueWithRepositoryId()
  669. {
  670. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  671. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  672. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  673. Assert.NotNull(label);
  674. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  675. Assert.NotNull(issue);
  676. await _issuesLabelsClient.AddToIssue(_context.Repository.Id, issue.Number, new[] { label.Name });
  677. var labels = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  678. Assert.NotEmpty(labels);
  679. Assert.Equal(label.Name, labels[0].Name);
  680. Assert.Equal(label.Color, labels[0].Color);
  681. }
  682. [IntegrationTest]
  683. public async Task CanRemoveAllFromIssue()
  684. {
  685. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  686. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  687. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  688. Assert.NotNull(label);
  689. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  690. Assert.NotNull(issue);
  691. await _issuesLabelsClient.AddToIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new []{ label.Name });
  692. await _issuesLabelsClient.RemoveAllFromIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  693. var labels = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  694. Assert.Empty(labels);
  695. }
  696. [IntegrationTest]
  697. public async Task CanRemoveAllFromIssueWithRepositoryId()
  698. {
  699. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  700. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  701. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  702. Assert.NotNull(label);
  703. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  704. Assert.NotNull(issue);
  705. await _issuesLabelsClient.AddToIssue(_context.Repository.Id, issue.Number, new[] { label.Name });
  706. await _issuesLabelsClient.RemoveAllFromIssue(_context.Repository.Id, issue.Number);
  707. var labels = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  708. Assert.Empty(labels);
  709. }
  710. [IntegrationTest]
  711. public async Task CanRemoveFromIssue()
  712. {
  713. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  714. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  715. var label = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel);
  716. Assert.NotNull(label);
  717. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  718. Assert.NotNull(issue);
  719. await _issuesLabelsClient.AddToIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new []{ label.Name });
  720. await _issuesLabelsClient.RemoveFromIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, label.Name);
  721. var labels = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  722. Assert.Empty(labels);
  723. }
  724. [IntegrationTest]
  725. public async Task CanRemoveFromIssueWithRepositoryId()
  726. {
  727. var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  728. var newLabel = new NewLabel("test label 1b", "FFFFFF");
  729. var label = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel);
  730. Assert.NotNull(label);
  731. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  732. Assert.NotNull(issue);
  733. await _issuesLabelsClient.AddToIssue(_context.Repository.Id, issue.Number, new[] { label.Name });
  734. await _issuesLabelsClient.RemoveFromIssue(_context.Repository.Id, issue.Number, label.Name);
  735. var labels = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  736. Assert.Empty(labels);
  737. }
  738. [IntegrationTest]
  739. public async Task CanReplaceAllForIssue()
  740. {
  741. var newIssue1 = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  742. var newLabel1 = new NewLabel("test label 1b", "FFFFFF");
  743. var newLabel2 = new NewLabel("test label 1a", "FFFFFF");
  744. var label1 = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel1);
  745. Assert.NotNull(label1);
  746. var label2 = await _issuesLabelsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newLabel2);
  747. Assert.NotNull(label2);
  748. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1);
  749. Assert.NotNull(issue);
  750. await _issuesLabelsClient.AddToIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new []{ label1.Name });
  751. await _issuesLabelsClient.ReplaceAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new[] { label2.Name });
  752. var labels = await _issuesLabelsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  753. Assert.NotEmpty(labels);
  754. Assert.Equal(label2.Name, labels[0].Name);
  755. Assert.Equal(label2.Color, labels[0].Color);
  756. }
  757. [IntegrationTest]
  758. public async Task CanReplaceAllForIssueWithRepositoryId()
  759. {
  760. var newIssue1 = new NewIssue("A test issue") { Body = "A new unassigned issue" };
  761. var newLabel1 = new NewLabel("test label 1b", "FFFFFF");
  762. var newLabel2 = new NewLabel("test label 1a", "FFFFFF");
  763. var label1 = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel1);
  764. Assert.NotNull(label1);
  765. var label2 = await _issuesLabelsClient.Create(_context.Repository.Id, newLabel2);
  766. Assert.NotNull(label2);
  767. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1);
  768. Assert.NotNull(issue);
  769. await _issuesLabelsClient.AddToIssue(_context.Repository.Id, issue.Number, new[] { label1.Name });
  770. await _issuesLabelsClient.ReplaceAllForIssue(_context.Repository.Id, issue.Number, new[] { label2.Name });
  771. var labels = await _issuesLabelsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  772. Assert.NotEmpty(labels);
  773. Assert.Equal(label2.Name, labels[0].Name);
  774. Assert.Equal(label2.Color, labels[0].Color);
  775. }
  776. public void Dispose()
  777. {
  778. _context.Dispose();
  779. }
  780. }