|
| 1 | +namespace Cake.Issues.Reporting.Generic.Tests |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using Cake.Issues.Testing; |
| 5 | + using Shouldly; |
| 6 | + using Xunit; |
| 7 | + |
| 8 | + public sealed class FileLinkSettingsTests |
| 9 | + { |
| 10 | + public sealed class TheGitHubMethod |
| 11 | + { |
| 12 | + [Fact] |
| 13 | + public void Should_Throw_If_RepositoryUrl_Is_Null() |
| 14 | + { |
| 15 | + // Given |
| 16 | + Uri repositoryUrl = null; |
| 17 | + var branch = "master"; |
| 18 | + var rootPath = string.Empty; |
| 19 | + |
| 20 | + // When |
| 21 | + var result = Record.Exception(() => |
| 22 | + FileLinkSettings.GitHub(repositoryUrl, branch, rootPath)); |
| 23 | + |
| 24 | + // Then |
| 25 | + result.IsArgumentNullException("repositoryUrl"); |
| 26 | + } |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public void Should_Throw_If_Branch_Is_Null() |
| 30 | + { |
| 31 | + // Given |
| 32 | + var repositoryUrl = new Uri("https://github.com/cake-contrib/Cake.Issues.Website"); |
| 33 | + string branch = null; |
| 34 | + var rootPath = string.Empty; |
| 35 | + |
| 36 | + // When |
| 37 | + var result = Record.Exception(() => |
| 38 | + FileLinkSettings.GitHub(repositoryUrl, branch, rootPath)); |
| 39 | + |
| 40 | + // Then |
| 41 | + result.IsArgumentNullException("branch"); |
| 42 | + } |
| 43 | + |
| 44 | + [Fact] |
| 45 | + public void Should_Throw_If_Branch_Is_Empty() |
| 46 | + { |
| 47 | + // Given |
| 48 | + var repositoryUrl = new Uri("https://github.com/cake-contrib/Cake.Issues.Website"); |
| 49 | + var branch = string.Empty; |
| 50 | + var rootPath = string.Empty; |
| 51 | + |
| 52 | + // When |
| 53 | + var result = Record.Exception(() => |
| 54 | + FileLinkSettings.GitHub(repositoryUrl, branch, rootPath)); |
| 55 | + |
| 56 | + // Then |
| 57 | + result.IsArgumentOutOfRangeException("branch"); |
| 58 | + } |
| 59 | + |
| 60 | + [Fact] |
| 61 | + public void Should_Throw_If_Branch_Is_Whitespace() |
| 62 | + { |
| 63 | + // Given |
| 64 | + var repositoryUrl = new Uri("https://github.com/cake-contrib/Cake.Issues.Website"); |
| 65 | + var branch = " "; |
| 66 | + var rootPath = string.Empty; |
| 67 | + |
| 68 | + // When |
| 69 | + var result = Record.Exception(() => |
| 70 | + FileLinkSettings.GitHub(repositoryUrl, branch, rootPath)); |
| 71 | + |
| 72 | + // Then |
| 73 | + result.IsArgumentOutOfRangeException("branch"); |
| 74 | + } |
| 75 | + |
| 76 | + [Theory] |
| 77 | + [InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", null, "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/{FilePath}#L{Line}")] |
| 78 | + [InlineData("https://github.com/cake-contrib/Cake.Issues.Website/", "master", null, "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/{FilePath}#L{Line}")] |
| 79 | + [InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "foo", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/{FilePath}#L{Line}")] |
| 80 | + [InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "/foo", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/{FilePath}#L{Line}")] |
| 81 | + [InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "foo/", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/{FilePath}#L{Line}")] |
| 82 | + [InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "foo/bar", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/bar/{FilePath}#L{Line}")] |
| 83 | + public void Should_Set_Correct_FileLinkPattern(string repositoryUrl, string branch, string rootPath, string expectedPattern) |
| 84 | + { |
| 85 | + // Given |
| 86 | + |
| 87 | + // When |
| 88 | + var result = FileLinkSettings.GitHub(new Uri(repositoryUrl), branch, rootPath); |
| 89 | + |
| 90 | + // Then |
| 91 | + result.FileLinkPattern.ShouldBe(expectedPattern); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + public sealed class TheTeamFoundationServerMethod |
| 96 | + { |
| 97 | + [Fact] |
| 98 | + public void Should_Throw_If_RepositoryUrl_Is_Null() |
| 99 | + { |
| 100 | + // Given |
| 101 | + Uri repositoryUrl = null; |
| 102 | + var branch = "master"; |
| 103 | + var rootPath = string.Empty; |
| 104 | + |
| 105 | + // When |
| 106 | + var result = Record.Exception(() => |
| 107 | + FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath)); |
| 108 | + |
| 109 | + // Then |
| 110 | + result.IsArgumentNullException("repositoryUrl"); |
| 111 | + } |
| 112 | + |
| 113 | + [Fact] |
| 114 | + public void Should_Throw_If_Branch_Is_Null() |
| 115 | + { |
| 116 | + // Given |
| 117 | + var repositoryUrl = new Uri("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository"); |
| 118 | + string branch = null; |
| 119 | + var rootPath = string.Empty; |
| 120 | + |
| 121 | + // When |
| 122 | + var result = Record.Exception(() => |
| 123 | + FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath)); |
| 124 | + |
| 125 | + // Then |
| 126 | + result.IsArgumentNullException("branch"); |
| 127 | + } |
| 128 | + |
| 129 | + [Fact] |
| 130 | + public void Should_Throw_If_Branch_Is_Empty() |
| 131 | + { |
| 132 | + // Given |
| 133 | + var repositoryUrl = new Uri("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository"); |
| 134 | + var branch = string.Empty; |
| 135 | + var rootPath = string.Empty; |
| 136 | + |
| 137 | + // When |
| 138 | + var result = Record.Exception(() => |
| 139 | + FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath)); |
| 140 | + |
| 141 | + // Then |
| 142 | + result.IsArgumentOutOfRangeException("branch"); |
| 143 | + } |
| 144 | + |
| 145 | + [Fact] |
| 146 | + public void Should_Throw_If_Branch_Is_Whitespace() |
| 147 | + { |
| 148 | + // Given |
| 149 | + var repositoryUrl = new Uri("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository"); |
| 150 | + var branch = " "; |
| 151 | + var rootPath = string.Empty; |
| 152 | + |
| 153 | + // When |
| 154 | + var result = Record.Exception(() => |
| 155 | + FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath)); |
| 156 | + |
| 157 | + // Then |
| 158 | + result.IsArgumentOutOfRangeException("branch"); |
| 159 | + } |
| 160 | + |
| 161 | + [Theory] |
| 162 | + [InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", null, "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path={FilePath}&version=GBmaster&line={Line}")] |
| 163 | + [InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository/", "master", null, "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path={FilePath}&version=GBmaster&line={Line}")] |
| 164 | + [InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "foo", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/{FilePath}&version=GBmaster&line={Line}")] |
| 165 | + [InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "/foo", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/{FilePath}&version=GBmaster&line={Line}")] |
| 166 | + [InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "foo/", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/{FilePath}&version=GBmaster&line={Line}")] |
| 167 | + [InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "foo/bar", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/bar/{FilePath}&version=GBmaster&line={Line}")] |
| 168 | + public void Should_Set_Correct_FileLinkPattern(string repositoryUrl, string branch, string rootPath, string expectedPattern) |
| 169 | + { |
| 170 | + // Given |
| 171 | + |
| 172 | + // When |
| 173 | + var result = FileLinkSettings.TeamFoundationServer(new Uri(repositoryUrl), branch, rootPath); |
| 174 | + |
| 175 | + // Then |
| 176 | + result.FileLinkPattern.ShouldBe(expectedPattern); |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | +} |
0 commit comments