@@ -36,7 +36,8 @@ public async Task Filter(string filter, string owner, string name, string url, i
3636 var hostAddress = HostAddress . GitHubDotComHostAddress ;
3737 var connection = CreateConnection ( hostAddress ) ;
3838 var repositoryCloneService = CreateRepositoryCloneService ( contributedToRepositories , hostAddress ) ;
39- var target = new RepositorySelectViewModel ( repositoryCloneService ) ;
39+ var gitHubContextService = CreateGitHubContextService ( ) ;
40+ var target = new RepositorySelectViewModel ( repositoryCloneService , gitHubContextService ) ;
4041 target . Filter = filter ;
4142 target . Initialize ( connection ) ;
4243
@@ -49,39 +50,63 @@ public async Task Filter(string filter, string owner, string name, string url, i
4950 Assert . That ( items . Count , Is . EqualTo ( expectCount ) ) ;
5051 }
5152
52- static IConnection CreateConnection ( HostAddress hostAddress )
53+ [ TestCase ( "filter" , null ) ]
54+ [ TestCase ( "https://github.com" , null ) ]
55+ [ TestCase ( "https://github.com/github/VisualStudio" , "https://github.com/github/VisualStudio" ) ]
56+ public void Set_Repository_When_Filter_Is_Url ( string url , string expectUrl )
5357 {
54- var connection = Substitute . For < IConnection > ( ) ;
55- connection . HostAddress . Returns ( hostAddress ) ;
56- return connection ;
57- }
58+ var expectCloneUrl = expectUrl != null ? new UriString ( expectUrl ) : null ;
59+ var repositoryCloneService = CreateRepositoryCloneService ( ) ;
60+ var gitHubContextService = new GitHubContextService ( Substitute . For < IGitHubServiceProvider > ( ) ,
61+ Substitute . For < IGitService > ( ) , Substitute . For < IVSServices > ( ) ) ;
62+ var target = new RepositorySelectViewModel ( repositoryCloneService , gitHubContextService ) ;
5863
59- static IRepositoryCloneService CreateRepositoryCloneService (
60- IList < RepositoryListItemModel > contributedToRepositories ,
61- HostAddress hostAddress )
62- {
63- var viewRepositoriesModel = CreateViewerRepositoriesModel ( contributedToRepositories : contributedToRepositories ) ;
64- var repositoryCloneService = Substitute . For < IRepositoryCloneService > ( ) ;
65- repositoryCloneService . ReadViewerRepositories ( hostAddress ) . Returns ( viewRepositoriesModel ) ;
66- return repositoryCloneService ;
64+ target . Filter = url ;
65+
66+ Assert . That ( target . Repository ? . CloneUrl , Is . EqualTo ( expectCloneUrl ) ) ;
6767 }
68+ }
6869
69- private static ViewerRepositoriesModel CreateViewerRepositoriesModel (
70- string owner = "owner" ,
71- IList < RepositoryListItemModel > repositories = null ,
72- IList < RepositoryListItemModel > contributedToRepositories = null )
73- {
74- repositories = repositories ?? Array . Empty < RepositoryListItemModel > ( ) ;
75- contributedToRepositories = contributedToRepositories ?? Array . Empty < RepositoryListItemModel > ( ) ;
70+ static IGitHubContextService CreateGitHubContextService ( )
71+ {
72+ return Substitute . For < IGitHubContextService > ( ) ;
73+ }
7674
77- return new ViewerRepositoriesModel
78- {
79- Owner = owner ,
80- Repositories = CreateRepositoriesList ( repositories ) ,
81- ContributedToRepositories = CreateRepositoriesList ( contributedToRepositories ) ,
82- Organizations = CreateOrganizationsList ( )
83- } ;
84- }
75+ static IConnection CreateConnection ( HostAddress hostAddress )
76+ {
77+ var connection = Substitute . For < IConnection > ( ) ;
78+ connection . HostAddress . Returns ( hostAddress ) ;
79+ return connection ;
80+ }
81+
82+ static IRepositoryCloneService CreateRepositoryCloneService (
83+ IList < RepositoryListItemModel > contributedToRepositories = null ,
84+ HostAddress hostAddress = null )
85+ {
86+ contributedToRepositories = contributedToRepositories ?? Array . Empty < RepositoryListItemModel > ( ) ;
87+ hostAddress = hostAddress ?? HostAddress . GitHubDotComHostAddress ;
88+
89+ var viewRepositoriesModel = CreateViewerRepositoriesModel ( contributedToRepositories : contributedToRepositories ) ;
90+ var repositoryCloneService = Substitute . For < IRepositoryCloneService > ( ) ;
91+ repositoryCloneService . ReadViewerRepositories ( hostAddress ) . Returns ( viewRepositoriesModel ) ;
92+ return repositoryCloneService ;
93+ }
94+
95+ private static ViewerRepositoriesModel CreateViewerRepositoriesModel (
96+ string owner = "owner" ,
97+ IList < RepositoryListItemModel > repositories = null ,
98+ IList < RepositoryListItemModel > contributedToRepositories = null )
99+ {
100+ repositories = repositories ?? Array . Empty < RepositoryListItemModel > ( ) ;
101+ contributedToRepositories = contributedToRepositories ?? Array . Empty < RepositoryListItemModel > ( ) ;
102+
103+ return new ViewerRepositoriesModel
104+ {
105+ Owner = owner ,
106+ Repositories = CreateRepositoriesList ( repositories ) ,
107+ ContributedToRepositories = CreateRepositoriesList ( contributedToRepositories ) ,
108+ Organizations = CreateOrganizationsList ( )
109+ } ;
85110 }
86111
87112 static IReadOnlyList < RepositoryListItemModel > CreateRepositoriesList ( IList < RepositoryListItemModel > repositories )
0 commit comments