1010using NUnit . Framework ;
1111using NSubstitute ;
1212using Microsoft . VisualStudio . TeamFoundation . Git . Extensibility ;
13- using Microsoft . VisualStudio . Shell ;
1413using Microsoft . VisualStudio . Threading ;
1514using Task = System . Threading . Tasks . Task ;
1615using static Microsoft . VisualStudio . VSConstants ;
16+ using GitHub . Primitives ;
17+ using LibGit2Sharp ;
18+ using System . Threading . Tasks ;
1719
1820public class VSGitExtTests
1921{
@@ -149,41 +151,41 @@ public void RepositoryOpenContextNotActive_IsEmpty()
149151 public void RepositoryOpenIsActive_InitializeWithActiveRepositories ( )
150152 {
151153 var repoPath = "repoPath" ;
152- var repoFactory = Substitute . For < ILocalRepositoryModelFactory > ( ) ;
154+ var gitService = Substitute . For < IGitService > ( ) ;
153155 var context = CreateVSUIContext ( true ) ;
154156 var gitExt = CreateGitExt ( new [ ] { repoPath } ) ;
155- var target = CreateVSGitExt ( context , gitExt , repoFactory : repoFactory ) ;
157+ var target = CreateVSGitExt ( context , gitExt , gitService : gitService ) ;
156158 target . JoinTillEmpty ( ) ;
157159
158160 var activeRepositories = target . ActiveRepositories ;
159161
160162 Assert . That ( activeRepositories . Count , Is . EqualTo ( 1 ) ) ;
161- repoFactory . Received ( 1 ) . Create ( repoPath ) ;
163+ gitService . Received ( 1 ) . CreateLocalRepositoryModel ( repoPath ) ;
162164 }
163165
164166 [ Test ]
165167 public void ExceptionRefreshingRepositories_ReturnsEmptyList ( )
166168 {
167169 var repoPath = "repoPath" ;
168- var repoFactory = Substitute . For < ILocalRepositoryModelFactory > ( ) ;
169- repoFactory . Create ( repoPath ) . ReturnsForAnyArgs ( x => { throw new Exception ( "Boom!" ) ; } ) ;
170+ var gitService = Substitute . For < IGitService > ( ) ;
171+ gitService . CreateLocalRepositoryModel ( repoPath ) . ReturnsForAnyArgs ( x => { throw new Exception ( "Boom!" ) ; } ) ;
170172 var context = CreateVSUIContext ( true ) ;
171173 var gitExt = CreateGitExt ( new [ ] { repoPath } ) ;
172- var target = CreateVSGitExt ( context , gitExt , repoFactory : repoFactory ) ;
174+ var target = CreateVSGitExt ( context , gitExt , gitService : gitService ) ;
173175 target . JoinTillEmpty ( ) ;
174176
175177 var activeRepositories = target . ActiveRepositories ;
176178
177- repoFactory . Received ( 1 ) . Create ( repoPath ) ;
179+ gitService . Received ( 1 ) . CreateLocalRepositoryModel ( repoPath ) ;
178180 Assert . That ( activeRepositories . Count , Is . EqualTo ( 0 ) ) ;
179181 }
180182
181183 [ Test ]
182184 public async Task ActiveRepositoriesChangedOrderingShouldBeCorrectAcrossThreads ( )
183185 {
184186 var gitExt = new MockGitExt ( ) ;
185- var repoFactory = new MockRepositoryFactory ( ) ;
186- var target = CreateVSGitExt ( gitExt : gitExt , repoFactory : repoFactory ) ;
187+ var gitService = new MockGitService ( ) ;
188+ var target = CreateVSGitExt ( gitExt : gitExt , gitService : gitService ) ;
187189 var activeRepositories1 = CreateActiveRepositories ( "repo1" ) ;
188190 var activeRepositories2 = CreateActiveRepositories ( "repo2" ) ;
189191 var task1 = Task . Run ( ( ) => gitExt . ActiveRepositories = activeRepositories1 ) ;
@@ -211,18 +213,18 @@ static IReadOnlyList<IGitRepositoryInfo> CreateActiveRepositories(params string[
211213 }
212214
213215 static VSGitExt CreateVSGitExt ( IVSUIContext context = null , IGitExt gitExt = null , IServiceProvider sp = null ,
214- ILocalRepositoryModelFactory repoFactory = null , JoinableTaskContext joinableTaskContext = null , string contextGuidString = null )
216+ IGitService gitService = null , JoinableTaskContext joinableTaskContext = null , string contextGuidString = null )
215217 {
216218 context = context ?? CreateVSUIContext ( true ) ;
217219 gitExt = gitExt ?? CreateGitExt ( ) ;
218220 var contextGuid = new Guid ( contextGuidString ?? Guids . GitSccProviderId ) ;
219221 sp = sp ?? Substitute . For < IServiceProvider > ( ) ;
220- repoFactory = repoFactory ?? Substitute . For < ILocalRepositoryModelFactory > ( ) ;
222+ gitService = gitService ?? Substitute . For < IGitService > ( ) ;
221223 joinableTaskContext = joinableTaskContext ?? new JoinableTaskContext ( ) ;
222224 var factory = Substitute . For < IVSUIContextFactory > ( ) ;
223225 factory . GetUIContext ( contextGuid ) . Returns ( context ) ;
224226 sp . GetService ( typeof ( IGitExt ) ) . Returns ( gitExt ) ;
225- var vsGitExt = new VSGitExt ( sp , factory , repoFactory , joinableTaskContext ) ;
227+ var vsGitExt = new VSGitExt ( sp , factory , gitService , joinableTaskContext ) ;
226228 vsGitExt . JoinTillEmpty ( ) ;
227229 return vsGitExt ;
228230 }
@@ -291,9 +293,9 @@ public IReadOnlyList<IGitRepositoryInfo> ActiveRepositories
291293 public event PropertyChangedEventHandler PropertyChanged ;
292294 }
293295
294- class MockRepositoryFactory : ILocalRepositoryModelFactory
296+ class MockGitService : IGitService
295297 {
296- public ILocalRepositoryModel Create ( string localPath )
298+ public ILocalRepositoryModel CreateLocalRepositoryModel ( string localPath )
297299 {
298300 var result = Substitute . For < ILocalRepositoryModel > ( ) ;
299301 result . LocalPath . Returns ( localPath ) ;
@@ -308,5 +310,13 @@ public ILocalRepositoryModel Create(string localPath)
308310
309311 return result ;
310312 }
313+
314+ public IBranch CreateCurrentBranchModel ( ILocalRepositoryModel model ) => throw new NotImplementedException ( ) ;
315+ public Task < string > GetLatestPushedSha ( string path , string remote = "origin" ) => throw new NotImplementedException ( ) ;
316+ public UriString GetRemoteUri ( IRepository repo , string remote = "origin" ) => throw new NotImplementedException ( ) ;
317+ public IRepository GetRepository ( string path ) => throw new NotImplementedException ( ) ;
318+ public UriString GetUri ( IRepository repository , string remote = "origin" ) => throw new NotImplementedException ( ) ;
319+ public UriString GetUri ( string path , string remote = "origin" ) => throw new NotImplementedException ( ) ;
320+ public void Refresh ( ILocalRepositoryModel localRepositoryModel ) => throw new NotImplementedException ( ) ;
311321 }
312322}
0 commit comments