diff --git a/.gitignore b/.gitignore index 57a1574..830d556 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ *.user *.userosscache *.sln.docstates - +*.DotSettings # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/src/Untappd.Net.UnitTests/Authentication/TestAuthenticationHelper.cs b/src/Untappd.Net.UnitTests/Authentication/TestAuthenticationHelper.cs index 4d2d1b5..7ea9b41 100644 --- a/src/Untappd.Net.UnitTests/Authentication/TestAuthenticationHelper.cs +++ b/src/Untappd.Net.UnitTests/Authentication/TestAuthenticationHelper.cs @@ -1,8 +1,4 @@ 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; @@ -47,5 +43,22 @@ namespace Untappd.Net.UnitTests.Authentication AuthenticationHelper.TokenUrl(new UnAuthenticatedUntappdCredentials("d", "d"), "ds", string.Empty); } + + [Test] + public void TestTokenUrl() + { + + var s = AuthenticationHelper.TokenUrl(new UnAuthenticatedUntappdCredentials("d", "d"), "ds", "code"); + Assert.AreEqual(s, Constants.OAuthTokenEndPoint + "/?client_id=d&client_secret=d&response_type=code&redirect_url=ds&code=code"); + + } + [Test] + public void TestRedirectUrl() + { + + var s = AuthenticationHelper.RedirectUserTo(new UnAuthenticatedUntappdCredentials("d", "d"), "ds"); + Assert.AreEqual(s, Constants.BaseRequestString + "/?client_id=d&response_type=code&redirect_url=ds"); + + } } } diff --git a/src/Untappd.Net.UnitTests/Request/TestRepository.cs b/src/Untappd.Net.UnitTests/Request/TestRepository.cs index 00453c0..b405557 100644 --- a/src/Untappd.Net.UnitTests/Request/TestRepository.cs +++ b/src/Untappd.Net.UnitTests/Request/TestRepository.cs @@ -45,5 +45,14 @@ namespace Untappd.Net.UnitTests.Request Assert.IsTrue(constructorTest.Client != null); Assert.IsTrue(constructorTest.Request != null); } + [Test] + public void ConfirmConfigureGetRequestClearsParams() + { + var constructorTest = new Repository(); + constructorTest.Request.Parameters.Add(new Parameter(){Name = "param"}); + Assert.IsTrue(constructorTest.Request.Parameters.Count > 0); + constructorTest.ConfigureGetRequest("endpoint"); + Assert.IsTrue(constructorTest.Request.Parameters.Count == 0); + } } } diff --git a/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs b/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs index d7eb638..06fc9c4 100644 --- a/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs +++ b/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs @@ -1,21 +1,21 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; using NUnit.Framework; using Untappd.Net.Client; using Untappd.Net.Request; -using Newtonsoft.Json; -using UserInfo = Untappd.Net.Responses.UserInfo; -using ActivityFeed = Untappd.Net.Responses.Feeds.ActivityFeed; -using UserActivityFeed = Untappd.Net.Responses.Feeds.UserActivityFeed; -using UserBadges = Untappd.Net.Responses.UserBadges; -using BeerInfo = Untappd.Net.Responses.BeerInfo; -using BeerSearch = Untappd.Net.Responses.BeerSearch; -using BreweryInfo = Untappd.Net.Responses.BreweryInfo; -using BrewerySearch = Untappd.Net.Responses.BrewerySearch; +using Untappd.Net.Responses.BeerInfo; +using Untappd.Net.Responses.BeerSearch; +using Untappd.Net.Responses.BreweryInfo; +using Untappd.Net.Responses.BrewerySearch; +using Untappd.Net.Responses.Feeds.ActivityFeed; +using Untappd.Net.Responses.Feeds.UserActivityFeed; +using Untappd.Net.Responses.UserBadges; +using Untappd.Net.Responses.UserFriends; +using Untappd.Net.Responses.UserInfo; +using Untappd.Net.Responses.VenueInfo; using UserDistinctBeers = Untappd.Net.Responses.UserDistinctBeer; -using UserFriends = Untappd.Net.Responses.UserFriends; using UserWishList = Untappd.Net.Responses.UserWishlist; -using VenueInfo = Untappd.Net.Responses.VenueInfo; namespace Untappd.Net.UnitTests { @@ -38,92 +38,92 @@ namespace Untappd.Net.UnitTests var repo = new Repository(); //var resp = repo.Get(credentials); - var resp3 = repo.Get(credentials, "", parameters); - var resp2 = repo.Get(credentials); + var resp3 = repo.Get(credentials, "", parameters); + var resp2 = repo.Get(credentials); } [Test] public void TestJsonDeserializeUserBadges() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "UserBadges.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "UserBadges.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerBeerInfo() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "BeerInfo.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "BeerInfo.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerBeerSearch() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "BeerSearch.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "BeerSearch.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerBreweryInfo() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "BreweryInfo.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "BreweryInfo.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerBrewerySearch() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "BrewerySearch.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "BrewerySearch.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerUserDistinctBeers() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "UserDistinctBeers.json")); + var json = File.ReadAllText(string.Format(ResponsePath, "UserDistinctBeers.json")); var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerUserFriends() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "UserFriends.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "UserFriends.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerUserInfo() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "UserInfo.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "UserInfo.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerUserWishList() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "UserWishList.json")); + var json = File.ReadAllText(string.Format(ResponsePath, "UserWishList.json")); var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerVenueInfo() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "VenueInfo.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "VenueInfo.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerActivityFeed() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "ActivityFeed.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "ActivityFeed.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } [Test] public void TestJsonDeserializerUserActivityFeed() { - var json = System.IO.File.ReadAllText(string.Format(ResponsePath, "UserActivityFeed.json")); - var jsonresult = JsonConvert.DeserializeObject(json); + var json = File.ReadAllText(string.Format(ResponsePath, "UserActivityFeed.json")); + var jsonresult = JsonConvert.DeserializeObject(json); } } } diff --git a/src/Untappd.Net.UnitTests/Responses/TestResponseEndpoints.cs b/src/Untappd.Net.UnitTests/Responses/TestResponseEndpoints.cs new file mode 100644 index 0000000..959d8bb --- /dev/null +++ b/src/Untappd.Net.UnitTests/Responses/TestResponseEndpoints.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using Untappd.Net.Request; + +namespace Untappd.Net.UnitTests.Responses +{ + [TestFixture] + public class TestResponseEndpoints + { + + /// + /// Run through all the endpoints to make sure they all atleast do not error out. + /// This is so we can get a high code coverage, while also covering new types that get added. + /// + [Test] + public void RunAllEndpoints() + { + + var objects = Assembly.GetAssembly(typeof (IRequest)).GetTypes().Where(myType => + myType.IsClass + && !myType.IsAbstract + && myType.GetInterface("IRequest") != null).Select(type => (IRequest) Activator.CreateInstance(type)).ToList(); + objects.ForEach(a=>Assert.IsNotNullOrEmpty(a.EndPoint("t"))); + } + } +} diff --git a/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj b/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj index 6c21b27..9bb0afb 100644 --- a/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj +++ b/src/Untappd.Net.UnitTests/Untappd.Net.UnitTests.csproj @@ -77,6 +77,7 @@ + diff --git a/src/Untappd.Net/Authentication/AuthenticationHelper.cs b/src/Untappd.Net/Authentication/AuthenticationHelper.cs index a3dad16..ddb9226 100644 --- a/src/Untappd.Net/Authentication/AuthenticationHelper.cs +++ b/src/Untappd.Net/Authentication/AuthenticationHelper.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Untappd.Net.Client; -using Untappd.Net.Request; namespace Untappd.Net.Authentication { diff --git a/src/Untappd.Net/Client/UnAuthenticatedUntappdCredentials.cs b/src/Untappd.Net/Client/UnAuthenticatedUntappdCredentials.cs index b349e02..39f4b68 100644 --- a/src/Untappd.Net/Client/UnAuthenticatedUntappdCredentials.cs +++ b/src/Untappd.Net/Client/UnAuthenticatedUntappdCredentials.cs @@ -1,6 +1,4 @@ -using System; - -namespace Untappd.Net.Client +namespace Untappd.Net.Client { public class UnAuthenticatedUntappdCredentials : UntappdCredentials, IUnAuthenticatedUntappdCredentials { diff --git a/src/Untappd.Net/Client/UntappdCredentials.cs b/src/Untappd.Net/Client/UntappdCredentials.cs index 6bdbce8..23e5390 100644 --- a/src/Untappd.Net/Client/UntappdCredentials.cs +++ b/src/Untappd.Net/Client/UntappdCredentials.cs @@ -12,7 +12,7 @@ namespace Untappd.Net.Client /// /// /// - public UntappdCredentials(string clientId, string clientSecret) + protected UntappdCredentials(string clientId, string clientSecret) { if (string.IsNullOrWhiteSpace(clientId)) { diff --git a/src/Untappd.Net/Request/BasicRequest.cs b/src/Untappd.Net/Request/BasicRequest.cs index 37e5688..f3ab311 100644 --- a/src/Untappd.Net/Request/BasicRequest.cs +++ b/src/Untappd.Net/Request/BasicRequest.cs @@ -1,4 +1,5 @@ using System; + namespace Untappd.Net.Request { public abstract class BasicRequest diff --git a/src/Untappd.Net/Request/IAuthenticatedRequest.cs b/src/Untappd.Net/Request/IAuthenticatedRequest.cs index a102cdc..3ec9ffd 100644 --- a/src/Untappd.Net/Request/IAuthenticatedRequest.cs +++ b/src/Untappd.Net/Request/IAuthenticatedRequest.cs @@ -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 interface IAuthenticatedRequest : IRequest { diff --git a/src/Untappd.Net/Request/IRequest.cs b/src/Untappd.Net/Request/IRequest.cs index 44b548a..1283f2f 100644 --- a/src/Untappd.Net/Request/IRequest.cs +++ b/src/Untappd.Net/Request/IRequest.cs @@ -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 interface IRequest { diff --git a/src/Untappd.Net/Request/IUnAuthenticatedRequest.cs b/src/Untappd.Net/Request/IUnAuthenticatedRequest.cs index a4d49b1..86e287c 100644 --- a/src/Untappd.Net/Request/IUnAuthenticatedRequest.cs +++ b/src/Untappd.Net/Request/IUnAuthenticatedRequest.cs @@ -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 interface IUnAuthenticatedRequest : IRequest { diff --git a/src/Untappd.Net/Request/Repository.cs b/src/Untappd.Net/Request/Repository.cs index faf5c4d..946cc2f 100644 --- a/src/Untappd.Net/Request/Repository.cs +++ b/src/Untappd.Net/Request/Repository.cs @@ -1,10 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Collections.Generic; using Newtonsoft.Json; using RestSharp; using Untappd.Net.Client; -using System.Threading; namespace Untappd.Net.Request { @@ -25,15 +22,18 @@ namespace Untappd.Net.Request Request = request; } - private void ConfigureGetRequest(IRestRequest request, string endPoint, IDictionary bodyParameters = null) + internal void ConfigureGetRequest(string endPoint, IDictionary bodyParameters = null) { - request.Resource = endPoint; - request.Method = Method.GET; - if (request.Parameters != null) this.Request.Parameters.Clear(); + Request.Resource = endPoint; + Request.Method = Method.GET; + if (Request.Parameters != null) Request.Parameters.Clear(); - if (bodyParameters != null) - foreach (var param in bodyParameters) - request.AddParameter(param.Key, param.Value); + if (bodyParameters == null) return; + foreach (var param in bodyParameters) + { + Request.AddParameter(param.Key, param.Value); + } + } /// @@ -48,12 +48,12 @@ namespace Untappd.Net.Request where TResult : IUnAuthenticatedRequest,new() { var result = new TResult(); - this.ConfigureGetRequest(this.Request, result.EndPoint(urlParameter), bodyParameters); + ConfigureGetRequest(result.EndPoint(urlParameter), bodyParameters); - this.Request.AddParameter("client_id", credentials.ClientId); - this.Request.AddParameter("client_secret", credentials.ClientSecret); + Request.AddParameter("client_id", credentials.ClientId); + Request.AddParameter("client_secret", credentials.ClientSecret); - return this.DoRestRequest(this.Request); + return DoRestRequest(); } /// @@ -68,17 +68,17 @@ namespace Untappd.Net.Request where TResult : IAuthenticatedRequest, new() { var result = new TResult(); - this.ConfigureGetRequest(this.Request, result.EndPoint(urlParameter), bodyParameters); + ConfigureGetRequest(result.EndPoint(urlParameter), bodyParameters); - this.Request.AddParameter("access_token", credentials.AccessToken); + Request.AddParameter("access_token", credentials.AccessToken); - return this.DoRestRequest(this.Request); + return DoRestRequest(); } - private TResult DoRestRequest(IRestRequest request) + private TResult DoRestRequest() { var client = new RestClient(Constants.BaseRequestString); - var resp = client.Execute(request); + var resp = client.Execute(Request); return JsonConvert.DeserializeObject(resp.Content); } diff --git a/src/Untappd.Net/Responses/UserBadges.cs b/src/Untappd.Net/Responses/UserBadges.cs index 7ba02ff..6cfd4bf 100644 --- a/src/Untappd.Net/Responses/UserBadges.cs +++ b/src/Untappd.Net/Responses/UserBadges.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; using Untappd.Net.Request; -using System.ComponentModel; namespace Untappd.Net.Responses.UserBadges { diff --git a/src/Untappd.Net/SingleObjectArrayConverter.cs b/src/Untappd.Net/SingleObjectArrayConverter.cs index b3c349e..75d6c40 100644 --- a/src/Untappd.Net/SingleObjectArrayConverter.cs +++ b/src/Untappd.Net/SingleObjectArrayConverter.cs @@ -19,17 +19,18 @@ namespace Untappd.Net public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - object retval = new Object(); + var retval = new Object(); - if (reader.TokenType == JsonToken.StartObject) + switch (reader.TokenType) { - T instance = (T)serializer.Deserialize(reader, typeof(T)); - retval = instance; - } - else if (reader.TokenType == JsonToken.StartArray) - { - reader.Read(); - retval = null; + case JsonToken.StartObject: + var instance = (T)serializer.Deserialize(reader, typeof(T)); + retval = instance; + break; + case JsonToken.StartArray: + reader.Read(); + retval = null; + break; } return retval;