PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs

https://gitlab.com/WoomyNightClub/GitHub-API-.NET
C# | 641 lines | 506 code | 135 blank | 0 comment | 70 complexity | bddf60bbb66acafb46ba43f0327f7f8a MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using NSubstitute;
  5. using Octokit;
  6. using Octokit.Tests;
  7. using Xunit;
  8. public class PullRequestReviewCommentsClientTests
  9. {
  10. public class TheCtor
  11. {
  12. [Fact]
  13. public void EnsuresNonNullArguments()
  14. {
  15. Assert.Throws<ArgumentNullException>(() => new PullRequestReviewCommentsClient(null));
  16. }
  17. [Fact]
  18. public void PullRequestReviewCommentCreateEnsuresArgumentsValue()
  19. {
  20. string body = "body";
  21. string commitId = "sha";
  22. string path = "path";
  23. int position = 1;
  24. var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);
  25. Assert.Equal(body, comment.Body);
  26. Assert.Equal(commitId, comment.CommitId);
  27. Assert.Equal(path, comment.Path);
  28. Assert.Equal(position, comment.Position);
  29. }
  30. [Fact]
  31. public void PullRequestReviewCommentCreateEnsuresNonNullArguments()
  32. {
  33. string body = "body";
  34. string commitId = "sha";
  35. string path = "path";
  36. int position = 1;
  37. Assert.Throws<ArgumentNullException>(() => new PullRequestReviewCommentCreate(null, commitId, path, position));
  38. Assert.Throws<ArgumentException>(() => new PullRequestReviewCommentCreate("", commitId, path, position));
  39. Assert.Throws<ArgumentNullException>(() => new PullRequestReviewCommentCreate(body, null, path, position));
  40. Assert.Throws<ArgumentException>(() => new PullRequestReviewCommentCreate(body, "", path, position));
  41. Assert.Throws<ArgumentNullException>(() => new PullRequestReviewCommentCreate(body, commitId, null, position));
  42. Assert.Throws<ArgumentException>(() => new PullRequestReviewCommentCreate(body, commitId, "", position));
  43. }
  44. [Fact]
  45. public void PullRequestReviewCommentEditEnsuresArgumentsValue()
  46. {
  47. string body = "body";
  48. var comment = new PullRequestReviewCommentEdit(body);
  49. Assert.Equal(body, comment.Body);
  50. }
  51. [Fact]
  52. public void PullRequestReviewCommentEditEnsuresNonNullArguments()
  53. {
  54. Assert.Throws<ArgumentNullException>(() => new PullRequestReviewCommentEdit(null));
  55. Assert.Throws<ArgumentException>(() => new PullRequestReviewCommentEdit(""));
  56. }
  57. [Fact]
  58. public void PullRequestReviewCommentReplyCreateEnsuresArgumentsValue()
  59. {
  60. string body = "body";
  61. int inReplyTo = 1;
  62. var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo);
  63. Assert.Equal(body, comment.Body);
  64. Assert.Equal(inReplyTo, comment.InReplyTo);
  65. }
  66. [Fact]
  67. public void PullRequestReviewCommentReplyCreateEnsuresNonNullArguments()
  68. {
  69. int inReplyTo = 1;
  70. Assert.Throws<ArgumentNullException>(() => new PullRequestReviewCommentReplyCreate(null, inReplyTo));
  71. Assert.Throws<ArgumentException>(() => new PullRequestReviewCommentReplyCreate("", inReplyTo));
  72. }
  73. }
  74. public class TheGetForPullRequestMethod
  75. {
  76. [Fact]
  77. public async Task RequestsCorrectUrl()
  78. {
  79. var connection = Substitute.For<IApiConnection>();
  80. var client = new PullRequestReviewCommentsClient(connection);
  81. await client.GetAll("owner", "name", 7);
  82. connection.Received().GetAll<PullRequestReviewComment>(
  83. Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/7/comments"),
  84. Arg.Any<Dictionary<string, string>>(),
  85. "application/vnd.github.squirrel-girl-preview", Args.ApiOptions);
  86. }
  87. [Fact]
  88. public async Task RequestsCorrectUrlWithRepositoryId()
  89. {
  90. var connection = Substitute.For<IApiConnection>();
  91. var client = new PullRequestReviewCommentsClient(connection);
  92. await client.GetAll(1, 7);
  93. connection.Received().GetAll<PullRequestReviewComment>(
  94. Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/7/comments"), Args.ApiOptions);
  95. }
  96. [Fact]
  97. public async Task RequestsCorrectUrlWithApiOptions()
  98. {
  99. var connection = Substitute.For<IApiConnection>();
  100. var client = new PullRequestReviewCommentsClient(connection);
  101. var options = new ApiOptions
  102. {
  103. StartPage = 1,
  104. PageCount = 1,
  105. PageSize = 1
  106. };
  107. await client.GetAll("owner", "name", 7, options);
  108. connection.Received().GetAll<PullRequestReviewComment>(
  109. Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/7/comments"),
  110. Arg.Any<Dictionary<string, string>>(),
  111. "application/vnd.github.squirrel-girl-preview", options);
  112. }
  113. [Fact]
  114. public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
  115. {
  116. var connection = Substitute.For<IApiConnection>();
  117. var client = new PullRequestReviewCommentsClient(connection);
  118. var options = new ApiOptions
  119. {
  120. StartPage = 1,
  121. PageCount = 1,
  122. PageSize = 1
  123. };
  124. await client.GetAll(1, 7, options);
  125. connection.Received().GetAll<PullRequestReviewComment>(
  126. Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/7/comments"), options);
  127. }
  128. [Fact]
  129. public async Task EnsuresNotNullArguments()
  130. {
  131. var connection = Substitute.For<IApiConnection>();
  132. var client = new PullRequestReviewCommentsClient(connection);
  133. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", 1));
  134. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, 1));
  135. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", 1, ApiOptions.None));
  136. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, 1, ApiOptions.None));
  137. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", 1, null));
  138. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, 1, null));
  139. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1));
  140. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1));
  141. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1, ApiOptions.None));
  142. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1, ApiOptions.None));
  143. }
  144. }
  145. public class TheGetForRepositoryMethod
  146. {
  147. [Fact]
  148. public async Task RequestsCorrectUrl()
  149. {
  150. var connection = Substitute.For<IApiConnection>();
  151. var client = new PullRequestReviewCommentsClient(connection);
  152. var request = new PullRequestReviewCommentRequest
  153. {
  154. Direction = SortDirection.Descending,
  155. Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()),
  156. Sort = PullRequestReviewCommentSort.Updated
  157. };
  158. await client.GetAllForRepository("owner", "name", request);
  159. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/comments"),
  160. Arg.Is<Dictionary<string, string>>(d => d.Count == 3
  161. && d["direction"] == "desc"
  162. && d["since"] == "2013-11-15T11:43:01Z"
  163. && d["sort"] == "updated"),
  164. "application/vnd.github.squirrel-girl-preview",
  165. Args.ApiOptions);
  166. }
  167. [Fact]
  168. public async Task RequestsCorrectUrlWithRepositoryId()
  169. {
  170. var connection = Substitute.For<IApiConnection>();
  171. var client = new PullRequestReviewCommentsClient(connection);
  172. var request = new PullRequestReviewCommentRequest
  173. {
  174. Direction = SortDirection.Descending,
  175. Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()),
  176. Sort = PullRequestReviewCommentSort.Updated
  177. };
  178. await client.GetAllForRepository(1, request);
  179. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments"),
  180. Arg.Is<Dictionary<string, string>>(d => d.Count == 3
  181. && d["direction"] == "desc"
  182. && d["since"] == "2013-11-15T11:43:01Z"
  183. && d["sort"] == "updated"),
  184. "application/vnd.github.squirrel-girl-preview", Args.ApiOptions);
  185. }
  186. [Fact]
  187. public async Task RequestsCorrectUrlWithApiOptions()
  188. {
  189. var connection = Substitute.For<IApiConnection>();
  190. var client = new PullRequestReviewCommentsClient(connection);
  191. var request = new PullRequestReviewCommentRequest
  192. {
  193. Direction = SortDirection.Descending,
  194. Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()),
  195. Sort = PullRequestReviewCommentSort.Updated
  196. };
  197. var options = new ApiOptions
  198. {
  199. PageCount = 1,
  200. StartPage = 1,
  201. PageSize = 1
  202. };
  203. await client.GetAllForRepository("owner", "name", request, options);
  204. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/comments"),
  205. Arg.Is<Dictionary<string, string>>(d => d.Count == 3
  206. && d["direction"] == "desc"
  207. && d["since"] == "2013-11-15T11:43:01Z"
  208. && d["sort"] == "updated"),
  209. "application/vnd.github.squirrel-girl-preview",
  210. options);
  211. }
  212. [Fact]
  213. public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
  214. {
  215. var connection = Substitute.For<IApiConnection>();
  216. var client = new PullRequestReviewCommentsClient(connection);
  217. var request = new PullRequestReviewCommentRequest
  218. {
  219. Direction = SortDirection.Descending,
  220. Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()),
  221. Sort = PullRequestReviewCommentSort.Updated
  222. };
  223. var options = new ApiOptions
  224. {
  225. PageCount = 1,
  226. StartPage = 1,
  227. PageSize = 1
  228. };
  229. await client.GetAllForRepository(1, request, options);
  230. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments"),
  231. Arg.Is<Dictionary<string, string>>(d => d.Count == 3
  232. && d["direction"] == "desc"
  233. && d["since"] == "2013-11-15T11:43:01Z"
  234. && d["sort"] == "updated"),
  235. "application/vnd.github.squirrel-girl-preview", options);
  236. }
  237. [Fact]
  238. public async Task RequestsCorrectUrlWithoutSelectedSortingArguments()
  239. {
  240. var connection = Substitute.For<IApiConnection>();
  241. var client = new PullRequestReviewCommentsClient(connection);
  242. await client.GetAllForRepository("owner", "name");
  243. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/comments"),
  244. Arg.Is<Dictionary<string, string>>(d => d.Count == 2
  245. && d["direction"] == "asc"
  246. && d["sort"] == "created"),
  247. "application/vnd.github.squirrel-girl-preview",
  248. Args.ApiOptions);
  249. }
  250. [Fact]
  251. public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithRepositoryId()
  252. {
  253. var connection = Substitute.For<IApiConnection>();
  254. var client = new PullRequestReviewCommentsClient(connection);
  255. await client.GetAllForRepository(1);
  256. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments"),
  257. Arg.Is<Dictionary<string, string>>(d => d.Count == 2
  258. && d["direction"] == "asc"
  259. && d["sort"] == "created"),
  260. "application/vnd.github.squirrel-girl-preview", Args.ApiOptions);
  261. }
  262. [Fact]
  263. public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOptions()
  264. {
  265. var connection = Substitute.For<IApiConnection>();
  266. var client = new PullRequestReviewCommentsClient(connection);
  267. var options = new ApiOptions
  268. {
  269. PageCount = 1,
  270. StartPage = 1,
  271. PageSize = 1
  272. };
  273. await client.GetAllForRepository("owner", "name", options);
  274. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/comments"),
  275. Arg.Is<Dictionary<string, string>>(d => d.Count == 2
  276. && d["direction"] == "asc"
  277. && d["sort"] == "created"),
  278. "application/vnd.github.squirrel-girl-preview",
  279. options);
  280. }
  281. [Fact]
  282. public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOptionsWithRepositoryId()
  283. {
  284. var connection = Substitute.For<IApiConnection>();
  285. var client = new PullRequestReviewCommentsClient(connection);
  286. var options = new ApiOptions
  287. {
  288. PageCount = 1,
  289. StartPage = 1,
  290. PageSize = 1
  291. };
  292. await client.GetAllForRepository(1, options);
  293. connection.Received().GetAll<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments"),
  294. Arg.Is<Dictionary<string, string>>(d => d.Count == 2
  295. && d["direction"] == "asc"
  296. && d["sort"] == "created"),
  297. "application/vnd.github.squirrel-girl-preview", options);
  298. }
  299. [Fact]
  300. public async Task EnsuresNonNullArguments()
  301. {
  302. var client = new PullRequestReviewCommentsClient(Substitute.For<IApiConnection>());
  303. var request = new PullRequestReviewCommentRequest();
  304. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request));
  305. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request));
  306. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (PullRequestReviewCommentRequest)null));
  307. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));
  308. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));
  309. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null));
  310. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request, ApiOptions.None));
  311. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request, ApiOptions.None));
  312. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None));
  313. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", request, null));
  314. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, (ApiOptions)null));
  315. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, (PullRequestReviewCommentRequest)null));
  316. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, null, ApiOptions.None));
  317. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, request, null));
  318. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", ApiOptions.None));
  319. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", ApiOptions.None));
  320. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request));
  321. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request));
  322. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request, ApiOptions.None));
  323. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request, ApiOptions.None));
  324. }
  325. [Fact]
  326. public async Task EnsuresDefaultValues()
  327. {
  328. var request = new PullRequestReviewCommentRequest();
  329. Assert.Equal(SortDirection.Ascending, request.Direction);
  330. Assert.Null(request.Since);
  331. Assert.Equal(PullRequestReviewCommentSort.Created, request.Sort);
  332. }
  333. }
  334. public class TheGetCommentMethod
  335. {
  336. [Fact]
  337. public void RequestsCorrectUrl()
  338. {
  339. var connection = Substitute.For<IApiConnection>();
  340. var client = new PullRequestReviewCommentsClient(connection);
  341. client.GetComment("owner", "name", 53);
  342. connection.Received().Get<PullRequestReviewComment>(
  343. Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/comments/53"),
  344. Arg.Any<Dictionary<string, string>>(),
  345. "application/vnd.github.squirrel-girl-preview");
  346. }
  347. [Fact]
  348. public void RequestsCorrectUrlWithRepositoryId()
  349. {
  350. var connection = Substitute.For<IApiConnection>();
  351. var client = new PullRequestReviewCommentsClient(connection);
  352. client.GetComment(1, 53);
  353. connection.Received().Get<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments/53"));
  354. }
  355. [Fact]
  356. public async Task EnsuresNonNullArguments()
  357. {
  358. var client = new PullRequestReviewCommentsClient(Substitute.For<IApiConnection>());
  359. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetComment(null, "name", 1));
  360. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetComment("owner", null, 1));
  361. await Assert.ThrowsAsync<ArgumentException>(() => client.GetComment("", "name", 1));
  362. await Assert.ThrowsAsync<ArgumentException>(() => client.GetComment("owner", "", 1));
  363. }
  364. }
  365. public class TheCreateMethod
  366. {
  367. [Fact]
  368. public void PostsToCorrectUrl()
  369. {
  370. var connection = Substitute.For<IApiConnection>();
  371. var client = new PullRequestReviewCommentsClient(connection);
  372. var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7);
  373. client.Create("fakeOwner", "fakeRepoName", 13, comment);
  374. connection.Connection.Received().Post<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"),
  375. comment, null, null);
  376. }
  377. [Fact]
  378. public void PostsToCorrectUrlWithRepositoryId()
  379. {
  380. var connection = Substitute.For<IApiConnection>();
  381. var client = new PullRequestReviewCommentsClient(connection);
  382. var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7);
  383. client.Create(1, 13, comment);
  384. connection.Connection.Received().Post<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/13/comments"),
  385. comment, null, null);
  386. }
  387. [Fact]
  388. public async Task EnsuresNonNullArguments()
  389. {
  390. var connection = Substitute.For<IApiConnection>();
  391. var client = new PullRequestReviewCommentsClient(connection);
  392. string body = "Comment content";
  393. string commitId = "qe3dsdsf6";
  394. string path = "file.css";
  395. int position = 7;
  396. var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);
  397. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "fakeRepoName", 1, comment));
  398. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("fakeOwner", null, 1, comment));
  399. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("fakeOwner", "fakeRepoName", 1, null));
  400. await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "fakeRepoName", 1, comment));
  401. await Assert.ThrowsAsync<ArgumentException>(() => client.Create("fakeOwner", "", 1, comment));
  402. }
  403. }
  404. public class TheCreateReplyMethod
  405. {
  406. [Fact]
  407. public void PostsToCorrectUrl()
  408. {
  409. var connection = Substitute.For<IApiConnection>();
  410. var client = new PullRequestReviewCommentsClient(connection);
  411. var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5);
  412. client.CreateReply("owner", "name", 13, comment);
  413. connection.Connection.Received().Post<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/13/comments"),
  414. comment, null, null);
  415. }
  416. [Fact]
  417. public void PostsToCorrectUrlWithRepositoryId()
  418. {
  419. var connection = Substitute.For<IApiConnection>();
  420. var client = new PullRequestReviewCommentsClient(connection);
  421. var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5);
  422. client.CreateReply(1, 13, comment);
  423. connection.Connection.Received().Post<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/13/comments"),
  424. comment, null, null);
  425. }
  426. [Fact]
  427. public async Task EnsuresNonNullArguments()
  428. {
  429. var connection = Substitute.For<IApiConnection>();
  430. var client = new PullRequestReviewCommentsClient(connection);
  431. string body = "Comment content";
  432. int inReplyTo = 7;
  433. var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo);
  434. await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateReply(null, "name", 1, comment));
  435. await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateReply("owner", null, 1, comment));
  436. await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateReply("owner", "name", 1, null));
  437. await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateReply(1, 1, null));
  438. await Assert.ThrowsAsync<ArgumentException>(() => client.CreateReply("", "name", 1, comment));
  439. await Assert.ThrowsAsync<ArgumentException>(() => client.CreateReply("owner", "", 1, comment));
  440. }
  441. }
  442. public class TheEditMethod
  443. {
  444. [Fact]
  445. public async Task PostsToCorrectUrl()
  446. {
  447. var connection = Substitute.For<IApiConnection>();
  448. var client = new PullRequestReviewCommentsClient(connection);
  449. var comment = new PullRequestReviewCommentEdit("New comment content");
  450. await client.Edit("owner", "name", 13, comment);
  451. connection.Received().Patch<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/comments/13"), comment);
  452. }
  453. [Fact]
  454. public async Task PostsToCorrectUrlWithRepositoryId()
  455. {
  456. var connection = Substitute.For<IApiConnection>();
  457. var client = new PullRequestReviewCommentsClient(connection);
  458. var comment = new PullRequestReviewCommentEdit("New comment content");
  459. await client.Edit(1, 13, comment);
  460. connection.Received().Patch<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments/13"), comment);
  461. }
  462. [Fact]
  463. public async Task EnsuresNonNullArguments()
  464. {
  465. var connection = Substitute.For<IApiConnection>();
  466. var client = new PullRequestReviewCommentsClient(connection);
  467. var body = "New comment content";
  468. var comment = new PullRequestReviewCommentEdit(body);
  469. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit(null, "name", 1, comment));
  470. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit("owner", null, 1, comment));
  471. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit("owner", "name", 1, null));
  472. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit(1, 1, null));
  473. await Assert.ThrowsAsync<ArgumentException>(() => client.Edit("", "name", 1, comment));
  474. await Assert.ThrowsAsync<ArgumentException>(() => client.Edit("owner", "", 1, comment));
  475. }
  476. }
  477. public class TheDeleteMethod
  478. {
  479. [Fact]
  480. public async Task PostsToCorrectUrl()
  481. {
  482. var connection = Substitute.For<IApiConnection>();
  483. var client = new PullRequestReviewCommentsClient(connection);
  484. await client.Delete("owner", "name", 13);
  485. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/pulls/comments/13"));
  486. }
  487. [Fact]
  488. public async Task PostsToCorrectUrlWithRepositoryId()
  489. {
  490. var connection = Substitute.For<IApiConnection>();
  491. var client = new PullRequestReviewCommentsClient(connection);
  492. await client.Delete(1, 13);
  493. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments/13"));
  494. }
  495. [Fact]
  496. public async Task EnsuresNonNullArguments()
  497. {
  498. var connection = Substitute.For<IApiConnection>();
  499. var client = new PullRequestReviewCommentsClient(connection);
  500. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete(null, "name", 1));
  501. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", null, 1));
  502. await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("", "name", 1));
  503. await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", "", 1));
  504. }
  505. }
  506. }