This commit is contained in:
rodkings
2015-04-21 13:05:31 -06:00
34 changed files with 278 additions and 154 deletions

View File

@@ -1,8 +1,8 @@
using System;
using NUnit.Framework;
using Untappd.Client.Net;
using Untappd.Net.Client;
using Untappd.Net.Request;
using Untappd.Net.Responses.UserDistinctBeer;
using Untappd.Net.Responses.UserInfo;
namespace Untappd.Net.UnitTests
{
@@ -13,8 +13,9 @@ namespace Untappd.Net.UnitTests
[Ignore]
public void Test()
{
var ts = new UnAuthenticatedUntappdCredentials("clientid", "clientkey");
var t = new Repository().Get<UserDistinctBeers>(ts, "tparnell");
var ts = new UnAuthenticatedUntappdCredentials("id", "scrt");
var t = new Repository().Get<UserInfo>(ts, "tparnell");
Console.WriteLine(t);
}
}

View File

@@ -0,0 +1,27 @@
using System;
using NUnit.Framework;
using Untappd.Net.Client;
namespace Untappd.Net.UnitTests.Client
{
[TestFixture]
public class TestAuthenticatedUntappdCredentials
{
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExpectException()
{
var t = new AuthenticatedUntappdCredentials(null, "d", "d");
}
[Test]
public void ExpectValid()
{
var token = "awesome";
var t = new AuthenticatedUntappdCredentials(token, "d", "d");
Assert.AreEqual(token, "awesome");
token = "newString";
//Make sure the reference is not copied over
Assert.AreEqual("awesome", t.AccessToken);
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using NUnit.Framework;
using Untappd.Net.Client;
namespace Untappd.Net.UnitTests.Client
{
[TestFixture]
public class TestUnAuthenticatedUntappdCredentials
{
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExpectClientIdException()
{
var t = new UnAuthenticatedUntappdCredentials(string.Empty, "t");
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExpectClientSecretException()
{
var t = new UnAuthenticatedUntappdCredentials("t", string.Empty);
}
}
}

View File

@@ -0,0 +1,28 @@
using NUnit.Framework;
using Untappd.Net.Exception;
namespace Untappd.Net.UnitTests.Exception
{
[TestFixture]
public class TestBaseUntappdException
{
[ExpectedException(typeof (BaseUntappdException))]
[Test]
public void TestStandardException()
{
throw new BaseUntappdException();
}
[ExpectedException(typeof(BaseUntappdException), ExpectedMessage = "messageHere")]
[Test]
public void TestStandardExceptionWithMessage()
{
throw new BaseUntappdException("messageHere");
}
[ExpectedException(typeof(BaseUntappdException), ExpectedMessage = "messageHere")]
[Test]
public void TestStandardExceptionWithInner()
{
throw new BaseUntappdException("messageHere", new System.Exception("innerException!"));
}
}
}

View File

@@ -0,0 +1,17 @@
using NUnit.Framework;
using Untappd.Net.Exception;
namespace Untappd.Net.UnitTests.Exception
{
[TestFixture]
public class TestEndpointConfigurationException
{
[Test]
[ExpectedException(typeof(EndpointConfigurationException), ExpectedMessage = "Invalid endpoint configured")]
public void TestThrownExeption()
{
throw new EndpointConfigurationException();
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following

View File

@@ -0,0 +1,49 @@
using System.Collections.Generic;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using RestSharp;
using Untappd.Net.Client;
using Untappd.Net.Request;
using Untappd.Net.Responses.BeerInfo;
namespace Untappd.Net.UnitTests.Request
{
[TestFixture]
public class TestRepository
{
[Test]
public void ConfirmRequestWorks()
{
var mockCreds = new Mock<IUntappdCredentials>();
mockCreds.Setup(a => a.ClientId).Returns("id");
mockCreds.Setup(a => a.ClientSecret).Returns("secret");
var bodyParam = new Dictionary<string, string> {{"key", "value"}};
var client = new Mock<IRestClient>();
var request = new Mock<IRestRequest>();
request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
request.Setup(a => a.AddParameter(It.IsAny<string>(), It.IsAny<string>()));
var response = new Mock<IRestResponse>();
var obj = JsonConvert.SerializeObject(new BeerInfo());
response.Setup(a => a.Content).Returns(obj);
client.Setup(a => a.Execute(It.IsAny<IRestRequest>())).Callback(() =>
{
}).Returns(response.Object);
var repository = new Repository(client.Object, request.Object);
repository.Get<BeerInfo>(mockCreds.Object, "awesome", bodyParam);
request.Verify(a => a.AddParameter("client_id", mockCreds.Object.ClientId));
request.Verify(a => a.AddParameter("client_secret", mockCreds.Object.ClientSecret));
request.Verify(a => a.AddParameter("key", "value"));
}
[Test]
public void ConfirmBasicConstructorWorks()
{
var constructorTest = new Repository();
Assert.IsTrue(constructorTest.Client != null);
Assert.IsTrue(constructorTest.Request != null);
}
}
}

View File

@@ -30,6 +30,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq">
<HintPath>..\..\packages\Moq.4.2.1502.0911\lib\net40\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.core">
<HintPath>..\..\packages\NUnitTestAdapter.1.2\lib\nunit.core.dll</HintPath>
<Private>False</Private>
@@ -49,6 +56,10 @@
<HintPath>..\..\packages\NUnitTestAdapter.1.2\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RestSharp, Version=105.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -59,7 +70,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Client\TestAuthenticatedUntappdCredentials.cs" />
<Compile Include="Client\TestUnAuthenticatedUntappdCredentials.cs" />
<Compile Include="Exception\TestBaseUntappdException.cs" />
<Compile Include="Exception\TestEndpointConfigurationException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Request\TestRepository.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Moq" version="4.2.1502.0911" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnitTestAdapter" version="1.2" targetFramework="net45" />
<package id="RestSharp" version="105.0.1" targetFramework="net45" />
</packages>

View File

@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Client.Net;
namespace Untappd.Net.Client
{
public class AuthenticatedUntappdCredentials : UntappdCredentials, IAuthenticatedUntappdCredentials
public class AuthenticatedUntappdCredentials : UnAuthenticatedUntappdCredentials
{
public string AccessToken { get; private set; }
/// <summary>
@@ -19,7 +14,10 @@ namespace Untappd.Net.Client
public AuthenticatedUntappdCredentials(string accessToken, string clientId, string clientSecret)
:base(clientId, clientSecret)
{
if (string.IsNullOrWhiteSpace(accessToken)) throw new ArgumentNullException("accessToken");
if (string.IsNullOrWhiteSpace(accessToken))
{
throw new ArgumentNullException("accessToken");
}
AccessToken = string.Copy(accessToken);
}
}

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net.Client
namespace Untappd.Net.Client
{
public interface IAuthenticatedUntappdCredentials : IUntappdCredentials
{

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net.Client
namespace Untappd.Net.Client
{
public interface IUntappdCredentials
{

View File

@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Net.Client;
namespace Untappd.Client.Net
namespace Untappd.Net.Client
{
public class UnAuthenticatedUntappdCredentials : UntappdCredentials, IUnAuthenticadedUntappdCredentials
{

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net
namespace Untappd.Net
{
public struct Constants
{

View File

@@ -0,0 +1,20 @@
using System;
namespace Untappd.Net.Exception
{
[Serializable]
public class BaseUntappdException : System.Exception
{
public BaseUntappdException()
{
}
public BaseUntappdException(string message) : base(message)
{
}
public BaseUntappdException(string message, System.Exception inner) : base(message, inner)
{
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Untappd.Net.Exception
{
public class EndpointConfigurationException : BaseUntappdException
{
/// <summary>
/// Called when a class has an empty endpoint
/// </summary>
/// <param name="type"></param>
public EndpointConfigurationException()
:base("Invalid endpoint configured")
{
}
}
}

View File

@@ -32,5 +32,6 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.2.*")]
[assembly: AssemblyFileVersion("0.2.*")]
[assembly: InternalsVisibleTo("Untappd.Net.UnitTests")]

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Net.Exception;
namespace Untappd.Net.Request
{
@@ -10,18 +6,17 @@ namespace Untappd.Net.Request
{
protected abstract string _EndPoint { get; }
/// <summary>
/// Pass in the parameter into the request...ie username, brewery, etc.
/// Pass in the url parameter into the request...ie username, brewery, etc.
/// </summary>
/// <param name="parameter"></param>
/// <param name="parameter">this can be null if request has no url params</param>
/// <returns></returns>
internal string EndPoint(string parameter = "")
internal string EndPoint(string parameter)
{
if (!String.IsNullOrEmpty(parameter))
if (string.IsNullOrWhiteSpace(_EndPoint))
{
parameter = string.Format("/{0}", parameter);
return string.Format(_EndPoint, parameter);
throw new EndpointConfigurationException();
}
return string.Format(_EndPoint, string.Empty);
return string.Format(_EndPoint, parameter);
}
}
}

View File

@@ -1,17 +1,27 @@
using Newtonsoft.Json;
using RestSharp;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Untappd.Client.Net;
using Newtonsoft.Json;
using RestSharp;
using Untappd.Net.Client;
namespace Untappd.Net.Request
{
public class Repository
{
internal IRestClient Client;
internal IRestRequest Request;
public Repository()
{
Client = new RestClient(Constants.BaseRequestString);
Request = new RestRequest();
}
internal Repository(IRestClient client, IRestRequest request)
{
Client = client;
Request = request;
}
/// <summary>
/// Get the things!
/// </summary>
@@ -23,18 +33,17 @@ namespace Untappd.Net.Request
public TResult Get<TResult> (IUnAuthenticadedUntappdCredentials credentials, string urlParameter, IDictionary<string, string> bodyParameters = null)
where TResult : UnAuthenticatedRequest,new()
{
// throw new NotImplementedException();
var result = new TResult();
var client = new RestClient(Constants.BaseRequestString);
var request = new RestRequest(result.EndPoint(urlParameter), Method.GET);
request.AddParameter("client_id", credentials.ClientId);
request.AddParameter("client_secret", credentials.ClientSecret);
Request.Resource = result.EndPoint(urlParameter);
Request.Method = Method.GET;
Request.AddParameter("client_id", credentials.ClientId);
Request.AddParameter("client_secret", credentials.ClientSecret);
if (bodyParameters != null)
foreach (var x in bodyParameters)
{
request.AddParameter(x.Key, x.Value);
Request.AddParameter(x.Key, x.Value);
}
var resp = client.Execute(request);
var resp = Client.Execute(Request);
var jsonresult = JsonConvert.DeserializeObject<TResult>(resp.Content);
return jsonresult;

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Untappd.Net.Request
namespace Untappd.Net.Request
{
public abstract class UnAuthenticatedRequest : AuthenticatedRequest
{

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BeerInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BeerSearch
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BreweryInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.BrewerySearch
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.Feeds
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserBadges
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserDistinctBeer
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserFriends
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.UserWishlist
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Untappd.Net.Request;
namespace Untappd.Net.Responses.VenueInfo
{
public class ResponseTime
public sealed class ResponseTime
{
[JsonProperty("time")]

View File

@@ -53,6 +53,8 @@
<Compile Include="Client\UnAuthenticatedUntappdCredentials.cs" />
<Compile Include="Client\UntappdCredentials.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Exception\BaseUntappdException.cs" />
<Compile Include="Exception\EndpointConfigurationException.cs" />
<Compile Include="Request\AuthenticatedRequest.cs" />
<Compile Include="Request\UnAuthenticatedRequest.cs" />
<Compile Include="Responses\BeerInfo.cs" />