PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs

https://gitlab.com/WoomyNightClub/GitHub-API-.NET
C# | 452 lines | 355 code | 91 blank | 6 comment | 2 complexity | 4bea3c69486e6924be55b73d04c5abeb MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using Octokit;
  5. using Octokit.Tests.Integration;
  6. using Octokit.Tests.Integration.Helpers;
  7. using Xunit;
  8. public class IssuesEventsClientTests : IDisposable
  9. {
  10. private readonly IIssuesEventsClient _issuesEventsClient;
  11. private readonly IIssuesClient _issuesClient;
  12. private readonly RepositoryContext _context;
  13. public IssuesEventsClientTests()
  14. {
  15. var github = Helper.GetAuthenticatedClient();
  16. _issuesEventsClient = github.Issue.Events;
  17. _issuesClient = github.Issue;
  18. var repoName = Helper.MakeNameWithTimestamp("public-repo");
  19. _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result;
  20. }
  21. [IntegrationTest]
  22. public async Task CanListEventInfoForAnIssue()
  23. {
  24. var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
  25. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  26. var issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  27. Assert.Empty(issueEventInfo);
  28. var closed = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed });
  29. Assert.NotNull(closed);
  30. issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  31. Assert.Equal(1, issueEventInfo.Count);
  32. Assert.Equal(EventInfoState.Closed, issueEventInfo[0].Event);
  33. }
  34. [IntegrationTest]
  35. public async Task CanListEventInfoForAnIssueWithRepositoryId()
  36. {
  37. var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
  38. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  39. var issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  40. Assert.Empty(issueEventInfo);
  41. var closed = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed });
  42. Assert.NotNull(closed);
  43. issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.Repository.Id, issue.Number);
  44. Assert.Equal(1, issueEventInfo.Count);
  45. Assert.Equal(EventInfoState.Closed, issueEventInfo[0].Event);
  46. }
  47. [IntegrationTest]
  48. public async Task ReturnsCorrectCountOfEventInfosWithoutStart()
  49. {
  50. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  51. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  52. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  53. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  54. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  55. var options = new ApiOptions
  56. {
  57. PageSize = 3,
  58. PageCount = 1
  59. };
  60. var eventInfos = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);
  61. Assert.Equal(3, eventInfos.Count);
  62. }
  63. [IntegrationTest]
  64. public async Task ReturnsCorrectCountOfEventInfosWithoutStartWithRepositoryId()
  65. {
  66. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  67. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  68. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  69. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  70. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  71. var options = new ApiOptions
  72. {
  73. PageSize = 3,
  74. PageCount = 1
  75. };
  76. var eventInfos = await _issuesEventsClient.GetAllForIssue(_context.Repository.Id, issue.Number, options);
  77. Assert.Equal(3, eventInfos.Count);
  78. }
  79. [IntegrationTest]
  80. public async Task ReturnsCorrectCountOfEventInfosWithStart()
  81. {
  82. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  83. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  84. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  85. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  86. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  87. var options = new ApiOptions
  88. {
  89. PageSize = 2,
  90. PageCount = 1,
  91. StartPage = 2
  92. };
  93. var eventInfos = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options);
  94. Assert.Equal(1, eventInfos.Count);
  95. }
  96. [IntegrationTest]
  97. public async Task ReturnsCorrectCountOfEventInfosWithStartWithRepositoryId()
  98. {
  99. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  100. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  101. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  102. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  103. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  104. var options = new ApiOptions
  105. {
  106. PageSize = 2,
  107. PageCount = 1,
  108. StartPage = 2
  109. };
  110. var eventInfos = await _issuesEventsClient.GetAllForIssue(_context.Repository.Id, issue.Number, options);
  111. Assert.Equal(1, eventInfos.Count);
  112. }
  113. [IntegrationTest]
  114. public async Task ReturnsDistinctEventInfosBasedOnStartPage()
  115. {
  116. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  117. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  118. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  119. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  120. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  121. var startOptions = new ApiOptions
  122. {
  123. PageSize = 1,
  124. PageCount = 1
  125. };
  126. var firstPage = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, startOptions);
  127. var skipStartOptions = new ApiOptions
  128. {
  129. PageSize = 1,
  130. PageCount = 1,
  131. StartPage = 2
  132. };
  133. var secondPage = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number, skipStartOptions);
  134. Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
  135. }
  136. [IntegrationTest]
  137. public async Task ReturnsDistinctEventInfosBasedOnStartPageWithRepositoryId()
  138. {
  139. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  140. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  141. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  142. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  143. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  144. var startOptions = new ApiOptions
  145. {
  146. PageSize = 1,
  147. PageCount = 1
  148. };
  149. var firstPage = await _issuesEventsClient.GetAllForIssue(_context.Repository.Id, issue.Number, startOptions);
  150. var skipStartOptions = new ApiOptions
  151. {
  152. PageSize = 1,
  153. PageCount = 1,
  154. StartPage = 2
  155. };
  156. var secondPage = await _issuesEventsClient.GetAllForIssue(_context.Repository.Id, issue.Number, skipStartOptions);
  157. Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
  158. }
  159. [IntegrationTest]
  160. public async Task CanListIssueEventsForARepository()
  161. {
  162. // create 2 new issues
  163. var newIssue1 = new NewIssue("A test issue1") { Body = "Everything's coming up Millhouse" };
  164. var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" };
  165. var issue1 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1);
  166. await Task.Delay(1000);
  167. var issue2 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2);
  168. await Task.Delay(1000);
  169. // close and open issue1
  170. var closed1 = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new IssueUpdate { State = ItemState.Closed });
  171. Assert.NotNull(closed1);
  172. var reopened1 = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new IssueUpdate { State = ItemState.Open });
  173. Assert.NotNull(reopened1);
  174. // close issue2
  175. var closed2 = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue2.Number, new IssueUpdate { State = ItemState.Closed });
  176. Assert.NotNull(closed2);
  177. var issueEvents = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
  178. Assert.Equal(3, issueEvents.Count);
  179. Assert.Equal(2, issueEvents.Count(issueEvent => issueEvent.Issue.Body == "Everything's coming up Millhouse"));
  180. }
  181. [IntegrationTest]
  182. public async Task CanListIssueEventsForARepositoryWithRepositoryId()
  183. {
  184. // create 2 new issues
  185. var newIssue1 = new NewIssue("A test issue1") { Body = "Everything's coming up Millhouse" };
  186. var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" };
  187. var issue1 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1);
  188. await Task.Delay(1000);
  189. var issue2 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2);
  190. await Task.Delay(1000);
  191. // close and open issue1
  192. var closed1 = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new IssueUpdate { State = ItemState.Closed });
  193. Assert.NotNull(closed1);
  194. var reopened1 = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new IssueUpdate { State = ItemState.Open });
  195. Assert.NotNull(reopened1);
  196. // close issue2
  197. var closed2 = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue2.Number, new IssueUpdate { State = ItemState.Closed });
  198. Assert.NotNull(closed2);
  199. var issueEvents = await _issuesEventsClient.GetAllForRepository(_context.Repository.Id);
  200. Assert.Equal(3, issueEvents.Count);
  201. Assert.Equal(2, issueEvents.Count(issueEvent => issueEvent.Issue.Body == "Everything's coming up Millhouse"));
  202. }
  203. [IntegrationTest]
  204. public async Task ReturnsCorrectCountOfIssueEventsWithoutStart()
  205. {
  206. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  207. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  208. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  209. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  210. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  211. var options = new ApiOptions
  212. {
  213. PageSize = 3,
  214. PageCount = 1
  215. };
  216. var eventInfos = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
  217. Assert.Equal(3, eventInfos.Count);
  218. }
  219. [IntegrationTest]
  220. public async Task ReturnsCorrectCountOfIssueEventsWithoutStartWithRepositoryId()
  221. {
  222. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  223. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  224. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  225. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  226. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  227. var options = new ApiOptions
  228. {
  229. PageSize = 3,
  230. PageCount = 1
  231. };
  232. var eventInfos = await _issuesEventsClient.GetAllForRepository(_context.Repository.Id, options);
  233. Assert.Equal(3, eventInfos.Count);
  234. }
  235. [IntegrationTest]
  236. public async Task ReturnsCorrectCountOfIssueEventsWithStart()
  237. {
  238. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  239. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  240. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  241. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  242. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  243. var options = new ApiOptions
  244. {
  245. PageSize = 2,
  246. PageCount = 1,
  247. StartPage = 2
  248. };
  249. var eventInfos = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, options);
  250. Assert.Equal(1, eventInfos.Count);
  251. }
  252. [IntegrationTest]
  253. public async Task ReturnsCorrectCountOfIssueEventsWithStartWithRepositoryId()
  254. {
  255. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  256. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  257. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  258. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  259. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  260. var options = new ApiOptions
  261. {
  262. PageSize = 2,
  263. PageCount = 1,
  264. StartPage = 2
  265. };
  266. var eventInfos = await _issuesEventsClient.GetAllForRepository(_context.Repository.Id, options);
  267. Assert.Equal(1, eventInfos.Count);
  268. }
  269. [IntegrationTest]
  270. public async Task ReturnsDistinctIssueEventsBasedOnStartPage()
  271. {
  272. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  273. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  274. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  275. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  276. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  277. var startOptions = new ApiOptions
  278. {
  279. PageSize = 1,
  280. PageCount = 1
  281. };
  282. var firstPage = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, startOptions);
  283. var skipStartOptions = new ApiOptions
  284. {
  285. PageSize = 1,
  286. PageCount = 1,
  287. StartPage = 2
  288. };
  289. var secondPage = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, skipStartOptions);
  290. Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
  291. }
  292. [IntegrationTest]
  293. public async Task ReturnsDistinctIssueEventsBasedOnStartPageWithRepositoryId()
  294. {
  295. var newIssue = new NewIssue("issue 1") { Body = "A new unassigned issue" };
  296. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  297. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  298. await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  299. await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number);
  300. var startOptions = new ApiOptions
  301. {
  302. PageSize = 1,
  303. PageCount = 1
  304. };
  305. var firstPage = await _issuesEventsClient.GetAllForRepository(_context.Repository.Id, startOptions);
  306. var skipStartOptions = new ApiOptions
  307. {
  308. PageSize = 1,
  309. PageCount = 1,
  310. StartPage = 2
  311. };
  312. var secondPage = await _issuesEventsClient.GetAllForRepository(_context.Repository.Id, skipStartOptions);
  313. Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
  314. }
  315. [IntegrationTest]
  316. public async Task CanRetrieveIssueEventById()
  317. {
  318. var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
  319. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  320. var closed = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed });
  321. Assert.NotNull(closed);
  322. var issueEvents = await _issuesEventsClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
  323. int issueEventId = issueEvents[0].Id;
  324. var issueEventLookupById = await _issuesEventsClient.Get(_context.RepositoryOwner, _context.RepositoryName, issueEventId);
  325. Assert.Equal(issueEventId, issueEventLookupById.Id);
  326. Assert.Equal(issueEvents[0].Event, issueEventLookupById.Event);
  327. }
  328. [IntegrationTest]
  329. public async Task CanRetrieveIssueEventByIdWithRepositoryId()
  330. {
  331. var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
  332. var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);
  333. var closed = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed });
  334. Assert.NotNull(closed);
  335. var issueEvents = await _issuesEventsClient.GetAllForRepository(_context.Repository.Id);
  336. int issueEventId = issueEvents[0].Id;
  337. var issueEventLookupById = await _issuesEventsClient.Get(_context.Repository.Id, issueEventId);
  338. Assert.Equal(issueEventId, issueEventLookupById.Id);
  339. Assert.Equal(issueEvents[0].Event, issueEventLookupById.Event);
  340. }
  341. [IntegrationTest]
  342. public async Task CanDeserializeUnsubscribeEvent()
  343. {
  344. var client = Helper.GetAuthenticatedClient();
  345. var issue = await client.Issue.Events.Get("waffleio", "waffle.io", 142230057);
  346. Assert.Equal(EventInfoState.Unsubscribed, issue.Event);
  347. }
  348. [IntegrationTest]
  349. public async Task CanDeserializeMergedEvent()
  350. {
  351. var issueEvent = await _issuesEventsClient.Get("octokit", "octokit.net", 490490630);
  352. Assert.NotNull(issueEvent);
  353. Assert.Equal(EventInfoState.Merged, issueEvent.Event);
  354. Assert.Equal("0bb8747a0ad1a9efff201ea017a0a6a4f69b797e", issueEvent.CommitId);
  355. Assert.Equal(new Uri("https://api.github.com/repos/octokit/octokit.net/commits/0bb8747a0ad1a9efff201ea017a0a6a4f69b797e"), issueEvent.CommitUrl);
  356. }
  357. public void Dispose()
  358. {
  359. _context.Dispose();
  360. }
  361. }