1+ using System . Text ;
12using NSubstitute ;
23using Octokit ;
34using Spectre . Console ;
45using Xunit ;
6+ using Repository = GitHubLabelSync . Tests . Stubs . Repository ;
57
68namespace GitHubLabelSync . Tests ;
79
@@ -16,7 +18,7 @@ public async Task SyncsAllReposFound()
1618 var sync = Substitute . For < ISynchronizer > ( ) ;
1719 sync . ValidateAccess ( ) . Returns ( ValidationResult . Success ( ) ) ;
1820 sync . ValidateUser ( Arg . Any < Account > ( ) ) . Returns ( ValidationResult . Success ( ) ) ;
19- sync . GetRepositories ( Arg . Any < Account > ( ) ) . Returns ( new [ ] { new Repository ( ) , new Repository ( ) , new Repository ( ) } ) ;
21+ sync . GetRepositories ( Arg . Any < Account > ( ) ) . Returns ( new [ ] { new Repository ( "test1" ) , new Repository ( "test2" ) , new Repository ( "test3" ) } ) ;
2022 var app = new App ( sync , NoOp , NoOp ) ;
2123
2224 var settings = new Settings { Name = "ecoAPM" } ;
@@ -29,14 +31,50 @@ public async Task SyncsAllReposFound()
2931 await sync . Received ( 3 ) . SyncRepo ( Arg . Any < Repository > ( ) , settings , Arg . Any < IReadOnlyList < Label > > ( ) ) ;
3032 }
3133
34+ [ Fact ]
35+ public async Task SyncsFilteredRepos ( )
36+ {
37+ //arrange
38+ var sync = Substitute . For < ISynchronizer > ( ) ;
39+ sync . ValidateAccess ( ) . Returns ( ValidationResult . Success ( ) ) ;
40+ sync . ValidateUser ( Arg . Any < Account > ( ) ) . Returns ( ValidationResult . Success ( ) ) ;
41+ sync . GetRepositories ( Arg . Any < Account > ( ) ) . Returns ( new [ ]
42+ {
43+ new Repository ( "other1" ) ,
44+ new Repository ( "test-abc1" ) ,
45+ new Repository ( "test-abc2" ) ,
46+ new Repository ( "def" ) ,
47+ new Repository ( "other22" ) ,
48+ } ) ;
49+ var app = new App ( sync , NoOp , NoOp ) ;
50+
51+ var settings = new Settings
52+ {
53+ Name = "ecoAPM" ,
54+ Filters = new [ ] { "abc" , "def" }
55+ } ;
56+
57+ //act
58+ await app . Run ( settings ) ;
59+
60+ //assert
61+ await sync . Received ( ) . GetAccount ( "ecoAPM" ) ;
62+ await sync . Received ( 3 ) . SyncRepo ( Arg . Any < Repository > ( ) , settings , Arg . Any < IReadOnlyList < Label > > ( ) ) ;
63+ }
64+
3265 [ Fact ]
3366 public async Task SkipsArchivedRepos ( )
3467 {
3568 //arrange
3669 var sync = Substitute . For < ISynchronizer > ( ) ;
3770 sync . ValidateAccess ( ) . Returns ( ValidationResult . Success ( ) ) ;
3871 sync . ValidateUser ( Arg . Any < Account > ( ) ) . Returns ( ValidationResult . Success ( ) ) ;
39- sync . GetRepositories ( Arg . Any < Account > ( ) ) . Returns ( new [ ] { new Repository ( ) , new Stubs . ArchivedRepository ( ) , new Repository ( ) } ) ;
72+ sync . GetRepositories ( Arg . Any < Account > ( ) ) . Returns ( new [ ]
73+ {
74+ new Repository ( "test1" ) ,
75+ new Repository ( "test2" , true ) ,
76+ new Repository ( "test3" )
77+ } ) ;
4078 var app = new App ( sync , NoOp , NoOp ) ;
4179
4280 var settings = new Settings { Name = "ecoAPM" } ;
@@ -48,6 +86,26 @@ public async Task SkipsArchivedRepos()
4886 await sync . Received ( 2 ) . SyncRepo ( Arg . Any < Repository > ( ) , settings , Arg . Any < IReadOnlyList < Label > > ( ) ) ;
4987 }
5088
89+ [ Fact ]
90+ public async Task ShowsMessageWhenNoRepos ( )
91+ {
92+ //arrange
93+ var sync = Substitute . For < ISynchronizer > ( ) ;
94+ sync . ValidateAccess ( ) . Returns ( ValidationResult . Success ( ) ) ;
95+ sync . ValidateUser ( Arg . Any < Account > ( ) ) . Returns ( ValidationResult . Success ( ) ) ;
96+ sync . GetRepositories ( Arg . Any < Account > ( ) ) . Returns ( Array . Empty < Repository > ( ) ) ;
97+ var output = new StringBuilder ( ) ;
98+ var app = new App ( sync , NoOp , s => output . AppendLine ( s ) ) ;
99+
100+ var settings = new Settings { Name = "ecoAPM" } ;
101+
102+ //act
103+ await app . Run ( settings ) ;
104+
105+ //assert
106+ Assert . Contains ( "no repositories to sync" , output . ToString ( ) ) ;
107+ }
108+
51109 [ Fact ]
52110 public async Task ThrowsOnAccessValidationFailure ( )
53111 {
0 commit comments