Ensure user agent not empty string

Also added more ctor tests
This commit is contained in:
Haacked
2013-10-04 09:47:28 -07:00
parent ace70b9a4b
commit d79b526d70
2 changed files with 80 additions and 21 deletions
+79 -20
View File
@@ -9,7 +9,6 @@ using NSubstitute;
using Octokit.Http;
using Octokit.Tests.Helpers;
using Xunit;
using Xunit.Extensions;
namespace Octokit.Tests.Http
{
@@ -18,25 +17,6 @@ namespace Octokit.Tests.Http
const string ExampleUrl = "http://example.com";
static readonly Uri ExampleUri = new Uri(ExampleUrl);
public class TheConstructor
{
[Fact]
public void EnsuresAbsoluteBaseAddress()
{
Assert.Throws<ArgumentException>(() => new Connection("Test Runner", new Uri("/foo", UriKind.Relative)));
Assert.Throws<ArgumentException>(() => new Connection("Test Runner", new Uri("/foo", UriKind.RelativeOrAbsolute)));
}
[Fact]
public void CreatesConnectionWithBaseAddress()
{
var connection = new Connection("Test Runner User Agent", new Uri("https://github.com/"));
Assert.Equal(new Uri("https://github.com/"), connection.BaseAddress);
Assert.Equal("Test Runner User Agent", connection.UserAgent);
}
}
public class TheGetAsyncMethod
{
[Fact]
@@ -271,5 +251,84 @@ namespace Octokit.Tests.Http
req.Endpoint == new Uri("/endpoint", UriKind.Relative)));
}
}
public class TheConstructor
{
[Fact]
public void EnsuresAbsoluteBaseAddress()
{
Assert.Throws<ArgumentException>(() => new Connection("Test Runner", new Uri("/foo", UriKind.Relative)));
Assert.Throws<ArgumentException>(() => new Connection("Test Runner", new Uri("/foo", UriKind.RelativeOrAbsolute)));
}
[Fact]
public void EnsuresNonNullArguments()
{
// 1 arg
Assert.Throws<ArgumentNullException>(() => new Connection(null));
Assert.Throws<ArgumentException>(() => new Connection(""));
// 2 args
Assert.Throws<ArgumentNullException>(() => new Connection(null, new Uri("https://example.com")));
Assert.Throws<ArgumentException>(() => new Connection("", new Uri("https://example.com")));
Assert.Throws<ArgumentNullException>(() => new Connection("foo", (Uri)null));
// 3 args
Assert.Throws<ArgumentException>(() => new Connection("",
new Uri("https://example.com"),
Substitute.For<ICredentialStore>()));
Assert.Throws<ArgumentNullException>(() => new Connection(null,
new Uri("https://example.com"),
Substitute.For<ICredentialStore>()));
Assert.Throws<ArgumentNullException>(() => new Connection("foo",
null,
Substitute.For<ICredentialStore>()));
Assert.Throws<ArgumentNullException>(() => new Connection("foo",
new Uri("https://example.com"),
null));
// 5 Args
Assert.Throws<ArgumentException>(() => new Connection(""
, new Uri("https://example.com"),
Substitute.For<ICredentialStore>(),
Substitute.For<IHttpClient>(),
Substitute.For<IJsonSerializer>()));
Assert.Throws<ArgumentNullException>(() => new Connection(null
, new Uri("https://example.com"),
Substitute.For<ICredentialStore>(),
Substitute.For<IHttpClient>(),
Substitute.For<IJsonSerializer>()));
Assert.Throws<ArgumentNullException>(() => new Connection("foo",
new Uri("https://example.com"),
Substitute.For<ICredentialStore>(),
Substitute.For<IHttpClient>(),
null));
Assert.Throws<ArgumentNullException>(() => new Connection("foo",
new Uri("https://example.com"),
Substitute.For<ICredentialStore>(),
null,
Substitute.For<IJsonSerializer>()));
Assert.Throws<ArgumentNullException>(() => new Connection("foo",
new Uri("https://example.com"),
null,
Substitute.For<IHttpClient>(),
Substitute.For<IJsonSerializer>()));
Assert.Throws<ArgumentNullException>(() => new Connection("foo",
null,
Substitute.For<ICredentialStore>(),
Substitute.For<IHttpClient>(),
Substitute.For<IJsonSerializer>()));
}
[Fact]
public void CreatesConnectionWithBaseAddress()
{
var connection = new Connection("Test Runner User Agent", new Uri("https://github.com/"));
Assert.Equal(new Uri("https://github.com/"), connection.BaseAddress);
Assert.Equal("Test Runner User Agent", connection.UserAgent);
}
}
}
}
+1 -1
View File
@@ -44,7 +44,7 @@ namespace Octokit.Http
IHttpClient httpClient,
IJsonSerializer serializer)
{
Ensure.ArgumentNotNull(userAgent, "userAgent");
Ensure.ArgumentNotNullOrEmptyString(userAgent, "userAgent");
Ensure.ArgumentNotNull(baseAddress, "baseAddress");
Ensure.ArgumentNotNull(credentialStore, "credentialStore");
Ensure.ArgumentNotNull(httpClient, "httpClient");