PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Octokit.Tests/Clients/IssuesLabelsClientTests.cs

https://gitlab.com/WoomyNightClub/GitHub-API-.NET
C# | 606 lines | 462 code | 144 blank | 0 comment | 28 complexity | 34547813cc94f238d3ff79ec66d8accd MD5 | raw file
  1. using System;
  2. using System.Threading.Tasks;
  3. using NSubstitute;
  4. using Xunit;
  5. using System.Collections.Generic;
  6. namespace Octokit.Tests.Clients
  7. {
  8. public class IssuesLabelsClientTests
  9. {
  10. public class TheCtor
  11. {
  12. [Fact]
  13. public void EnsuresNonNullArguments()
  14. {
  15. Assert.Throws<ArgumentNullException>(
  16. () => new IssuesLabelsClient(null));
  17. }
  18. }
  19. public class TheGetForIssueMethod
  20. {
  21. [Fact]
  22. public async Task RequestsCorrectUrl()
  23. {
  24. var connection = Substitute.For<IApiConnection>();
  25. var client = new IssuesLabelsClient(connection);
  26. await client.GetAllForIssue("fake", "repo", 42);
  27. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Args.ApiOptions);
  28. }
  29. [Fact]
  30. public async Task RequestsCorrectUrlWithRepositoryId()
  31. {
  32. var connection = Substitute.For<IApiConnection>();
  33. var client = new IssuesLabelsClient(connection);
  34. await client.GetAllForIssue(1, 42);
  35. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/labels"), Args.ApiOptions);
  36. }
  37. [Fact]
  38. public async Task RequestsCorrectUrlWithApiOptions()
  39. {
  40. var connection = Substitute.For<IApiConnection>();
  41. var client = new IssuesLabelsClient(connection);
  42. var options = new ApiOptions
  43. {
  44. PageCount = 1,
  45. StartPage = 1,
  46. PageSize = 1
  47. };
  48. await client.GetAllForIssue("fake", "repo", 42, options);
  49. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"), options);
  50. }
  51. [Fact]
  52. public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
  53. {
  54. var connection = Substitute.For<IApiConnection>();
  55. var client = new IssuesLabelsClient(connection);
  56. var options = new ApiOptions
  57. {
  58. PageCount = 1,
  59. StartPage = 1,
  60. PageSize = 1
  61. };
  62. await client.GetAllForIssue(1, 42, options);
  63. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/labels"), options);
  64. }
  65. [Fact]
  66. public async Task EnsuresNonNullArguments()
  67. {
  68. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  69. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1));
  70. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1));
  71. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None));
  72. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None));
  73. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue("owner", "name", 1, null));
  74. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForIssue(1, 1, null));
  75. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForIssue("", "name", 1));
  76. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForIssue("owner", "", 1));
  77. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForIssue("", "name", 1, ApiOptions.None));
  78. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None));
  79. }
  80. }
  81. public class TheGetForRepositoryMethod
  82. {
  83. [Fact]
  84. public async Task RequestsCorrectUrl()
  85. {
  86. var connection = Substitute.For<IApiConnection>();
  87. var client = new IssuesLabelsClient(connection);
  88. await client.GetAllForRepository("fake", "repo");
  89. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels"), Args.ApiOptions);
  90. }
  91. [Fact]
  92. public async Task RequestsCorrectUrlWithRepositoryId()
  93. {
  94. var connection = Substitute.For<IApiConnection>();
  95. var client = new IssuesLabelsClient(connection);
  96. await client.GetAllForRepository(1);
  97. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels"), Args.ApiOptions);
  98. }
  99. [Fact]
  100. public async Task RequestsCorrectUrlWithApiOptions()
  101. {
  102. var connection = Substitute.For<IApiConnection>();
  103. var client = new IssuesLabelsClient(connection);
  104. var options = new ApiOptions
  105. {
  106. PageCount = 1,
  107. StartPage = 1,
  108. PageSize = 1
  109. };
  110. await client.GetAllForRepository("fake", "repo", options);
  111. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels"), options);
  112. }
  113. [Fact]
  114. public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
  115. {
  116. var connection = Substitute.For<IApiConnection>();
  117. var client = new IssuesLabelsClient(connection);
  118. var options = new ApiOptions
  119. {
  120. PageCount = 1,
  121. StartPage = 1,
  122. PageSize = 1
  123. };
  124. await client.GetAllForRepository(1, options);
  125. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels"), options);
  126. }
  127. [Fact]
  128. public async Task EnsuresNonNullArguments()
  129. {
  130. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  131. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
  132. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
  133. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));
  134. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));
  135. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));
  136. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, null));
  137. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name"));
  138. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", ""));
  139. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", ApiOptions.None));
  140. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", ApiOptions.None));
  141. }
  142. }
  143. public class TheGetForMilestoneMethod
  144. {
  145. [Fact]
  146. public async Task RequestsCorrectUrl()
  147. {
  148. var connection = Substitute.For<IApiConnection>();
  149. var client = new IssuesLabelsClient(connection);
  150. await client.GetAllForMilestone("fake", "repo", 42);
  151. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones/42/labels"), Args.ApiOptions);
  152. }
  153. [Fact]
  154. public async Task RequestsCorrectUrlWithRepositoryId()
  155. {
  156. var connection = Substitute.For<IApiConnection>();
  157. var client = new IssuesLabelsClient(connection);
  158. await client.GetAllForMilestone(1, 42);
  159. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/milestones/42/labels"), Args.ApiOptions);
  160. }
  161. [Fact]
  162. public async Task RequestsCorrectUrlWithApiOptions()
  163. {
  164. var connection = Substitute.For<IApiConnection>();
  165. var client = new IssuesLabelsClient(connection);
  166. var options = new ApiOptions
  167. {
  168. PageCount = 1,
  169. StartPage = 1,
  170. PageSize = 1
  171. };
  172. await client.GetAllForMilestone("fake", "repo", 42, options);
  173. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones/42/labels"), options);
  174. }
  175. [Fact]
  176. public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
  177. {
  178. var connection = Substitute.For<IApiConnection>();
  179. var client = new IssuesLabelsClient(connection);
  180. var options = new ApiOptions
  181. {
  182. PageCount = 1,
  183. StartPage = 1,
  184. PageSize = 1
  185. };
  186. await client.GetAllForMilestone(1, 42, options);
  187. connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/milestones/42/labels"), options);
  188. }
  189. [Fact]
  190. public async Task EnsuresNonNullArguments()
  191. {
  192. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  193. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForMilestone(null, "name", 42));
  194. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForMilestone("owner", null, 42));
  195. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForMilestone(null, "name", 42, ApiOptions.None));
  196. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForMilestone("owner", null, 42, ApiOptions.None));
  197. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForMilestone("owner", "name", 42, null));
  198. await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForMilestone(1, 42, null));
  199. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForMilestone("", "name", 42));
  200. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForMilestone("owner", "", 42));
  201. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForMilestone("", "name", 42, ApiOptions.None));
  202. await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForMilestone("owner", "", 42, ApiOptions.None));
  203. }
  204. }
  205. public class TheGetMethod
  206. {
  207. [Fact]
  208. public async Task RequestsCorrectUrl()
  209. {
  210. var connection = Substitute.For<IApiConnection>();
  211. var client = new IssuesLabelsClient(connection);
  212. await client.Get("fake", "repo", "label");
  213. connection.Received().Get<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels/label"));
  214. }
  215. [Fact]
  216. public async Task RequestsCorrectUrlWithRepositoryId()
  217. {
  218. var connection = Substitute.For<IApiConnection>();
  219. var client = new IssuesLabelsClient(connection);
  220. await client.Get(1, "label");
  221. connection.Received().Get<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels/label"));
  222. }
  223. [Fact]
  224. public async Task EnsuresNonNullArguments()
  225. {
  226. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  227. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "label"));
  228. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "label"));
  229. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null));
  230. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(1, null));
  231. await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "label"));
  232. await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "label"));
  233. await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", ""));
  234. await Assert.ThrowsAsync<ArgumentException>(() => client.Get(1, ""));
  235. }
  236. }
  237. public class TheAddToIssueMethod
  238. {
  239. readonly string[] labels = { "foo", "bar" };
  240. [Fact]
  241. public void PostsToCorrectUrl()
  242. {
  243. var connection = Substitute.For<IApiConnection>();
  244. var client = new IssuesLabelsClient(connection);
  245. client.AddToIssue("fake", "repo", 42, labels);
  246. connection.Received().Post<IReadOnlyList<Label>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Arg.Any<string[]>());
  247. }
  248. [Fact]
  249. public void PostsToCorrectUrlWithRepositoryId()
  250. {
  251. var connection = Substitute.For<IApiConnection>();
  252. var client = new IssuesLabelsClient(connection);
  253. client.AddToIssue(1, 42, labels);
  254. connection.Received().Post<IReadOnlyList<Label>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/labels"), Arg.Any<string[]>());
  255. }
  256. [Fact]
  257. public async Task EnsuresNonNullArguments()
  258. {
  259. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  260. await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddToIssue(null, "name", 42, labels));
  261. await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddToIssue("owner", null, 42, labels));
  262. await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddToIssue("owner", "name", 42, null));
  263. await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddToIssue(1, 42, null));
  264. await Assert.ThrowsAsync<ArgumentException>(() => client.AddToIssue("", "name", 42, labels));
  265. await Assert.ThrowsAsync<ArgumentException>(() => client.AddToIssue("owner", "", 42, labels));
  266. }
  267. }
  268. public class TheRemoveFromIssueMethod
  269. {
  270. [Fact]
  271. public void DeleteCorrectUrl()
  272. {
  273. var connection = Substitute.For<IApiConnection>();
  274. var client = new IssuesLabelsClient(connection);
  275. client.RemoveFromIssue("fake", "repo", 42, "label");
  276. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels/label"));
  277. }
  278. [Fact]
  279. public void DeleteCorrectUrlWithRepositoryId()
  280. {
  281. var connection = Substitute.For<IApiConnection>();
  282. var client = new IssuesLabelsClient(connection);
  283. client.RemoveFromIssue(1, 42, "label");
  284. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/labels/label"));
  285. }
  286. [Fact]
  287. public async Task EnsuresNonNullArguments()
  288. {
  289. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  290. await Assert.ThrowsAsync<ArgumentNullException>(() => client.RemoveFromIssue(null, "name", 42, "label"));
  291. await Assert.ThrowsAsync<ArgumentNullException>(() => client.RemoveFromIssue("owner", null, 42, "label"));
  292. await Assert.ThrowsAsync<ArgumentNullException>(() => client.RemoveFromIssue("owner", "name", 42, null));
  293. await Assert.ThrowsAsync<ArgumentNullException>(() => client.RemoveFromIssue(1, 42, null));
  294. await Assert.ThrowsAsync<ArgumentException>(() => client.RemoveFromIssue("", "name", 42, "label"));
  295. await Assert.ThrowsAsync<ArgumentException>(() => client.RemoveFromIssue("owner", "", 42, "label"));
  296. await Assert.ThrowsAsync<ArgumentException>(() => client.RemoveFromIssue("owner", "name", 42, ""));
  297. await Assert.ThrowsAsync<ArgumentException>(() => client.RemoveFromIssue(1, 42, ""));
  298. }
  299. }
  300. public class TheReplaceForIssueMethod
  301. {
  302. readonly string[] labels = { "foo", "bar" };
  303. [Fact]
  304. public void PutsToCorrectUrl()
  305. {
  306. var connection = Substitute.For<IApiConnection>();
  307. var client = new IssuesLabelsClient(connection);
  308. client.ReplaceAllForIssue("fake", "repo", 42, labels);
  309. connection.Received().Put<IReadOnlyList<Label>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Arg.Any<string[]>());
  310. }
  311. [Fact]
  312. public void PutsToCorrectUrlWithRepositoryId()
  313. {
  314. var connection = Substitute.For<IApiConnection>();
  315. var client = new IssuesLabelsClient(connection);
  316. client.ReplaceAllForIssue(1, 42, labels);
  317. connection.Received().Put<IReadOnlyList<Label>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/labels"), Arg.Any<string[]>());
  318. }
  319. [Fact]
  320. public async Task EnsuresNonNullArguments()
  321. {
  322. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  323. await Assert.ThrowsAsync<ArgumentNullException>(() => client.ReplaceAllForIssue(null, "name", 42, labels));
  324. await Assert.ThrowsAsync<ArgumentNullException>(() => client.ReplaceAllForIssue("owner", null, 42, labels));
  325. await Assert.ThrowsAsync<ArgumentNullException>(() => client.ReplaceAllForIssue("owner", "name", 42, null));
  326. await Assert.ThrowsAsync<ArgumentNullException>(() => client.ReplaceAllForIssue(1, 42, null));
  327. await Assert.ThrowsAsync<ArgumentException>(() => client.ReplaceAllForIssue("", "name", 42, labels));
  328. await Assert.ThrowsAsync<ArgumentException>(() => client.ReplaceAllForIssue("owner", "", 42, labels));
  329. }
  330. }
  331. public class TheRemoveAllFromIssueMethod
  332. {
  333. [Fact]
  334. public void DeletesCorrectUrl()
  335. {
  336. var connection = Substitute.For<IApiConnection>();
  337. var client = new IssuesLabelsClient(connection);
  338. client.RemoveAllFromIssue("fake", "repo", 42);
  339. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"));
  340. }
  341. [Fact]
  342. public void DeletesCorrectUrlWithRepositoryId()
  343. {
  344. var connection = Substitute.For<IApiConnection>();
  345. var client = new IssuesLabelsClient(connection);
  346. client.RemoveAllFromIssue(1, 42);
  347. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/labels"));
  348. }
  349. [Fact]
  350. public async Task EnsuresNonNullArguments()
  351. {
  352. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  353. await Assert.ThrowsAsync<ArgumentNullException>(() => client.RemoveAllFromIssue(null, "name", 42));
  354. await Assert.ThrowsAsync<ArgumentNullException>(() => client.RemoveAllFromIssue("owner", null, 42));
  355. await Assert.ThrowsAsync<ArgumentException>(() => client.RemoveAllFromIssue("", "name", 42));
  356. await Assert.ThrowsAsync<ArgumentException>(() => client.RemoveAllFromIssue("owner", "", 42));
  357. }
  358. }
  359. public class TheDeleteMethod
  360. {
  361. [Fact]
  362. public void DeletesCorrectUrl()
  363. {
  364. var connection = Substitute.For<IApiConnection>();
  365. var client = new IssuesLabelsClient(connection);
  366. client.Delete("fake", "repo", "labelName");
  367. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels/labelName"));
  368. }
  369. [Fact]
  370. public void DeletesCorrectUrlWithRepositoryId()
  371. {
  372. var connection = Substitute.For<IApiConnection>();
  373. var client = new IssuesLabelsClient(connection);
  374. client.Delete(1, "labelName");
  375. connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels/labelName"));
  376. }
  377. [Fact]
  378. public async Task EnsuresNonNullArguments()
  379. {
  380. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  381. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete(null, "name", "labelName"));
  382. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", null, "labelName"));
  383. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", "name", null));
  384. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete(1, null));
  385. await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("", "name", "labelName"));
  386. await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", "", "labelName"));
  387. await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", "name", ""));
  388. await Assert.ThrowsAsync<ArgumentException>(() => client.Delete(1, ""));
  389. }
  390. }
  391. public class TheCreateMethod
  392. {
  393. [Fact]
  394. public void CreatesCorrectUrl()
  395. {
  396. var connection = Substitute.For<IApiConnection>();
  397. var client = new IssuesLabelsClient(connection);
  398. var newLabel = new NewLabel("labelName", "FF0000");
  399. client.Create("fake", "repo", newLabel);
  400. connection.Received().Post<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels"), newLabel);
  401. }
  402. [Fact]
  403. public void CreatesCorrectUrlWithRepositoryId()
  404. {
  405. var connection = Substitute.For<IApiConnection>();
  406. var client = new IssuesLabelsClient(connection);
  407. var newLabel = new NewLabel("labelName", "FF0000");
  408. client.Create(1, newLabel);
  409. connection.Received().Post<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels"), newLabel);
  410. }
  411. [Fact]
  412. public async Task EnsuresNonNullArguments()
  413. {
  414. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  415. var newLabel = new NewLabel("labelName", "FF0000");
  416. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", newLabel));
  417. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, newLabel));
  418. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
  419. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null));
  420. await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", newLabel));
  421. await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", newLabel));
  422. }
  423. }
  424. public class TheUpdateMethod
  425. {
  426. [Fact]
  427. public void UpdatesCorrectUrl()
  428. {
  429. var connection = Substitute.For<IApiConnection>();
  430. var client = new IssuesLabelsClient(connection);
  431. var labelUpdate = new LabelUpdate("name", "FF0000");
  432. client.Update("fake", "repo", "labelName", labelUpdate);
  433. connection.Received().Post<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels/labelName"), labelUpdate);
  434. }
  435. [Fact]
  436. public void UpdatesCorrectUrlWithRepositoryId()
  437. {
  438. var connection = Substitute.For<IApiConnection>();
  439. var client = new IssuesLabelsClient(connection);
  440. var labelUpdate = new LabelUpdate("name", "FF0000");
  441. client.Update(1, "labelName", labelUpdate);
  442. connection.Received().Post<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels/labelName"), labelUpdate);
  443. }
  444. [Fact]
  445. public async Task EnsuresNonNullArguments()
  446. {
  447. var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
  448. var labelUpdate = new LabelUpdate("name", "FF0000");
  449. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update(null, "name", "labelName", labelUpdate));
  450. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", null, "labelName", labelUpdate));
  451. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", "name", null, labelUpdate));
  452. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", "name", "labelName", null));
  453. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update(1, null, labelUpdate));
  454. await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update(1, "labelName", null));
  455. await Assert.ThrowsAsync<ArgumentException>(() => client.Update("", "name", "labelName", labelUpdate));
  456. await Assert.ThrowsAsync<ArgumentException>(() => client.Update("owner", "", "labelName", labelUpdate));
  457. await Assert.ThrowsAsync<ArgumentException>(() => client.Update("owner", "name", "", labelUpdate));
  458. await Assert.ThrowsAsync<ArgumentException>(() => client.Update(1, "", labelUpdate));
  459. }
  460. }
  461. }
  462. }