|
7 | 7 |
|
8 | 8 | public class GitServiceIntegrationTests |
9 | 9 | { |
10 | | - public class TheCreateLocalRepositoryModelMethod : TestBaseClass |
| 10 | + public class TheCreateLocalRepositoryModelMethod |
11 | 11 | { |
12 | | - [TestCase(true)] |
13 | | - [TestCase(false)] |
14 | | - public void NoRepository_Same_As_Repository_With_No_CloneUrl(bool createRepository) |
| 12 | + [Test] |
| 13 | + public void Empty_Repository() |
15 | 14 | { |
16 | | - using (var temp = new TempDirectory()) |
| 15 | + using (var temp = new TempRepository()) |
17 | 16 | { |
18 | 17 | var path = temp.Directory.FullName; |
19 | | - if (createRepository) |
| 18 | + var target = new GitService(new RepositoryFacade()); |
| 19 | + |
| 20 | + var model = target.CreateLocalRepositoryModel(path); |
| 21 | + |
| 22 | + Assert.That(model, Is.Not.Null); |
| 23 | + Assert.That(model.LocalPath, Is.EqualTo(path)); |
| 24 | + Assert.That(model.Name, Is.EqualTo(temp.Directory.Name)); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + [TestCase("origin", "https://github.com/github/VisualStudio", false)] |
| 29 | + [TestCase("not_origin", "https://github.com/github/VisualStudio", true)] |
| 30 | + [TestCase(null, null, false, Description = "Has no remotes")] |
| 31 | + public void Check_HasNoRemoteOrigin(string remoteName, string remoteUrl, bool hasNoRemoteOrigin) |
| 32 | + { |
| 33 | + using (var temp = new TempRepository()) |
| 34 | + { |
| 35 | + if (remoteName != null) |
20 | 36 | { |
21 | | - using (var repo = new Repository(Repository.Init(path))) { } |
| 37 | + temp.Repository.Network.Remotes.Add(remoteName, remoteUrl); |
22 | 38 | } |
| 39 | + var path = temp.Directory.FullName; |
| 40 | + var target = new GitService(new RepositoryFacade()); |
| 41 | + |
| 42 | + var model = target.CreateLocalRepositoryModel(path); |
| 43 | + |
| 44 | + Assert.That(model.HasNoRemoteOrigin, Is.EqualTo(hasNoRemoteOrigin)); |
| 45 | + } |
| 46 | + } |
23 | 47 |
|
| 48 | + [Test] |
| 49 | + public void NoRepository_Same_As_Repository_With_No_CloneUrl() |
| 50 | + { |
| 51 | + using (var temp = new TempDirectory()) |
| 52 | + { |
| 53 | + var path = temp.Directory.FullName; |
24 | 54 | var target = new GitService(new RepositoryFacade()); |
25 | 55 |
|
26 | 56 | var model = target.CreateLocalRepositoryModel(path); |
@@ -234,4 +264,57 @@ static void AddTrackedBranch(Repository repo, Branch branch, Commit commit, |
234 | 264 | repo.Branches.Update(branch, b => b.TrackedBranch = canonicalName); |
235 | 265 | } |
236 | 266 | } |
| 267 | + |
| 268 | + protected class TempRepository : TempDirectory |
| 269 | + { |
| 270 | + public TempRepository() |
| 271 | + : base() |
| 272 | + { |
| 273 | + Repository = CreateRepository(Directory.FullName); |
| 274 | + } |
| 275 | + |
| 276 | + static Repository CreateRepository(string path) |
| 277 | + { |
| 278 | + return new Repository(Repository.Init(path)); |
| 279 | + } |
| 280 | + |
| 281 | + public Repository Repository |
| 282 | + { |
| 283 | + get; |
| 284 | + } |
| 285 | + } |
| 286 | + |
| 287 | + protected class TempDirectory : IDisposable |
| 288 | + { |
| 289 | + public TempDirectory() |
| 290 | + { |
| 291 | + var f = Path.GetTempFileName(); |
| 292 | + var name = Path.GetFileNameWithoutExtension(f); |
| 293 | + File.Delete(f); |
| 294 | + Directory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), name)); |
| 295 | + Directory.Create(); |
| 296 | + } |
| 297 | + |
| 298 | + public DirectoryInfo Directory { get; } |
| 299 | + |
| 300 | + public void Dispose() |
| 301 | + { |
| 302 | + // Remove any read-only attributes |
| 303 | + SetFileAttributes(Directory, FileAttributes.Normal); |
| 304 | + Directory.Delete(true); |
| 305 | + } |
| 306 | + |
| 307 | + static void SetFileAttributes(DirectoryInfo dir, FileAttributes attributes) |
| 308 | + { |
| 309 | + foreach (DirectoryInfo subdir in dir.GetDirectories()) |
| 310 | + { |
| 311 | + SetFileAttributes(subdir, attributes); |
| 312 | + } |
| 313 | + |
| 314 | + foreach (var file in dir.GetFiles()) |
| 315 | + { |
| 316 | + File.SetAttributes(file.FullName, attributes); |
| 317 | + } |
| 318 | + } |
| 319 | + } |
237 | 320 | } |
0 commit comments