|
17 | 17 |
|
18 | 18 | public class PullRequestServiceTests : TestBaseClass |
19 | 19 | { |
| 20 | + public class TheIsWorkingDirectoryCleanMethod |
| 21 | + { |
| 22 | + [Fact] |
| 23 | + public async Task NewRepo_IsWorkingDirectoryClean_True() |
| 24 | + { |
| 25 | + using (var tempDir = new TempDirectory()) |
| 26 | + using (var repo = CreateRepository(tempDir)) |
| 27 | + { |
| 28 | + var service = CreatePullRequestService(repo); |
| 29 | + var repositoryModel = CreateLocalRepositoryModel(repo); |
| 30 | + |
| 31 | + var isClean = await service.IsWorkingDirectoryClean(repositoryModel).FirstAsync(); |
| 32 | + |
| 33 | + Assert.True(isClean); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public async Task UntrackedFile_IsWorkingDirectoryClean_True() |
| 39 | + { |
| 40 | + using (var tempDir = new TempDirectory()) |
| 41 | + using (var repo = CreateRepository(tempDir)) |
| 42 | + { |
| 43 | + var service = CreatePullRequestService(repo); |
| 44 | + var repositoryModel = CreateLocalRepositoryModel(repo); |
| 45 | + var file = Path.Combine(repo.Info.WorkingDirectory, "untracked.txt"); |
| 46 | + File.WriteAllText(file, "contents"); |
| 47 | + |
| 48 | + var isClean = await service.IsWorkingDirectoryClean(repositoryModel).FirstAsync(); |
| 49 | + |
| 50 | + Assert.True(isClean); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + [Fact] |
| 55 | + public async Task StagedFile_IsWorkingDirectoryClean_False() |
| 56 | + { |
| 57 | + using (var tempDir = new TempDirectory()) |
| 58 | + using (var repo = CreateRepository(tempDir)) |
| 59 | + { |
| 60 | + var service = CreatePullRequestService(repo); |
| 61 | + var repositoryModel = CreateLocalRepositoryModel(repo); |
| 62 | + var file = Path.Combine(repo.Info.WorkingDirectory, "modified.txt"); |
| 63 | + File.WriteAllText(file, "contents"); |
| 64 | + Commands.Stage(repo, file); |
| 65 | + |
| 66 | + var isClean = await service.IsWorkingDirectoryClean(repositoryModel).FirstAsync(); |
| 67 | + |
| 68 | + Assert.False(isClean); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + [Fact] |
| 73 | + public async Task CommittedFile_IsWorkingDirectoryClean_True() |
| 74 | + { |
| 75 | + using (var tempDir = new TempDirectory()) |
| 76 | + using (var repo = CreateRepository(tempDir)) |
| 77 | + { |
| 78 | + var service = CreatePullRequestService(repo); |
| 79 | + var repositoryModel = CreateLocalRepositoryModel(repo); |
| 80 | + var file = Path.Combine(repo.Info.WorkingDirectory, "modified.txt"); |
| 81 | + File.WriteAllText(file, "contents"); |
| 82 | + Commands.Stage(repo, file); |
| 83 | + var author = new Signature("foo", "[email protected]", DateTimeOffset.Now); |
| 84 | + repo.Commit("foo", author, author); |
| 85 | + |
| 86 | + var isClean = await service.IsWorkingDirectoryClean(repositoryModel).FirstAsync(); |
| 87 | + |
| 88 | + Assert.True(isClean); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + static Repository CreateRepository(TempDirectory tempDirectory) |
| 93 | + { |
| 94 | + var repoDir = tempDirectory.Directory.FullName; |
| 95 | + return new Repository(Repository.Init(repoDir)); |
| 96 | + } |
| 97 | + |
| 98 | + static IPullRequestService CreatePullRequestService(Repository repo) |
| 99 | + { |
| 100 | + var repoDir = repo.Info.WorkingDirectory; |
| 101 | + var serviceProvider = Substitutes.ServiceProvider; |
| 102 | + var gitService = serviceProvider.GetGitService(); |
| 103 | + gitService.GetRepository(repoDir).Returns(repo); |
| 104 | + var service = new PullRequestService(Substitute.For<IGitClient>(), gitService, serviceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>()); |
| 105 | + return service; |
| 106 | + } |
| 107 | + |
| 108 | + static ILocalRepositoryModel CreateLocalRepositoryModel(Repository repo) |
| 109 | + { |
| 110 | + var repoDir = repo.Info.WorkingDirectory; |
| 111 | + var repositoryModel = Substitute.For<ILocalRepositoryModel>(); |
| 112 | + repositoryModel.LocalPath.Returns(repoDir); |
| 113 | + return repositoryModel; |
| 114 | + } |
| 115 | + |
| 116 | + } |
| 117 | + |
20 | 118 | public class TheExtractFileMethod |
21 | 119 | { |
22 | 120 | [Fact] |
|
0 commit comments