add some argumentnull and exception handling

This commit is contained in:
Tommy Parnell
2015-04-21 20:29:33 -04:00
parent 44d2c4db2c
commit f63579884e
3 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using Untappd.Net.Authentication;
using Untappd.Net.Client;
namespace Untappd.Net.UnitTests.Authentication
{
[TestFixture]
public class TestAuthenticationHelper
{
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestRedirectUserToException1()
{
AuthenticationHelper.RedirectUserTo(null, "url");
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestRedirectUserToException2()
{
AuthenticationHelper.RedirectUserTo(new UnAuthenticatedUntappdCredentials("d", "d"), string.Empty);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestTokenUrlException1()
{
AuthenticationHelper.TokenUrl(null, "some", "code");
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestTokenUrlException2()
{
AuthenticationHelper.TokenUrl(new UnAuthenticatedUntappdCredentials("d", "d"), string.Empty, "code");
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestTokenUrlException3()
{
AuthenticationHelper.TokenUrl(new UnAuthenticatedUntappdCredentials("d", "d"), "ds", string.Empty);
}
}
}

View File

@@ -69,6 +69,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Authentication\TestAuthenticationHelper.cs" />
<Compile Include="Class1.cs" />
<Compile Include="Client\TestAuthenticatedUntappdCredentials.cs" />
<Compile Include="Client\TestUnAuthenticatedUntappdCredentials.cs" />

View File

@@ -18,6 +18,16 @@ namespace Untappd.Net.Authentication
/// <returns></returns>
public static string RedirectUserTo(IUnAuthenticadedUntappdCredentials credentials, string redirectUrl)
{
if (credentials == null)
{
throw new ArgumentNullException("credentials");
}
if (string.IsNullOrWhiteSpace(redirectUrl))
{
throw new ArgumentNullException("redirectUrl");
}
return string.Format("{0}/?client_id={1}&response_type=code&redirect_url={2}", Constants.BaseRequestString,
credentials.ClientId, redirectUrl);
}
@@ -31,6 +41,19 @@ namespace Untappd.Net.Authentication
/// <returns></returns>
public static string TokenUrl(IUnAuthenticadedUntappdCredentials credentials, string redirectUrl, string code)
{
if (credentials == null)
{
throw new ArgumentNullException("credentials");
}
if (string.IsNullOrWhiteSpace(redirectUrl))
{
throw new ArgumentNullException("redirectUrl");
}
if (string.IsNullOrWhiteSpace(code))
{
throw new ArgumentNullException("code");
}
return string.Format("{0}/?client_id={1}&client_secret={2}&response_type=code&redirect_url={3}&code={4}",
Constants.OAuthTokenEndPoint,
credentials.ClientId,