PageRenderTime 32ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs

https://gitlab.com/WoomyNightClub/GitHub-API-.NET
C# | 769 lines | 599 code | 158 blank | 12 comment | 4 complexity | e47db874a2b6f3ed32e7014cf66fe97f 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 Octokit.Tests.Integration.Helpers;
  8. using Xunit;
  9. public class RepositoryCommentsClientTests
  10. {
  11. public class TheGetMethod
  12. {
  13. readonly IGitHubClient _github;
  14. readonly IRepositoryCommentsClient _fixture;
  15. const string owner = "octocat";
  16. const string name = "Hello-World";
  17. const int repositoryId = 1296269;
  18. public TheGetMethod()
  19. {
  20. _github = Helper.GetAuthenticatedClient();
  21. _fixture = _github.Repository.Comment;
  22. }
  23. [IntegrationTest]
  24. public async Task CanGetComment()
  25. {
  26. var commit = await _fixture.Get(owner, name, 1467023);
  27. Assert.NotNull(commit);
  28. }
  29. [IntegrationTest]
  30. public async Task CanGetCommentWithRepositoryId()
  31. {
  32. var commit = await _fixture.Get(repositoryId, 1467023);
  33. Assert.NotNull(commit);
  34. }
  35. [IntegrationTest]
  36. public async Task CanGetReactionPayload()
  37. {
  38. using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("CommitCommentsReactionTests")))
  39. {
  40. // Create a test commit
  41. var commit = await HelperCreateCommit(context.RepositoryOwner, context.RepositoryName);
  42. // Create a test comment with reactions
  43. var commentId = await HelperCreateCommitCommentWithReactions(context.RepositoryOwner, context.RepositoryName, commit.Sha);
  44. // Retrieve the comment
  45. var retrieved = await _fixture.Get(context.RepositoryOwner, context.RepositoryName, commentId);
  46. // Check the reactions
  47. Assert.True(retrieved.Id > 0);
  48. Assert.Equal(6, retrieved.Reactions.TotalCount);
  49. Assert.Equal(1, retrieved.Reactions.Plus1);
  50. Assert.Equal(1, retrieved.Reactions.Hooray);
  51. Assert.Equal(1, retrieved.Reactions.Heart);
  52. Assert.Equal(1, retrieved.Reactions.Laugh);
  53. Assert.Equal(1, retrieved.Reactions.Confused);
  54. Assert.Equal(1, retrieved.Reactions.Minus1);
  55. }
  56. }
  57. }
  58. public class TheGetAllForRepositoryMethod
  59. {
  60. readonly IGitHubClient _github;
  61. readonly IRepositoryCommentsClient _fixture;
  62. const string owner = "octocat";
  63. const string name = "Hello-World";
  64. const int repositoryId = 1296269;
  65. public TheGetAllForRepositoryMethod()
  66. {
  67. _github = Helper.GetAuthenticatedClient();
  68. _fixture = _github.Repository.Comment;
  69. }
  70. [IntegrationTest]
  71. public async Task CanGetListOfCommentsForRepository()
  72. {
  73. var list = await _fixture.GetAllForRepository(owner, name);
  74. Assert.NotEmpty(list);
  75. }
  76. [IntegrationTest]
  77. public async Task CanGetListOfCommentsForRepositoryWithRepositoryId()
  78. {
  79. var list = await _fixture.GetAllForRepository(repositoryId);
  80. Assert.NotEmpty(list);
  81. }
  82. [IntegrationTest]
  83. public async Task CanGetCorrectCountOfCommentsWithoutStart()
  84. {
  85. var options = new ApiOptions
  86. {
  87. PageSize = 5,
  88. PageCount = 1
  89. };
  90. var commits = await _fixture.GetAllForRepository(owner, name, options);
  91. Assert.Equal(5, commits.Count);
  92. }
  93. [IntegrationTest]
  94. public async Task CanGetCorrectCountOfCommentsWithoutStartWithRepositoryId()
  95. {
  96. var options = new ApiOptions
  97. {
  98. PageSize = 5,
  99. PageCount = 1
  100. };
  101. var commits = await _fixture.GetAllForRepository(repositoryId, options);
  102. Assert.Equal(5, commits.Count);
  103. }
  104. [IntegrationTest]
  105. public async Task CanGetCorrectCountOfCommentsWithStart()
  106. {
  107. var options = new ApiOptions
  108. {
  109. PageSize = 5,
  110. PageCount = 1,
  111. StartPage = 2
  112. };
  113. var commits = await _fixture.GetAllForRepository(owner, name, options);
  114. Assert.Equal(5, commits.Count);
  115. }
  116. [IntegrationTest]
  117. public async Task CanGetCorrectCountOfCommentsWithStartWithRepositoryId()
  118. {
  119. var options = new ApiOptions
  120. {
  121. PageSize = 5,
  122. PageCount = 1,
  123. StartPage = 2
  124. };
  125. var commits = await _fixture.GetAllForRepository(repositoryId, options);
  126. Assert.Equal(5, commits.Count);
  127. }
  128. [IntegrationTest]
  129. public async Task ReturnsDistinctResultsBasedOnStart()
  130. {
  131. var startOptions = new ApiOptions
  132. {
  133. PageSize = 5,
  134. PageCount = 1
  135. };
  136. var skipStartOptions = new ApiOptions
  137. {
  138. PageSize = 5,
  139. PageCount = 1,
  140. StartPage = 2
  141. };
  142. var firstCommit = await _fixture.GetAllForRepository(owner, name, startOptions);
  143. var secondCommit = await _fixture.GetAllForRepository(owner, name, skipStartOptions);
  144. Assert.NotEqual(firstCommit[0].Id, secondCommit[0].Id);
  145. Assert.NotEqual(firstCommit[1].Id, secondCommit[1].Id);
  146. Assert.NotEqual(firstCommit[2].Id, secondCommit[2].Id);
  147. Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id);
  148. Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id);
  149. }
  150. [IntegrationTest]
  151. public async Task ReturnsDistinctResultsBasedOnStartWithRepositoryId()
  152. {
  153. var startOptions = new ApiOptions
  154. {
  155. PageSize = 5,
  156. PageCount = 1
  157. };
  158. var skipStartOptions = new ApiOptions
  159. {
  160. PageSize = 5,
  161. PageCount = 1,
  162. StartPage = 2
  163. };
  164. var firstCommit = await _fixture.GetAllForRepository(repositoryId, startOptions);
  165. var secondCommit = await _fixture.GetAllForRepository(repositoryId, skipStartOptions);
  166. Assert.NotEqual(firstCommit[0].Id, secondCommit[0].Id);
  167. Assert.NotEqual(firstCommit[1].Id, secondCommit[1].Id);
  168. Assert.NotEqual(firstCommit[2].Id, secondCommit[2].Id);
  169. Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id);
  170. Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id);
  171. }
  172. [IntegrationTest]
  173. public async Task CanGetReactionPayload()
  174. {
  175. var numberToCreate = 2;
  176. using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("CommitCommentsReactionTests")))
  177. {
  178. var commentIds = new List<int>();
  179. // Create multiple test commits
  180. for (int count = 1; count <= numberToCreate; count++)
  181. {
  182. var commit = await HelperCreateCommit(context.RepositoryOwner, context.RepositoryName);
  183. // Each with a comment with reactions
  184. var commentId = await HelperCreateCommitCommentWithReactions(context.RepositoryOwner, context.RepositoryName, commit.Sha);
  185. commentIds.Add(commentId);
  186. }
  187. Assert.Equal(numberToCreate, commentIds.Count);
  188. // Retrieve all comments for the repo
  189. var commitComments = await _fixture.GetAllForRepository(context.RepositoryOwner, context.RepositoryName);
  190. // Check the reactions
  191. foreach (var commentId in commentIds)
  192. {
  193. var retrieved = commitComments.FirstOrDefault(x => x.Id == commentId);
  194. Assert.NotNull(retrieved);
  195. Assert.Equal(6, retrieved.Reactions.TotalCount);
  196. Assert.Equal(1, retrieved.Reactions.Plus1);
  197. Assert.Equal(1, retrieved.Reactions.Hooray);
  198. Assert.Equal(1, retrieved.Reactions.Heart);
  199. Assert.Equal(1, retrieved.Reactions.Laugh);
  200. Assert.Equal(1, retrieved.Reactions.Confused);
  201. Assert.Equal(1, retrieved.Reactions.Minus1);
  202. }
  203. }
  204. }
  205. }
  206. public class TheGetAllForCommitMethod
  207. {
  208. readonly IGitHubClient _github;
  209. readonly IRepositoryCommentsClient _fixture;
  210. const string owner = "octocat";
  211. const string name = "Hello-World";
  212. const int repositoryId = 1296269;
  213. public TheGetAllForCommitMethod()
  214. {
  215. _github = Helper.GetAuthenticatedClient();
  216. _fixture = _github.Repository.Comment;
  217. }
  218. [IntegrationTest]
  219. public async Task CanGetListOfCommentsForCommit()
  220. {
  221. var list = await _fixture.GetAllForCommit(owner, name, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d");
  222. Assert.NotEmpty(list);
  223. }
  224. [IntegrationTest]
  225. public async Task CanGetListOfCommentsForCommitWithRepositoryId()
  226. {
  227. var list = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d");
  228. Assert.NotEmpty(list);
  229. }
  230. [IntegrationTest]
  231. public async Task CanGetCorrectCountOfCommentsWithoutStartForCommit()
  232. {
  233. var options = new ApiOptions
  234. {
  235. PageSize = 5,
  236. PageCount = 1
  237. };
  238. var commits = await _fixture.GetAllForCommit(owner, name, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", options);
  239. Assert.Equal(5, commits.Count);
  240. }
  241. [IntegrationTest]
  242. public async Task CanGetCorrectCountOfCommentsWithoutStartForCommitWithRepositoryId()
  243. {
  244. var options = new ApiOptions
  245. {
  246. PageSize = 5,
  247. PageCount = 1
  248. };
  249. var commits = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", options);
  250. Assert.Equal(5, commits.Count);
  251. }
  252. [IntegrationTest]
  253. public async Task CanGetCorrectCountOfCommentsWithStartForCommit()
  254. {
  255. var options = new ApiOptions
  256. {
  257. PageSize = 5,
  258. PageCount = 1,
  259. StartPage = 2
  260. };
  261. var commits = await _fixture.GetAllForCommit(owner, name, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", options);
  262. Assert.Equal(5, commits.Count);
  263. }
  264. [IntegrationTest]
  265. public async Task CanGetCorrectCountOfCommentsWithStartForCommitWithRepositoryId()
  266. {
  267. var options = new ApiOptions
  268. {
  269. PageSize = 5,
  270. PageCount = 1,
  271. StartPage = 2
  272. };
  273. var commits = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", options);
  274. Assert.Equal(5, commits.Count);
  275. }
  276. [IntegrationTest]
  277. public async Task ReturnsDistinctResultsBasedOnStartForCommit()
  278. {
  279. var startOptions = new ApiOptions
  280. {
  281. PageSize = 5,
  282. PageCount = 1
  283. };
  284. var skipStartOptions = new ApiOptions
  285. {
  286. PageSize = 5,
  287. PageCount = 1,
  288. StartPage = 2
  289. };
  290. var firstCommit = await _fixture.GetAllForCommit(owner, name, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", startOptions);
  291. var secondCommit = await _fixture.GetAllForCommit(owner, name, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", skipStartOptions);
  292. Assert.NotEqual(firstCommit[0].Id, secondCommit[0].Id);
  293. Assert.NotEqual(firstCommit[1].Id, secondCommit[1].Id);
  294. Assert.NotEqual(firstCommit[2].Id, secondCommit[2].Id);
  295. Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id);
  296. Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id);
  297. }
  298. [IntegrationTest]
  299. public async Task ReturnsDistinctResultsBasedOnStartForCommitWithRepositoryId()
  300. {
  301. var startOptions = new ApiOptions
  302. {
  303. PageSize = 5,
  304. PageCount = 1
  305. };
  306. var skipStartOptions = new ApiOptions
  307. {
  308. PageSize = 5,
  309. PageCount = 1,
  310. StartPage = 2
  311. };
  312. var firstCommit = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", startOptions);
  313. var secondCommit = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", skipStartOptions);
  314. Assert.NotEqual(firstCommit[0].Id, secondCommit[0].Id);
  315. Assert.NotEqual(firstCommit[1].Id, secondCommit[1].Id);
  316. Assert.NotEqual(firstCommit[2].Id, secondCommit[2].Id);
  317. Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id);
  318. Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id);
  319. }
  320. [IntegrationTest]
  321. public async Task CanGetReactionPayload()
  322. {
  323. var numberToCreate = 2;
  324. using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("CommitCommentsReactionTests")))
  325. {
  326. var commentIds = new List<int>();
  327. // Create a single test commit
  328. var commit = await HelperCreateCommit(context.RepositoryOwner, context.RepositoryName);
  329. // With multiple comments with reactions
  330. for (int count = 1; count <= numberToCreate; count++)
  331. {
  332. var commentId = await HelperCreateCommitCommentWithReactions(context.RepositoryOwner, context.RepositoryName, commit.Sha);
  333. commentIds.Add(commentId);
  334. }
  335. Assert.Equal(numberToCreate, commentIds.Count);
  336. // Retrieve all comments for the commit
  337. var commitComments = await _fixture.GetAllForCommit(context.RepositoryOwner, context.RepositoryName, commit.Sha);
  338. // Check the reactions
  339. foreach (var commentId in commentIds)
  340. {
  341. var retrieved = commitComments.FirstOrDefault(x => x.Id == commentId);
  342. Assert.NotNull(retrieved);
  343. Assert.Equal(6, retrieved.Reactions.TotalCount);
  344. Assert.Equal(1, retrieved.Reactions.Plus1);
  345. Assert.Equal(1, retrieved.Reactions.Hooray);
  346. Assert.Equal(1, retrieved.Reactions.Heart);
  347. Assert.Equal(1, retrieved.Reactions.Laugh);
  348. Assert.Equal(1, retrieved.Reactions.Confused);
  349. Assert.Equal(1, retrieved.Reactions.Minus1);
  350. }
  351. }
  352. }
  353. }
  354. public class TheCreateMethod : IDisposable
  355. {
  356. private readonly IGitHubClient _github;
  357. private readonly RepositoryContext _context;
  358. public TheCreateMethod()
  359. {
  360. _github = Helper.GetAuthenticatedClient();
  361. _context = _github.CreateRepositoryContext("public-repo").Result;
  362. }
  363. private async Task<Commit> SetupCommitForRepository(IGitHubClient client)
  364. {
  365. var blob = new NewBlob
  366. {
  367. Content = "Hello World!",
  368. Encoding = EncodingType.Utf8
  369. };
  370. var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob);
  371. var newTree = new NewTree();
  372. newTree.Tree.Add(new NewTreeItem
  373. {
  374. Type = TreeType.Blob,
  375. Mode = FileMode.File,
  376. Path = "README.md",
  377. Sha = blobResult.Sha
  378. });
  379. var treeResult = await client.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);
  380. var newCommit = new NewCommit("test-commit", treeResult.Sha);
  381. return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
  382. }
  383. [IntegrationTest]
  384. public async Task CanCreateComment()
  385. {
  386. var commit = await SetupCommitForRepository(_github);
  387. var comment = new NewCommitComment("test");
  388. var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
  389. commit.Sha, comment);
  390. Assert.NotNull(result);
  391. var retrieved = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id);
  392. Assert.NotNull(retrieved);
  393. }
  394. [IntegrationTest]
  395. public async Task CanCreateCommentWithRepositoryId()
  396. {
  397. var commit = await SetupCommitForRepository(_github);
  398. var comment = new NewCommitComment("test");
  399. var result = await _github.Repository.Comment.Create(_context.Repository.Id,
  400. commit.Sha, comment);
  401. Assert.NotNull(result);
  402. var retrieved = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id);
  403. Assert.NotNull(retrieved);
  404. }
  405. [IntegrationTest]
  406. public async Task CanGetReactionPayload()
  407. {
  408. var commit = await SetupCommitForRepository(_github);
  409. var comment = new NewCommitComment("test");
  410. var result = await _github.Repository.Comment.Create(_context.Repository.Id,
  411. commit.Sha, comment);
  412. foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
  413. {
  414. var newReaction = new NewReaction(reactionType);
  415. var reaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction);
  416. Assert.IsType<Reaction>(reaction);
  417. Assert.Equal(reactionType, reaction.Content);
  418. Assert.Equal(result.User.Id, reaction.User.Id);
  419. }
  420. var retrieved = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id);
  421. Assert.True(retrieved.Id > 0);
  422. Assert.Equal(6, retrieved.Reactions.TotalCount);
  423. Assert.Equal(1, retrieved.Reactions.Plus1);
  424. Assert.Equal(1, retrieved.Reactions.Hooray);
  425. Assert.Equal(1, retrieved.Reactions.Heart);
  426. Assert.Equal(1, retrieved.Reactions.Laugh);
  427. Assert.Equal(1, retrieved.Reactions.Confused);
  428. Assert.Equal(1, retrieved.Reactions.Minus1);
  429. }
  430. public void Dispose()
  431. {
  432. _context.Dispose();
  433. }
  434. }
  435. public class TheUpdateMethod : IDisposable
  436. {
  437. private readonly IGitHubClient _github;
  438. private readonly RepositoryContext _context;
  439. public TheUpdateMethod()
  440. {
  441. _github = Helper.GetAuthenticatedClient();
  442. _context = _github.CreateRepositoryContext("public-repo").Result;
  443. }
  444. private async Task<Commit> SetupCommitForRepository(IGitHubClient client)
  445. {
  446. var blob = new NewBlob
  447. {
  448. Content = "Hello World!",
  449. Encoding = EncodingType.Utf8
  450. };
  451. var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob);
  452. var newTree = new NewTree();
  453. newTree.Tree.Add(new NewTreeItem
  454. {
  455. Type = TreeType.Blob,
  456. Mode = FileMode.File,
  457. Path = "README.md",
  458. Sha = blobResult.Sha
  459. });
  460. var treeResult = await client.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);
  461. var newCommit = new NewCommit("test-commit", treeResult.Sha);
  462. return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
  463. }
  464. [IntegrationTest]
  465. public async Task CanUpdateComment()
  466. {
  467. var commit = await SetupCommitForRepository(_github);
  468. var comment = new NewCommitComment("test");
  469. var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
  470. commit.Sha, comment);
  471. Assert.NotNull(result);
  472. var retrievedBefore = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id);
  473. Assert.NotNull(retrievedBefore);
  474. await _github.Repository.Comment.Update(_context.RepositoryOwner, _context.RepositoryName, result.Id, "new comment");
  475. var retrievedAfter = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id);
  476. Assert.Equal("new comment", retrievedAfter.Body);
  477. }
  478. [IntegrationTest]
  479. public async Task CanUpdateCommentWithRepositoryId()
  480. {
  481. var commit = await SetupCommitForRepository(_github);
  482. var comment = new NewCommitComment("test");
  483. var result = await _github.Repository.Comment.Create(_context.Repository.Id,
  484. commit.Sha, comment);
  485. Assert.NotNull(result);
  486. var retrievedBefore = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id);
  487. Assert.NotNull(retrievedBefore);
  488. await _github.Repository.Comment.Update(_context.Repository.Id, result.Id, "new comment");
  489. var retrievedAfter = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id);
  490. Assert.Equal("new comment", retrievedAfter.Body);
  491. }
  492. public void Dispose()
  493. {
  494. _context.Dispose();
  495. }
  496. }
  497. public class TheDeleteMethod : IDisposable
  498. {
  499. private readonly IGitHubClient _github;
  500. private readonly RepositoryContext _context;
  501. public TheDeleteMethod()
  502. {
  503. _github = Helper.GetAuthenticatedClient();
  504. _context = _github.CreateRepositoryContext("public-repo").Result;
  505. }
  506. private async Task<Commit> SetupCommitForRepository(IGitHubClient client)
  507. {
  508. var blob = new NewBlob
  509. {
  510. Content = "Hello World!",
  511. Encoding = EncodingType.Utf8
  512. };
  513. var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob);
  514. var newTree = new NewTree();
  515. newTree.Tree.Add(new NewTreeItem
  516. {
  517. Type = TreeType.Blob,
  518. Mode = FileMode.File,
  519. Path = "README.md",
  520. Sha = blobResult.Sha
  521. });
  522. var treeResult = await client.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);
  523. var newCommit = new NewCommit("test-commit", treeResult.Sha);
  524. return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
  525. }
  526. [IntegrationTest]
  527. public async Task CanDeleteComment()
  528. {
  529. var commit = await SetupCommitForRepository(_github);
  530. var comment = new NewCommitComment("test");
  531. var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
  532. commit.Sha, comment);
  533. Assert.NotNull(result);
  534. var retrievedBefore = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id);
  535. Assert.NotNull(retrievedBefore);
  536. await _github.Repository.Comment.Delete(_context.RepositoryOwner, _context.RepositoryName, result.Id);
  537. var notFound = false;
  538. try
  539. {
  540. await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id);
  541. }
  542. catch (NotFoundException)
  543. {
  544. notFound = true;
  545. }
  546. Assert.True(notFound);
  547. }
  548. [IntegrationTest]
  549. public async Task CanDeleteCommentWithRepositoryId()
  550. {
  551. var commit = await SetupCommitForRepository(_github);
  552. var comment = new NewCommitComment("test");
  553. var result = await _github.Repository.Comment.Create(_context.Repository.Id,
  554. commit.Sha, comment);
  555. Assert.NotNull(result);
  556. var retrievedBefore = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id);
  557. Assert.NotNull(retrievedBefore);
  558. await _github.Repository.Comment.Delete(_context.Repository.Id, result.Id);
  559. var notFound = false;
  560. try
  561. {
  562. await _github.Repository.Comment.Get(_context.Repository.Id, result.Id);
  563. }
  564. catch (NotFoundException)
  565. {
  566. notFound = true;
  567. }
  568. Assert.True(notFound);
  569. }
  570. public void Dispose()
  571. {
  572. _context.Dispose();
  573. }
  574. }
  575. async static Task<Commit> HelperCreateCommit(string owner, string repo)
  576. {
  577. var client = Helper.GetAuthenticatedClient();
  578. var blob = new NewBlob
  579. {
  580. Content = "Hello World!",
  581. Encoding = EncodingType.Utf8
  582. };
  583. var blobResult = await client.Git.Blob.Create(owner, repo, blob);
  584. var newTree = new NewTree();
  585. newTree.Tree.Add(new NewTreeItem
  586. {
  587. Type = TreeType.Blob,
  588. Mode = FileMode.File,
  589. Path = "README.md",
  590. Sha = blobResult.Sha
  591. });
  592. var treeResult = await client.Git.Tree.Create(owner, repo, newTree);
  593. var newCommit = new NewCommit("test-commit", treeResult.Sha);
  594. return await client.Git.Commit.Create(owner, repo, newCommit);
  595. }
  596. async static Task<int> HelperCreateCommitCommentWithReactions(string owner, string repo, string sha)
  597. {
  598. var github = Helper.GetAuthenticatedClient();
  599. var commitComment = await github.Repository.Comment.Create(owner, repo, sha, new NewCommitComment("A test comment"));
  600. Assert.NotNull(commitComment);
  601. foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
  602. {
  603. var newReaction = new NewReaction(reactionType);
  604. var reaction = await github.Reaction.CommitComment.Create(owner, repo, commitComment.Id, newReaction);
  605. Assert.IsType<Reaction>(reaction);
  606. Assert.Equal(reactionType, reaction.Content);
  607. Assert.Equal(commitComment.User.Id, reaction.User.Id);
  608. }
  609. return commitComment.Id;
  610. }
  611. }