-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathStashClientTester.cs
More file actions
871 lines (705 loc) · 35.1 KB
/
StashClientTester.cs
File metadata and controls
871 lines (705 loc) · 35.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
using Atlassian.Stash.Api;
using Atlassian.Stash.Api.Entities;
using Atlassian.Stash.Api.Exceptions;
using Atlassian.Stash.Entities;
using Atlassian.Stash.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Atlassian.Stash.IntegrationTests
{
[TestClass]
public class StashClientTester : TestBase
{
[TestMethod]
public async Task Can_GetFileContents()
{
var response = await stashClient.Repositories.GetFileContents(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_FILE);
Assert.IsNotNull(response);
Assert.IsTrue(response.FileContents.Count > 0);
Assert.AreEqual(1, response.Size);
}
[TestMethod]
public async Task Can_GetFileContents_In_SubFolder()
{
var response = await stashClient.Repositories.GetFileContents(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_FILE_IN_SUBFOLDER);
Assert.IsNotNull(response);
Assert.IsTrue(response.FileContents.Count > 0);
Assert.AreEqual(1, response.Size);
}
[TestMethod]
public async Task Can_GetFileContents_In_SubFolder_With_Spaces()
{
var response = await stashClient.Repositories.GetFileContents(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_FILE_IN_SUBFOLDER_WITH_SPACES);
Assert.IsNotNull(response);
Assert.IsTrue(response.FileContents.Count > 0);
Assert.AreEqual(1, response.Size);
}
[TestMethod]
public async Task Can_GetFileContents_From_Branch()
{
var response = await stashClient.Repositories.GetFileContents(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_FILE, MASTER_BRANCH_NAME);
Assert.IsNotNull(response);
Assert.IsTrue(response.FileContents.Count > 0);
Assert.AreEqual(1, response.Size);
}
[TestMethod]
public async Task Can_GetBranchesForCommit()
{
var response = await stashClient.Branches.GetByCommitId(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT);
Assert.IsNotNull(response);
Assert.IsTrue(response.Values.Any(x => x.Id.Equals(MASTER_BRANCH_REFERENCE)));
}
[TestMethod]
public async Task Can_GetAllProjects()
{
var response = await stashClient.Projects.Get();
var projects = response.Values;
Assert.IsNotNull(projects);
Assert.IsInstanceOfType(projects, typeof(IEnumerable<Project>));
Assert.IsTrue(projects.Any());
}
[TestMethod]
public async Task Can_GetAllUsers()
{
var response = await stashClient.Groups.GetUsers(EXISTING_GROUP, new RequestOptions { Limit = 1, Start = 0 });
var projects = response.Values;
Assert.IsNotNull(projects);
Assert.IsInstanceOfType(projects, typeof(IEnumerable<User>));
Assert.IsTrue(projects.Any());
}
[TestMethod]
public async Task Can_GetAllProjects_WithRequestOptions()
{
int requestLimit = 1;
var response = await stashClient.Projects.Get(new RequestOptions { Limit = requestLimit, Start = 0 });
var projects = response.Values;
Assert.IsNotNull(projects);
Assert.IsInstanceOfType(projects, typeof(IEnumerable<Project>));
Assert.AreEqual(requestLimit, projects.Count());
}
[TestMethod]
public async Task Can_GetByIdProject()
{
var project = await stashClient.Projects.GetById(EXISTING_PROJECT);
Assert.IsNotNull(project);
Assert.IsInstanceOfType(project, typeof(Project));
Assert.AreEqual(EXISTING_PROJECT.ToLower(), project.Name.ToLower());
}
[TestMethod]
public async Task Can_GetAllSizes()
{
var response = await this.stashClient.Repositories.GetSizes(this.EXISTING_PROJECT, this.EXISTING_REPOSITORY);
Assert.IsNotNull(response.Repository);
Assert.IsNotNull(response.Attachments);
}
[TestMethod]
public async Task Can_GetAllRepositories()
{
var response = await stashClient.Repositories.Get(EXISTING_PROJECT);
var repositories = response.Values;
Assert.IsNotNull(repositories);
Assert.IsInstanceOfType(repositories, typeof(IEnumerable<Repository>));
Assert.IsTrue(repositories.Any());
}
[TestMethod]
public async Task Can_GetAllRepositories_WithRequestOptions()
{
int requestLimit = 1;
var response = await stashClient.Repositories.Get(EXISTING_PROJECT, new RequestOptions { Limit = requestLimit });
var repositories = response.Values;
Assert.IsNotNull(repositories);
Assert.IsInstanceOfType(repositories, typeof(IEnumerable<Repository>));
Assert.AreEqual(requestLimit, repositories.Count());
}
[TestMethod]
public async Task Can_GetByIdRepository()
{
var repository = await stashClient.Repositories.GetById(EXISTING_PROJECT, EXISTING_REPOSITORY);
Assert.IsNotNull(repository);
Assert.IsInstanceOfType(repository, typeof(Repository));
Assert.AreEqual(EXISTING_REPOSITORY.ToLower(), repository.Name.ToLower());
}
[TestMethod]
public async Task Can_GetAllTags()
{
var response = await stashClient.Repositories.GetTags(EXISTING_PROJECT, EXISTING_REPOSITORY);
var tags = response.Values;
Assert.IsNotNull(tags);
Assert.IsInstanceOfType(tags, typeof(IEnumerable<Tag>));
Assert.IsTrue(tags.Any());
}
[TestMethod]
public async Task Can_GetAllTags_WithRequestOptions()
{
int requestLimit = 1;
var response = await stashClient.Repositories.GetTags(EXISTING_PROJECT, EXISTING_REPOSITORY, new RequestOptions { Limit = requestLimit });
var tags = response.Values;
Assert.IsNotNull(tags);
Assert.IsInstanceOfType(tags, typeof(IEnumerable<Tag>));
Assert.AreEqual(requestLimit, tags.Count());
}
[TestMethod]
public async Task Can_Create_And_Delete_Tags()
{
var initialResponse = await stashClient.Repositories.GetTags(EXISTING_PROJECT, EXISTING_REPOSITORY);
int initialTagCount = initialResponse.Values.Count();
// create tag
Tag createTag = new Tag
{
Force = true,
Name = "integration-test-tag",
Message = "integration test tag",
StartPoint = "refs/heads/master",
Type = TagType.ANNOTATED
};
var createResponse = await stashClient.Repositories.CreateTag(EXISTING_PROJECT, EXISTING_REPOSITORY, createTag);
// mid-step get tags again
var midResponse = await stashClient.Repositories.GetTags(EXISTING_PROJECT, EXISTING_REPOSITORY);
int midTagCount = midResponse.Values.Count();
Assert.AreEqual(initialTagCount + 1, midTagCount);
Assert.IsTrue(midResponse.Values.Any(x => x.Id.Contains(createTag.Name)));
// delete tag
await stashClient.Repositories.DeleteTag(EXISTING_PROJECT, EXISTING_REPOSITORY, createTag.Name);
// final check to ensure the tag count didn't change
var finalResponse = await stashClient.Repositories.GetTags(EXISTING_PROJECT, EXISTING_REPOSITORY);
int finalTagCount = initialResponse.Values.Count();
Assert.AreEqual(initialTagCount, finalTagCount);
}
[TestMethod]
public async Task Can_GetFilesInSubFolder()
{
var response = await stashClient.Repositories.GetFiles(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_FOLDER);
var files = response.Values;
Assert.IsNotNull(files);
Assert.IsInstanceOfType(files, typeof(IEnumerable<string>));
Assert.IsTrue(files.Any());
}
[TestMethod]
public async Task Can_GetAllFiles()
{
var response = await stashClient.Repositories.GetFiles(EXISTING_PROJECT, EXISTING_REPOSITORY);
var files = response.Values;
Assert.IsNotNull(files);
Assert.IsInstanceOfType(files, typeof(IEnumerable<string>));
Assert.IsTrue(files.Any());
}
[TestMethod]
public async Task Can_GetAllFiles_WithRequestOptions()
{
int requestLimit = 1;
var response = await stashClient.Repositories.GetFiles(EXISTING_PROJECT, EXISTING_REPOSITORY, new RequestOptions { Limit = requestLimit });
var files = response.Values;
Assert.IsNotNull(files);
Assert.IsInstanceOfType(files, typeof(IEnumerable<string>));
Assert.AreEqual(requestLimit, files.Count());
}
[TestMethod]
public async Task Can_GetPullRequestSettings()
{
var response = await stashClient.Repositories.GetPullRequestSettings(EXISTING_PROJECT, EXISTING_REPOSITORY);
Assert.IsNotNull(response);
Assert.IsNotNull(response.MergeConfig);
Assert.IsNotNull(response.MergeConfig.DefaultStrategy);
Assert.IsNotNull(response.MergeConfig.Strategies);
Assert.IsNotNull(response.MergeConfig.Type = "REPOSITORY");
Assert.IsNotNull(response.RequiredApprovers = 0);
}
[TestMethod]
public async Task Can_SetPullRequestSettings()
{
var originalSettings = await stashClient.Repositories.GetPullRequestSettings(EXISTING_PROJECT, EXISTING_REPOSITORY);
var settings = new PullRequestSettings
{
MergeConfig = new MergeConfig
{
DefaultStrategy = new Strategy {Id = StrategyIdType.SQUASH_FAST_FORWARD_ONLY},
Strategies = new List<Strategy>
{
new Strategy {Id = StrategyIdType.SQUASH_FAST_FORWARD_ONLY},
new Strategy {Id = StrategyIdType.NO_FAST_FORWARD}
}
},
RequiredAllApprovers = false,
RequiredAllTasksComplete = false,
RequiredApprovers = 2,
RequiredSuccessfulBuilds = 1
};
await stashClient.Repositories.SetPullRequestSettings(EXISTING_PROJECT, EXISTING_REPOSITORY, settings);
var response = await stashClient.Repositories.GetPullRequestSettings(EXISTING_PROJECT, EXISTING_REPOSITORY);
Assert.IsNotNull(response);
Assert.IsNotNull(response.MergeConfig);
Assert.IsNotNull(response.MergeConfig.DefaultStrategy);
Assert.IsNotNull(response.MergeConfig.DefaultStrategy.Id = StrategyIdType.SQUASH_FAST_FORWARD_ONLY);
Assert.IsNotNull(response.MergeConfig.Strategies);
Assert.AreEqual(2, response.MergeConfig.Strategies.Count(s => s.Enabled != null && s.Enabled.Value));
Assert.AreEqual(2, response.RequiredApprovers);
Assert.AreEqual(1, response.RequiredSuccessfulBuilds);
await stashClient.Repositories.SetPullRequestSettings(EXISTING_PROJECT, EXISTING_REPOSITORY, originalSettings);
}
[TestMethod]
public async Task Can_GetAllBranches()
{
var response = await stashClient.Branches.Get(EXISTING_PROJECT, EXISTING_REPOSITORY);
var branches = response.Values;
Assert.IsNotNull(branches);
Assert.IsInstanceOfType(branches, typeof(IEnumerable<Branch>));
Assert.IsTrue(branches.Any());
}
[TestMethod]
public async Task GetPullRequest_RetrieveAllPullRequests_ReturnsSomePullRequests()
{
var response = await stashClient.PullRequests.Get(EXISTING_PROJECT, EXISTING_REPOSITORY, state: PullRequestState.ALL);
var pullRequests = response.Values;
Assert.IsNotNull(pullRequests);
Assert.IsInstanceOfType(pullRequests, typeof(IEnumerable<PullRequest>));
Assert.IsTrue(pullRequests.Any());
}
[TestMethod]
public async Task GetPullRequest_WithRequestOptions_ReturnsSomePullRequests()
{
var response = await stashClient.PullRequests.Get(EXISTING_PROJECT, EXISTING_REPOSITORY, new RequestOptions { Limit = 1 }, state: PullRequestState.ALL);
var pullRequests = response.Values;
Assert.IsNotNull(pullRequests);
Assert.IsInstanceOfType(pullRequests, typeof(IEnumerable<PullRequest>));
Assert.IsTrue(pullRequests.Any());
}
[TestMethod]
public async Task Can_GetAllBranches_WithRequestOptions()
{
int requestLimit = 1;
var response = await stashClient.Branches.Get(EXISTING_PROJECT, EXISTING_REPOSITORY, new RequestOptions { Limit = requestLimit });
var branches = response.Values;
Assert.IsNotNull(branches);
Assert.IsInstanceOfType(branches, typeof(IEnumerable<Branch>));
Assert.AreEqual(requestLimit, branches.Count());
}
[TestMethod]
public async Task Can_GetAllCommits()
{
var response = await stashClient.Commits.Get(EXISTING_PROJECT, EXISTING_REPOSITORY);
var commits = response.Values;
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(IEnumerable<Commit>));
Assert.IsTrue(commits.Any());
}
[TestMethod]
public async Task Can_GetAllCommits_WithRequestOptions()
{
int requestLimit = 2;
var response = await stashClient.Commits.Get(EXISTING_PROJECT, EXISTING_REPOSITORY, new RequestOptions { Limit = requestLimit });
var commits = response.Values;
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(IEnumerable<Commit>));
Assert.AreEqual(requestLimit, commits.Count());
}
[TestMethod]
public async Task Can_GetAllCommits_WithRequestOptionsForCommits()
{
int expectedCommitCount = 1;
var response = await stashClient.Commits.Get(EXISTING_PROJECT, EXISTING_REPOSITORY, null, new RequestOptionsForCommits { Until = EXISTING_COMMIT, Since = EXISTING_OLDER_COMMIT });
var commits = response.Values;
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(IEnumerable<Commit>));
Assert.AreEqual(expectedCommitCount, commits.Count());
}
[TestMethod]
public async Task Can_GetByIdCommit()
{
var commit = await stashClient.Commits.GetById(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT);
Assert.IsNotNull(commit);
Assert.IsInstanceOfType(commit, typeof(Commit));
Assert.AreEqual(EXISTING_COMMIT.ToLower(), commit.Id.ToLower());
}
[TestMethod]
public async Task Can_GetChangesUntil()
{
var changes = await stashClient.Commits.GetChanges(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT);
Assert.IsNotNull(changes);
Assert.IsInstanceOfType(changes, typeof(Changes));
Assert.AreEqual(EXISTING_COMMIT.ToLower(), changes.ToHash.ToLower());
}
[TestMethod]
public async Task Can_GetChangesUntil_WithRequestOptions()
{
int requestLimit = 1;
var changes = await stashClient.Commits.GetChanges(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, null, new RequestOptions { Limit = requestLimit });
Assert.IsNotNull(changes);
Assert.IsInstanceOfType(changes, typeof(Changes));
Assert.AreEqual(EXISTING_COMMIT.ToLower(), changes.ToHash.ToLower());
Assert.AreEqual(requestLimit, changes.ListOfChanges.Count());
}
[TestMethod]
public async Task Can_GetChangesUntil_And_Since()
{
var changes = await stashClient.Commits.GetChanges(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, EXISTING_OLDER_COMMIT);
Assert.IsNotNull(changes);
Assert.IsInstanceOfType(changes, typeof(Changes));
Assert.AreEqual(EXISTING_COMMIT.ToLower(), changes.ToHash.ToLower());
}
[TestMethod]
public async Task Can_GetChangesUntil_And_Since_WithRequestOptions()
{
int requestLimit = 1;
var changes = await stashClient.Commits.GetChanges(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, EXISTING_OLDER_COMMIT, new RequestOptions { Limit = requestLimit });
Assert.IsNotNull(changes);
Assert.IsInstanceOfType(changes, typeof(Changes));
Assert.AreEqual(EXISTING_COMMIT.ToLower(), changes.ToHash.ToLower());
Assert.AreEqual(requestLimit, changes.ListOfChanges.Count());
}
[TestMethod]
public async Task Can_GetChangesUntil_And_Since_MoreThanOneResult()
{
var changes = await stashClient.Commits.GetChanges(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, EXISTING_OLDER_COMMIT);
Assert.IsNotNull(changes);
Assert.IsInstanceOfType(changes, typeof(Changes));
Assert.AreEqual(EXISTING_COMMIT, changes.ToHash, ignoreCase: true);
Assert.AreEqual(EXISTING_NUMBER_OF_CHANGES, changes.ListOfChanges.Count());
}
[TestMethod]
public async Task Can_GetCommitsUntil()
{
var commits = await stashClient.Commits.GetCommits(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT);
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(ResponseWrapper<Commit>));
Assert.IsTrue(commits.Values.Count() > 1);
Assert.IsTrue(commits.Values.Any(x => x.Id.Equals(EXISTING_COMMIT, StringComparison.OrdinalIgnoreCase)));
}
[TestMethod]
public async Task Can_GetCommitsUntil_WithRequestOptions()
{
int requestLimit = 1;
var commits = await stashClient.Commits.GetCommits(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, null, new RequestOptions { Limit = requestLimit });
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(ResponseWrapper<Commit>));
Assert.IsTrue(commits.Values.Count() > 0);
Assert.IsTrue(commits.Values.Any(x => x.Id.Equals(EXISTING_COMMIT, StringComparison.OrdinalIgnoreCase)));
}
[TestMethod]
public async Task Can_GetCommitsUntil_And_Since()
{
var commits = await stashClient.Commits.GetCommits(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, EXISTING_OLDER_COMMIT);
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(ResponseWrapper<Commit>));
Assert.IsTrue(commits.Values.Count() > 0);
Assert.IsTrue(commits.Values.Any(x => x.Id.Equals(EXISTING_COMMIT, StringComparison.OrdinalIgnoreCase)));
// excluside call (excludes 'since' commit)
Assert.IsFalse(commits.Values.Any(x => x.Id.Equals(EXISTING_OLDER_COMMIT, StringComparison.OrdinalIgnoreCase)));
}
[TestMethod]
public async Task Can_GetCommitsUntil_And_Since_WithRequestOptions()
{
int requestLimit = 1;
var commits = await stashClient.Commits.GetCommits(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, EXISTING_OLDER_COMMIT, new RequestOptions { Limit = requestLimit });
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(ResponseWrapper<Commit>));
Assert.IsTrue(commits.Values.Count() > 0);
Assert.IsTrue(commits.Values.Any(x => x.Id.Equals(EXISTING_COMMIT, StringComparison.OrdinalIgnoreCase)));
// excluside call (excludes 'since' commit)
Assert.IsFalse(commits.Values.Any(x => x.Id.Equals(EXISTING_OLDER_COMMIT, StringComparison.OrdinalIgnoreCase)));
}
[TestMethod]
public async Task Can_GetCommitsUntil_And_Since_MoreThanOneResult()
{
var commits = await stashClient.Commits.GetCommits(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_COMMIT, EXISTING_OLDER_COMMIT);
Assert.IsNotNull(commits);
Assert.IsInstanceOfType(commits, typeof(ResponseWrapper<Commit>));
Assert.IsTrue(commits.Values.Count() > 0);
Assert.IsTrue(commits.Values.Any(x => x.Id.Equals(EXISTING_COMMIT, StringComparison.OrdinalIgnoreCase)));
// excluside call (excludes 'since' commit)
Assert.IsFalse(commits.Values.Any(x => x.Id.Equals(EXISTING_OLDER_COMMIT, StringComparison.OrdinalIgnoreCase)));
}
[TestMethod]
public async Task Can_GetRepository_Hooks()
{
var response = await stashClient.Repositories.GetHooks(EXISTING_PROJECT, EXISTING_REPOSITORY);
var hooks = response.Values;
Assert.IsNotNull(hooks);
Assert.IsInstanceOfType(hooks, typeof(IEnumerable<Hook>));
Assert.IsTrue(hooks.Any());
}
[TestMethod]
public async Task Can_GetRepository_Hooks_WithRequestOptions()
{
int requestLimit = 1;
var response = await stashClient.Repositories.GetHooks(EXISTING_PROJECT, EXISTING_REPOSITORY, new RequestOptions { Limit = requestLimit });
var hooks = response.Values;
Assert.IsNotNull(hooks);
Assert.IsInstanceOfType(hooks, typeof(IEnumerable<Hook>));
Assert.AreEqual(requestLimit, hooks.Count());
}
[TestMethod]
public async Task Can_GetRepository_Hook_ById()
{
var response = await stashClient.Repositories.GetHookById(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_HOOK);
Assert.IsNotNull(response);
Assert.IsInstanceOfType(response, typeof(Hook));
Assert.AreEqual(EXISTING_HOOK, response.Details.Key);
}
[TestMethod]
public async Task Can_SetDefaultBranch_Than_RetrieveIt()
{
var response = await stashClient.Branches.GetDefault(EXISTING_PROJECT, EXISTING_REPOSITORY);
Assert.IsNotNull(response);
Assert.AreEqual("refs/heads/master", response.Id);
var defaultBranch = new Branch { Id = "refs/heads/develop" };
await stashClient.Branches.SetDefault(EXISTING_PROJECT, EXISTING_REPOSITORY, defaultBranch);
response = await stashClient.Branches.GetDefault(EXISTING_PROJECT, EXISTING_REPOSITORY);
Assert.IsNotNull(response);
Assert.AreEqual("refs/heads/develop", response.Id);
defaultBranch = new Branch { Id = "refs/heads/master" };
await stashClient.Branches.SetDefault(EXISTING_PROJECT, EXISTING_REPOSITORY, defaultBranch);
}
[TestMethod]
public async Task Can_GetBranchPermissions()
{
var response = await stashClient.Branches.GetPermissions(EXISTING_PROJECT, EXISTING_REPOSITORY);
Assert.IsNotNull(response);
Assert.IsInstanceOfType(response, typeof(ResponseWrapper<BranchPermission>));
}
[TestMethod]
public async Task Can_SetBranchPermissions_Than_DeleteBranchPermissions()
{
BranchPermission setBranchPerm = new BranchPermission
{
Type = BranchPermissionType.READ_ONLY,
Matcher = new BranchPermissionMatcher
{
Id = "master",
DisplayId = "master",
Active = true,
Type = new BranchPermissionMatcherType
{
Id = BranchPermissionMatcherTypeName.BRANCH,
Name = "Branch"
}
},
Users = new List<User>(),
Groups = new string[] { EXISTING_GROUP }
};
var response = await stashClient.Branches.SetPermissions(EXISTING_PROJECT, EXISTING_REPOSITORY, setBranchPerm);
Assert.IsNotNull(response);
Assert.IsInstanceOfType(response, typeof(BranchPermission));
Assert.AreEqual(setBranchPerm.Type, response.Type);
Assert.AreEqual(setBranchPerm.Matcher.Id, response.Matcher.Id);
Assert.AreEqual(setBranchPerm.Matcher.Type.Id, response.Matcher.Type.Id);
Assert.IsTrue(response.Id > 0);
await stashClient.Branches.DeletePermissions(EXISTING_PROJECT, EXISTING_REPOSITORY, response.Id);
}
[TestMethod]
public async Task Can_SetBranchPermissions_Than_DeleteBranchPermissions_Using_Pattern()
{
BranchPermission setBranchPerm = new BranchPermission
{
Type = BranchPermissionType.READ_ONLY,
Matcher = new BranchPermissionMatcher
{
Id = "**",
DisplayId = "**",
Active = true,
Type = new BranchPermissionMatcherType
{
Id = BranchPermissionMatcherTypeName.PATTERN,
Name = "Pattern"
}
},
Users = new List<User>(),
Groups = new string[] { EXISTING_GROUP }
};
var response = await stashClient.Branches.SetPermissions(EXISTING_PROJECT, EXISTING_REPOSITORY, setBranchPerm);
Assert.IsNotNull(response);
Assert.IsInstanceOfType(response, typeof(BranchPermission));
Assert.AreEqual(setBranchPerm.Type, response.Type);
Assert.AreEqual(setBranchPerm.Matcher.Id, response.Matcher.Id);
Assert.AreEqual(setBranchPerm.Matcher.Type.Id, response.Matcher.Type.Id);
Assert.IsTrue(response.Id > 0);
await stashClient.Branches.DeletePermissions(EXISTING_PROJECT, EXISTING_REPOSITORY, response.Id);
}
[TestMethod]
public async Task Can_CreateProject_Than_DeleteProject()
{
Project newProject = new Project { Key = "ZTEST", Name = "Project of Integration tests", Description = "Project created by integration tests, please delete!" };
var createdProject = await stashClient.Projects.Create(newProject);
Assert.IsNotNull(createdProject);
Assert.IsInstanceOfType(createdProject, typeof(Project));
Assert.AreEqual(newProject.Key.ToLower(), createdProject.Key.ToLower());
await stashClient.Projects.Delete(newProject.Key);
}
[TestMethod]
public async Task Can_CreateRepository_Than_DeleteRepository()
{
Repository newRepository = new Repository { Name = "Repository of Integration tests" };
var createdRepository = await stashClient.Repositories.Create(EXISTING_PROJECT, newRepository);
Assert.IsNotNull(createdRepository);
Assert.IsInstanceOfType(createdRepository, typeof(Repository));
Assert.AreEqual(newRepository.Name.ToLower(), createdRepository.Name.ToLower());
await stashClient.Repositories.Delete(EXISTING_PROJECT, createdRepository.Slug);
}
[TestMethod]
public async Task Can_CreateBranch_Than_DeleteBranch()
{
Branch newBranch = new Branch { Name = "test-repo", StartPoint = MASTER_BRANCH_REFERENCE };
var createdBranch = await stashClient.Branches.Create(EXISTING_PROJECT, EXISTING_REPOSITORY, newBranch);
Assert.IsNotNull(createdBranch);
Assert.IsInstanceOfType(createdBranch, typeof(Branch));
Assert.AreEqual(newBranch.Name.ToLower(), createdBranch.DisplayId.ToLower());
Branch deleteBranch = new Branch { Name = newBranch.Name, DryRun = false };
await stashClient.Branches.Delete(EXISTING_PROJECT, EXISTING_REPOSITORY, deleteBranch);
}
[TestMethod]
public async Task Can_Get_Enable_And_Disable_Hook()
{
var enableHook = await stashClient.Repositories.EnableHook(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_HOOK);
Assert.IsNotNull(enableHook);
Assert.IsTrue(enableHook.Enabled);
Assert.IsInstanceOfType(enableHook, typeof(Hook));
Assert.AreEqual(EXISTING_HOOK, enableHook.Details.Key);
var disableHook = await stashClient.Repositories.DisableHook(EXISTING_PROJECT, EXISTING_REPOSITORY, EXISTING_HOOK);
Assert.IsNotNull(disableHook);
Assert.IsFalse(disableHook.Enabled);
Assert.IsInstanceOfType(disableHook, typeof(Hook));
Assert.AreEqual(EXISTING_HOOK, disableHook.Details.Key);
}
[TestMethod]
public async Task Can_Create_Group_Then_Delete_Group()
{
#region Setup/Clean up
var existingTestGroups = await stashClient.Groups.Get("tempTestGroup");
foreach (var existingGroup in existingTestGroups.Values)
{
await stashClient.Groups.Delete(existingGroup.Name);
}
#endregion
var group = await stashClient.Groups.Create("tempTestGroup");
await stashClient.Groups.Delete(group.Name);
var finalSetOfTestGroups = await stashClient.Groups.Get("tempTestGroup");
Assert.AreEqual(0, finalSetOfTestGroups.Values.Count());
}
[TestMethod]
public async Task Can_Create_User_Then_AddTogroup_Then_Delete_User()
{
#region Setup/Clean up
var existingTestUsers = await stashClient.Users.Get("tmpTestUser");
foreach (var existingUser in existingTestUsers.Values)
{
await stashClient.Users.Delete(existingUser.Name);
}
#endregion
await stashClient.Users.Create("tmpTestUser", "Temporary test user", "tmpUser@company.com", "password");
await stashClient.Users.AddToGroups("tmpTestUser", EXISTING_GROUP);
var deletedUser = await stashClient.Users.Delete("tmpTestUser");
Assert.IsNotNull(deletedUser);
Assert.IsInstanceOfType(deletedUser, typeof(User));
Assert.AreEqual("tmpTestUser", deletedUser.Name);
}
[TestMethod]
public async Task Can_Get_Then_Create_Then_Grant_Access_To_Project_And_Delete_User()
{
#region Setup/Clean up
var existingTestUsers = await stashClient.Users.Get("tmpTestUser");
foreach (var existingUser in existingTestUsers.Values)
{
await stashClient.Users.Delete(existingUser.Name);
}
#endregion
await stashClient.Users.Create("tmpTestUser", "Temporary test user", "tmpUser@company.com", "password");
await stashClient.Projects.GrantUser(EXISTING_PROJECT, "tmpTestUser", ProjectPermissions.PROJECT_ADMIN);
var deletedUser = await stashClient.Users.Delete("tmpTestUser");
Assert.IsNotNull(deletedUser);
Assert.IsInstanceOfType(deletedUser, typeof(User));
Assert.AreEqual("tmpTestUser", deletedUser.Name);
}
[TestMethod]
public async Task Can_GetPullRequestStatus()
{
var pullrequests = await stashClient.PullRequests.Get(EXISTING_PROJECT, EXISTING_REPOSITORY);
var request = pullrequests.Values.First();
var status = await stashClient.PullRequests.Status(request, EXISTING_PROJECT);
Assert.IsNotNull(status);
}
[TestMethod]
public async Task Create_Update_Decline_Approve_Merge_PullRequest()
{
var newPullRequest = new PullRequest
{
Title = "Automatically Generated Pull Request",
Author = new AuthorWrapper
{
User = new Author
{
Name = TEST_USERNAME
}
},
FromRef = new Ref
{
Id = DEVELOP_BRANCH_REFERENCE,
Repository = new Repository
{
Slug = EXISTING_REPOSITORY,
Project = new Project
{
Key = EXISTING_PROJECT
}
}
},
ToRef = new Ref
{
Id = MASTER_BRANCH_REFERENCE,
Repository = new Repository
{
Slug = EXISTING_REPOSITORY,
Project = new Project
{
Key = EXISTING_PROJECT
}
}
},
State = PullRequestState.OPEN
};
newPullRequest = await stashClient.PullRequests.Create(EXISTING_PROJECT, EXISTING_REPOSITORY, newPullRequest);
Assert.IsTrue(newPullRequest.State != PullRequestState.MERGED);
Assert.IsTrue(newPullRequest.Reviewers.Length == 0);
newPullRequest.Reviewers = new[]
{
new AuthorWrapper
{
User = new Author
{
Name = OTHERTEST_USERNAME
}
}
};
newPullRequest = await stashClient.PullRequests.Update(newPullRequest, EXISTING_PROJECT, EXISTING_REPOSITORY);
Assert.IsTrue(newPullRequest.Reviewers.Length == 1);
stashClient.SetBasicAuthentication(OTHERTEST_USERNAME, OTHERTEST_PASSWORD);
var pullRequestReviewed = await stashClient.PullRequests.Approve(newPullRequest, EXISTING_PROJECT);
Assert.IsTrue(pullRequestReviewed.Approved);
pullRequestReviewed = await stashClient.PullRequests.Decline(newPullRequest, EXISTING_PROJECT);
Assert.IsFalse(pullRequestReviewed.Approved);
stashClient.SetBasicAuthentication(TEST_USERNAME, TEST_PASSWORD);
newPullRequest = await stashClient.PullRequests.Merge(newPullRequest, EXISTING_PROJECT);
Assert.IsTrue(newPullRequest.State == PullRequestState.MERGED);
}
[TestMethod]
public async Task Get_TestUser_User_With_BearAuthenticationToken()
{
var client = new StashClient(BASE_URL, PERSONAL_ACCESS_TOKEN, true);
var response = await client.Users.Get(TEST_USERNAME);
var users = response.Values;
Assert.IsNotNull(users);
Assert.IsTrue(users.Any());
Assert.IsNotNull(users.Single(user => user.Name == TEST_USERNAME));
}
[TestMethod]
public async Task Can_GetAllLabels()
{
var response = await stashClient.Labels.Get();
var projects = response.Values;
Assert.IsNotNull(projects);
Assert.IsInstanceOfType(projects, typeof(IEnumerable<Label>));
Assert.IsTrue(projects.Any());
}
}
}