adjusting exception message to not rely on credentials

This commit is contained in:
Brendan Forster
2014-04-30 13:25:14 +08:00
parent 68384f778b
commit ac89fe07da
4 changed files with 41 additions and 7 deletions
@@ -0,0 +1,36 @@
using Xunit;
namespace Octokit.Tests.Exceptions
{
public class RepositoryExistsExceptionTests
{
public class TheMessageProperty
{
[Fact]
public void WhenOwnerIsNullDoNotMentionInMessage()
{
var exception = new RepositoryExistsException(
null,
"some-repo",
false,
GitHubClient.GitHubDotComUrl,
new ApiValidationException());
Assert.Equal("There is already a repository named 'some-repo' for the current account.", exception.Message);
}
[Fact]
public void WhenOwnerIsNotNullMentionInMessage()
{
var exception = new RepositoryExistsException(
"some-org",
"some-repo",
true,
GitHubClient.GitHubDotComUrl,
new ApiValidationException());
Assert.Equal("There is already a repository named 'some-repo' in the organization 'some-org'.", exception.Message);
}
}
}
}
+1
View File
@@ -98,6 +98,7 @@
<Compile Include="Clients\FollowersClientTests.cs" />
<Compile Include="Exceptions\ApiExceptionTests.cs" />
<Compile Include="Exceptions\ApiValidationExceptionTests.cs" />
<Compile Include="Exceptions\RepositoryExistsExceptionTests.cs" />
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
<Compile Include="Exceptions\ForbiddenExceptionTests.cs" />
<Compile Include="Exceptions\LoginAttemptsExceededExceptionTests.cs" />
+1 -3
View File
@@ -84,13 +84,11 @@ namespace Octokit
errorMessage,
StringComparison.OrdinalIgnoreCase))
{
string owner = organizationLogin ?? Connection.Credentials.Login;
var baseAddress = Connection.BaseAddress.Host != GitHubClient.GitHubApiUrl.Host
? Connection.BaseAddress
: new Uri("https://github.com/");
throw new RepositoryExistsException(
owner,
organizationLogin,
newRepository.Name,
organizationLogin != null,
baseAddress, e);
@@ -37,11 +37,10 @@ namespace Octokit
ApiValidationException innerException)
: base(innerException)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "repositoryName");
Ensure.ArgumentNotNull(baseAddress, "baseAddress");
Owner = owner;
Owner = owner ?? ""; // TODO: this is a total hack
RepositoryName = name;
OwnerIsOrganization = ownerIsOrganization;
var webBaseAddress = baseAddress.Host != GitHubClient.GitHubApiUrl.Host
@@ -49,8 +48,8 @@ namespace Octokit
: GitHubClient.GitHubDotComUrl;
ExistingRepositoryWebUrl = new Uri(webBaseAddress, new Uri(owner + "/" + name, UriKind.Relative));
string messageFormat = ownerIsOrganization
? "There is already a repository named '{0}' in the organization '{1}'"
: "There is already a repository named '{0}' for the owner '{1}'.";
? "There is already a repository named '{0}' in the organization '{1}'."
: "There is already a repository named '{0}' for the current account.";
_message = String.Format(CultureInfo.InvariantCulture, messageFormat, name, owner);
}