@@ -208,15 +208,15 @@ public async Task FetchUsingHttps(string repoUrl, string expectFetchUrl)
208208 repo . Network . Remotes . Received ( 1 ) . Add ( Arg . Any < string > ( ) , expectFetchUrl ) ;
209209 }
210210
211- [ TestCase ( "https://github.com/owner/repo" , "https://github.com/owner/repo" , null ) ]
212- [ TestCase ( "https://github.com/fetch/repo" , "https://github.com/origin/repo" , "https://github.com/fetch/repo" ) ]
213- [ TestCase ( "[email protected] :owner/repo" , "[email protected] :owner/repo" , "https://github.com/owner/repo" ) ] 214- public async Task UseOriginWhenPossible ( string fetchUrl , string originUrl , string addUrl = null )
211+ [ TestCase ( "https://github.com/owner/repo" , "origin" , "https://github.com/owner/repo" , null ) ]
212+ [ TestCase ( "https://github.com/fetch/repo" , "origin" , "https://github.com/origin/repo" , "https://github.com/fetch/repo" ) ]
213+ [ TestCase ( "[email protected] :owner/repo" , "origin" , "[email protected] :owner/repo" , "https://github.com/owner/repo" , Description = "Only use http style urls" ) ] 214+ [ TestCase ( "https://github.com/jcansdale/repo" , "jcansdale" , "https://github.com/jcansdale/repo" , null , Description = "Use existing remote" ) ]
215+ [ TestCase ( "https://github.com/jcansdale/repo.git" , "jcansdale" , "https://github.com/jcansdale/repo" , null , Description = "Ignore trailing .git" ) ]
216+ [ TestCase ( "https://github.com/JCANSDALE/REPO" , "jcansdale" , "https://github.com/jcansdale/repo" , null , Description = "Ignore different case" ) ]
217+ public async Task UseExistingRemoteWhenPossible ( string fetchUrl , string remoteName , string remoteUrl , string addUrl = null )
215218 {
216- var remote = Substitute . For < Remote > ( ) ;
217- remote . Url . Returns ( originUrl ) ;
218- var repo = Substitute . For < IRepository > ( ) ;
219- repo . Network . Remotes [ "origin" ] . Returns ( remote ) ;
219+ var repo = CreateRepository ( remoteName , remoteUrl ) ;
220220 var fetchUri = new UriString ( fetchUrl ) ;
221221 var refSpec = "refSpec" ;
222222 var gitClient = CreateGitClient ( ) ;
@@ -232,6 +232,18 @@ public async Task UseOriginWhenPossible(string fetchUrl, string originUrl, strin
232232 repo . Network . Remotes . DidNotReceiveWithAnyArgs ( ) . Add ( null , null ) ;
233233 }
234234 }
235+
236+ static IRepository CreateRepository ( string remoteName , string remoteUrl )
237+ {
238+ var remote = Substitute . For < Remote > ( ) ;
239+ remote . Name . Returns ( remoteName ) ;
240+ remote . Url . Returns ( remoteUrl ) ;
241+ var remotes = new List < Remote > { remote } ;
242+ var repo = Substitute . For < IRepository > ( ) ;
243+ repo . Network . Remotes [ remoteName ] . Returns ( remote ) ;
244+ repo . Network . Remotes . GetEnumerator ( ) . Returns ( _ => remotes . GetEnumerator ( ) ) ;
245+ return repo ;
246+ }
235247 }
236248
237249 public class TheGetPullRequestMergeBaseMethod : TestBaseClass
0 commit comments