@@ -65,9 +65,10 @@ public async void MergeBaseNotAvailable_ThrowsFileNotFoundException()
6565 var mergeBaseSha = null as string ;
6666 var head = false ;
6767 var expectMessage = $ "Couldn't find merge base between { baseSha } and { headSha } .";
68+ var mergeBaseException = new NotFoundException ( expectMessage ) ;
6869
6970 var ex = await Assert . ThrowsAsync < NotFoundException > ( ( ) => ExtractFile ( baseSha , baseFileContent , headSha , headFileContent , mergeBaseSha , mergeBaseFileContent ,
70- fileName , head , Encoding . UTF8 ) ) ;
71+ fileName , head , Encoding . UTF8 , mergeBaseException : mergeBaseException ) ) ;
7172 Assert . Equal ( expectMessage , ex . Message ) ;
7273 }
7374
@@ -150,7 +151,8 @@ static bool HasPreamble(string file, Encoding encoding)
150151
151152 static async Task < string > ExtractFile (
152153 string baseSha , object baseFileContent , string headSha , object headFileContent , string mergeBaseSha , object mergeBaseFileContent ,
153- string fileName , bool head , Encoding encoding , string repoDir = "repoDir" , int pullNumber = 666 , string baseRef = "baseRef" , string headRef = "headRef" )
154+ string fileName , bool head , Encoding encoding , string repoDir = "repoDir" , int pullNumber = 666 , string baseRef = "baseRef" , string headRef = "headRef" ,
155+ Exception mergeBaseException = null )
154156 {
155157 var repositoryModel = Substitute . For < ILocalRepositoryModel > ( ) ;
156158 repositoryModel . LocalPath . Returns ( repoDir ) ;
@@ -166,7 +168,15 @@ static async Task<string> ExtractFile(
166168 var gitService = serviceProvider . GetGitService ( ) ;
167169 var service = new PullRequestService ( gitClient , gitService , serviceProvider . GetOperatingSystem ( ) , Substitute . For < IUsageTracker > ( ) ) ;
168170
169- gitClient . GetPullRequestMergeBase ( Arg . Any < IRepository > ( ) , Arg . Any < UriString > ( ) , Arg . Any < UriString > ( ) , baseSha , headSha , baseRef , headRef ) . ReturnsForAnyArgs ( Task . FromResult ( mergeBaseSha ) ) ;
171+ if ( mergeBaseException == null )
172+ {
173+ gitClient . GetPullRequestMergeBase ( Arg . Any < IRepository > ( ) , Arg . Any < UriString > ( ) , Arg . Any < UriString > ( ) , baseSha , headSha , baseRef , headRef ) . ReturnsForAnyArgs ( Task . FromResult ( mergeBaseSha ) ) ;
174+ }
175+ else
176+ {
177+ gitClient . GetPullRequestMergeBase ( Arg . Any < IRepository > ( ) , Arg . Any < UriString > ( ) , Arg . Any < UriString > ( ) , baseSha , headSha , baseRef , headRef ) . ReturnsForAnyArgs ( Task . FromException < string > ( mergeBaseException ) ) ;
178+ }
179+
170180 gitClient . ExtractFile ( Arg . Any < IRepository > ( ) , mergeBaseSha , fileName ) . Returns ( GetFileTask ( mergeBaseFileContent ) ) ;
171181 gitClient . ExtractFile ( Arg . Any < IRepository > ( ) , baseSha , fileName ) . Returns ( GetFileTask ( baseFileContent ) ) ;
172182 gitClient . ExtractFile ( Arg . Any < IRepository > ( ) , headSha , fileName ) . Returns ( GetFileTask ( headFileContent ) ) ;
@@ -561,7 +571,7 @@ static IGitService MockGitService()
561571 var branches = MockBranches ( "pr/123-foo1" , "pr/123-foo1-2" ) ;
562572 repository . Branches . Returns ( branches ) ;
563573
564- var result = Substitute . For < IGitService > ( ) ;
574+ var result = Substitute . For < IGitService > ( ) ;
565575 result . GetRepository ( Arg . Any < string > ( ) ) . Returns ( repository ) ;
566576 return result ;
567577 }
0 commit comments