|
11 | 11 |
|
12 | 12 | public class GitClientTests |
13 | 13 | { |
| 14 | + public class TheIsModifiedMethod |
| 15 | + { |
| 16 | + [Theory] |
| 17 | + [InlineData(FileStatus.Unaltered, false)] |
| 18 | + [InlineData(FileStatus.ModifiedInIndex, true)] |
| 19 | + [InlineData(FileStatus.ModifiedInWorkdir, true)] |
| 20 | + public async Task RetrieveStatus(FileStatus fileStatus, bool expect) |
| 21 | + { |
| 22 | + var path = "path"; |
| 23 | + var repo = Substitute.For<IRepository>(); |
| 24 | + repo.RetrieveStatus(path).Returns(fileStatus); |
| 25 | + repo.Head.Returns(Substitute.For<Branch>()); |
| 26 | + var treeEntry = null as TreeEntry; |
| 27 | + repo.Head[path].Returns(treeEntry); |
| 28 | + var gitClient = new GitClient(Substitute.For<IGitHubCredentialProvider>()); |
| 29 | + |
| 30 | + var modified = await gitClient.IsModified(repo, path, null); |
| 31 | + |
| 32 | + Assert.Equal(expect, modified); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public async Task TreeEntry_Null_False() |
| 37 | + { |
| 38 | + var path = "path"; |
| 39 | + var repo = Substitute.For<IRepository>(); |
| 40 | + repo.RetrieveStatus(path).Returns(FileStatus.Unaltered); |
| 41 | + repo.Head.Returns(Substitute.For<Branch>()); |
| 42 | + var treeEntry = null as TreeEntry; |
| 43 | + repo.Head[path].Returns(treeEntry); |
| 44 | + var gitClient = new GitClient(Substitute.For<IGitHubCredentialProvider>()); |
| 45 | + |
| 46 | + var modified = await gitClient.IsModified(repo, path, null); |
| 47 | + |
| 48 | + Assert.False(modified); |
| 49 | + } |
| 50 | + |
| 51 | + [Fact] |
| 52 | + public async Task TreeEntryTarget_GitLink_False() |
| 53 | + { |
| 54 | + var path = "path"; |
| 55 | + var repo = Substitute.For<IRepository>(); |
| 56 | + repo.RetrieveStatus(path).Returns(FileStatus.Unaltered); |
| 57 | + repo.Head.Returns(Substitute.For<Branch>()); |
| 58 | + var treeEntry = Substitute.For<TreeEntry>(); |
| 59 | + treeEntry.TargetType.Returns(TreeEntryTargetType.GitLink); |
| 60 | + treeEntry.Target.Returns(Substitute.For<GitLink>()); |
| 61 | + repo.Head[path].Returns(treeEntry); |
| 62 | + var gitClient = new GitClient(Substitute.For<IGitHubCredentialProvider>()); |
| 63 | + |
| 64 | + var modified = await gitClient.IsModified(repo, path, null); |
| 65 | + |
| 66 | + Assert.False(modified); |
| 67 | + } |
| 68 | + |
| 69 | + [Theory] |
| 70 | + [InlineData(0, 0, false)] |
| 71 | + [InlineData(1, 0, true)] |
| 72 | + [InlineData(0, 1, true)] |
| 73 | + [InlineData(1, 1, true)] |
| 74 | + public async Task ContentChanges(int linesAdded, int linesDeleted, bool expected) |
| 75 | + { |
| 76 | + var path = "path"; |
| 77 | + var repo = Substitute.For<IRepository>(); |
| 78 | + repo.RetrieveStatus(path).Returns(FileStatus.Unaltered); |
| 79 | + repo.Head.Returns(Substitute.For<Branch>()); |
| 80 | + var treeEntry = Substitute.For<TreeEntry>(); |
| 81 | + treeEntry.TargetType.Returns(TreeEntryTargetType.Blob); |
| 82 | + treeEntry.Target.Returns(Substitute.For<Blob>()); |
| 83 | + repo.Head[path].Returns(treeEntry); |
| 84 | + var changes = Substitute.For<ContentChanges>(); |
| 85 | + changes.LinesAdded.Returns(linesAdded); |
| 86 | + changes.LinesDeleted.Returns(linesDeleted); |
| 87 | + repo.Diff.Compare(null, null).ReturnsForAnyArgs(changes); |
| 88 | + var gitClient = new GitClient(Substitute.For<IGitHubCredentialProvider>()); |
| 89 | + |
| 90 | + var modified = await gitClient.IsModified(repo, path, null); |
| 91 | + |
| 92 | + Assert.Equal(expected, modified); |
| 93 | + } |
| 94 | + } |
| 95 | + |
14 | 96 | public class TheIsHeadPushedMethod : TestBaseClass |
15 | 97 | { |
16 | 98 | [Theory] |
|
0 commit comments