add unit tests, finish actions
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Untappd.Net.Responses.Actions;
|
||||
|
||||
namespace Untappd.Net.UnitTests.Responses.Actions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCheckInAction
|
||||
{
|
||||
[Test]
|
||||
public void TestAccessors()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => { new CheckIn(string.Empty, "timezone", 1); });
|
||||
Assert.Throws<ArgumentNullException>(() => { new CheckIn("1", string.Empty, 1); });
|
||||
var checkin = new CheckIn("offset", "timezone", 1);
|
||||
Assert.IsNotNullOrEmpty(checkin.RequestMethod.ToString());
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => { checkin.Rating = -1; });
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => { checkin.Rating = 6; });
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => { checkin.Shout = new String('d', 141); });
|
||||
checkin.Rating = 3;
|
||||
Assert.AreEqual(3, checkin.Rating);
|
||||
var t = "tst";
|
||||
checkin.Shout = t;
|
||||
Assert.IsNotNullOrEmpty(checkin.EndPoint);
|
||||
Assert.AreEqual(checkin.Shout, t);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDictionaryGeneration()
|
||||
{
|
||||
var checkin = new CheckIn("offset", "timezone", 1);
|
||||
Assert.AreEqual(checkin.BodyParameters["gmt_offset"], "offset");
|
||||
Assert.AreEqual(checkin.BodyParameters["timezone"], "timezone");
|
||||
Assert.AreEqual(checkin.BodyParameters["bid"], 1);
|
||||
|
||||
Assert.IsFalse(checkin.BodyParameters.ContainsKey("geolat"));
|
||||
checkin.Geolat = 4;
|
||||
Assert.IsTrue(checkin.BodyParameters.ContainsKey("geolat"));
|
||||
Assert.AreEqual(checkin.BodyParameters["geolat"], 4);
|
||||
|
||||
Assert.IsFalse(checkin.BodyParameters.ContainsKey("geolng"));
|
||||
checkin.Geolng = 4;
|
||||
Assert.IsTrue(checkin.BodyParameters.ContainsKey("geolng"));
|
||||
Assert.AreEqual(checkin.BodyParameters["geolng"], 4);
|
||||
|
||||
Assert.IsFalse(checkin.BodyParameters.ContainsKey("shout"));
|
||||
checkin.Shout = "shout";
|
||||
Assert.IsTrue(checkin.BodyParameters.ContainsKey("shout"));
|
||||
Assert.AreEqual(checkin.BodyParameters["shout"], "shout");
|
||||
|
||||
Assert.IsFalse(checkin.BodyParameters.ContainsKey("rating"));
|
||||
checkin.Rating = 2;
|
||||
Assert.IsTrue(checkin.BodyParameters.ContainsKey("rating"));
|
||||
Assert.AreEqual(checkin.BodyParameters["rating"], 2);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Untappd.Net.Responses.Actions;
|
||||
|
||||
namespace Untappd.Net.UnitTests.Responses.Actions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSimpleActions
|
||||
{
|
||||
[Test]
|
||||
public void TestFriends()
|
||||
{
|
||||
var accept = new AcceptFriend("targetid");
|
||||
Assert.IsNotNullOrEmpty(accept.RequestMethod.ToString());
|
||||
Assert.IsTrue(accept.EndPoint.Contains("targetid"));
|
||||
Assert.IsNotNull(accept.BodyParameters);
|
||||
|
||||
var add = new AddFriend("targetid");
|
||||
Assert.IsNotNullOrEmpty(add.RequestMethod.ToString());
|
||||
Assert.IsTrue(add.EndPoint.Contains("targetid"));
|
||||
Assert.IsNotNull(add.BodyParameters);
|
||||
|
||||
var toast = new ToastUntoast("targetid");
|
||||
Assert.IsNotNullOrEmpty(toast.RequestMethod.ToString());
|
||||
Assert.IsTrue(toast.EndPoint.Contains("targetid"));
|
||||
Assert.IsNotNull(toast.BodyParameters);
|
||||
|
||||
var remove = new RemoveFriend("targetid");
|
||||
Assert.IsNotNullOrEmpty(remove.RequestMethod.ToString());
|
||||
Assert.IsTrue(remove.EndPoint.Contains("targetid"));
|
||||
Assert.IsNotNull(remove.BodyParameters);
|
||||
|
||||
var removeWish = new RemoveFromWishList(1);
|
||||
Assert.IsNotNullOrEmpty(removeWish.RequestMethod.ToString());
|
||||
Assert.IsNotNullOrEmpty(removeWish.EndPoint);
|
||||
Assert.AreEqual(removeWish.BodyParameters["bid"], 1);
|
||||
|
||||
|
||||
var addWish = new AddToWishList(1);
|
||||
Assert.IsNotNullOrEmpty(addWish.RequestMethod.ToString());
|
||||
Assert.IsNotNullOrEmpty(addWish.EndPoint);
|
||||
Assert.AreEqual(addWish.BodyParameters["bid"], 1);
|
||||
|
||||
var comment = new AddComment("checkin", "shout");
|
||||
Assert.IsNotNullOrEmpty(comment.RequestMethod.ToString());
|
||||
Assert.IsTrue(comment.EndPoint.Contains("checkin"));
|
||||
Assert.AreEqual(comment.BodyParameters["shout"], "shout");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPendingFriends()
|
||||
{
|
||||
var pending = new PendingFriends();
|
||||
Assert.IsNotNullOrEmpty(pending.RequestMethod.ToString());
|
||||
Assert.IsNotNullOrEmpty(pending.EndPoint);
|
||||
Assert.IsNotNull(pending.BodyParameters);
|
||||
Assert.IsFalse(pending.BodyParameters.ContainsKey("limit"));
|
||||
pending.Limit = 1;
|
||||
Assert.IsTrue(pending.BodyParameters.ContainsKey("limit"));
|
||||
Assert.IsFalse(pending.BodyParameters.ContainsKey("offset"));
|
||||
pending.Offset = 1;
|
||||
Assert.IsTrue(pending.BodyParameters.ContainsKey("offset"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestArgumentNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => { new AcceptFriend(string.Empty); });
|
||||
Assert.Throws<ArgumentNullException>(() => { new AddFriend(string.Empty); });
|
||||
Assert.Throws<ArgumentNullException>(() => { new RemoveFriend(string.Empty); });
|
||||
Assert.Throws<ArgumentNullException>(() => { new ToastUntoast(string.Empty); });
|
||||
Assert.Throws<ArgumentNullException>(() => { new AddComment(string.Empty, "ds"); });
|
||||
Assert.Throws<ArgumentNullException>(() => { new AddComment("ds", string.Empty); });
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => { new AddComment("ds", new String('d', 141)); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Responses\Actions\TestCheckInAction.cs" />
|
||||
<Compile Include="Responses\Actions\TestSimpleActions.cs" />
|
||||
<Compile Include="Responses\TestDeserializer.cs" />
|
||||
<Compile Include="Authentication\TestAuthenticationHelper.cs" />
|
||||
<Compile Include="Client\TestAuthenticatedUntappdCredentials.cs" />
|
||||
|
||||
@@ -4,6 +4,12 @@ namespace Untappd.Net.Request
|
||||
{
|
||||
public partial class Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// do a post with actions
|
||||
/// </summary>
|
||||
/// <param name="credentials"></param>
|
||||
/// <param name="action"></param>
|
||||
/// <returns>returns dynamic since often the return doesn't matter</returns>
|
||||
public dynamic Post(IAuthenticatedUntappdCredentials credentials, IAction action)
|
||||
{
|
||||
ConfigureRequest(action.EndPoint, action.BodyParameters);
|
||||
|
||||
22
src/Untappd.Net/Responses/Actions/AcceptFriend.cs
Normal file
22
src/Untappd.Net/Responses/Actions/AcceptFriend.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
using Untappd.Net.Request;
|
||||
|
||||
namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class AcceptFriend : IAction
|
||||
{
|
||||
public Method RequestMethod { get { return Method.GET; } }
|
||||
public string EndPoint { get; private set; }
|
||||
public IDictionary<string, object> BodyParameters { get { return new Dictionary<string, object>(); } }
|
||||
public AcceptFriend(string target_id)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(target_id))
|
||||
{
|
||||
throw new ArgumentNullException("target_id");
|
||||
}
|
||||
EndPoint = string.Format("v4/friend/accept/{0}", target_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/Untappd.Net/Responses/Actions/AddComment.cs
Normal file
32
src/Untappd.Net/Responses/Actions/AddComment.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
using Untappd.Net.Request;
|
||||
|
||||
namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class AddComment : IAction
|
||||
{
|
||||
public Method RequestMethod { get {return Method.POST;} }
|
||||
public string EndPoint { get; private set; }
|
||||
public IDictionary<string, object> BodyParameters { get; private set; }
|
||||
public AddComment(string checkinId, string shout)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(checkinId))
|
||||
{
|
||||
throw new ArgumentNullException("checkinId");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(shout))
|
||||
{
|
||||
throw new ArgumentNullException("shout");
|
||||
}
|
||||
if (shout.Length > 140)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("shout", shout, "Shout cannot be more than 140 characters");
|
||||
}
|
||||
EndPoint = string.Format("v4/checkin/addcomment/{0}", checkinId);
|
||||
BodyParameters = new Dictionary<string, object> {{shout, shout}};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/Untappd.Net/Responses/Actions/AddFriend.cs
Normal file
22
src/Untappd.Net/Responses/Actions/AddFriend.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
using Untappd.Net.Request;
|
||||
|
||||
namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class AddFriend : IAction
|
||||
{
|
||||
public Method RequestMethod { get{return Method.GET;} }
|
||||
public string EndPoint { get; private set; }
|
||||
public IDictionary<string, object> BodyParameters { get{ return new Dictionary<string, object>();} }
|
||||
public AddFriend(string target_id)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(target_id))
|
||||
{
|
||||
throw new ArgumentNullException("target_id");
|
||||
}
|
||||
EndPoint = string.Format("v4/friend/request/{0}", target_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Untappd.Net/Responses/Actions/AddToWishList.cs
Normal file
18
src/Untappd.Net/Responses/Actions/AddToWishList.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
using Untappd.Net.Request;
|
||||
|
||||
namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class AddToWishList : IAction
|
||||
{
|
||||
public Method RequestMethod { get {return Method.GET;} }
|
||||
public string EndPoint { get { return "v4/user/wishlist/add"; } }
|
||||
public IDictionary<string, object> BodyParameters { get; private set; }
|
||||
public AddToWishList(int beerId)
|
||||
{
|
||||
BodyParameters = new Dictionary<string, object>() { { "bid", beerId } };
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,37 +18,37 @@ namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
var dict = new Dictionary<string, object>
|
||||
{
|
||||
{"gmt_offset", gmt_offset},
|
||||
{"timezone", timezone},
|
||||
{"bid", bid}
|
||||
{"gmt_offset", GmtOffset},
|
||||
{"timezone", Timezone},
|
||||
{"bid", Bid}
|
||||
};
|
||||
if (geolat.HasValue)
|
||||
if (Geolat.HasValue)
|
||||
{
|
||||
dict.Add("geolat", geolat.Value);
|
||||
dict.Add("geolat", Geolat.Value);
|
||||
}
|
||||
if (geolng.HasValue)
|
||||
if (Geolng.HasValue)
|
||||
{
|
||||
dict.Add("geolng", geolng.Value);
|
||||
dict.Add("geolng", Geolng.Value);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(shout) && shout.Length <= 140)
|
||||
if (!string.IsNullOrWhiteSpace(Shout) && Shout.Length <= 140)
|
||||
{
|
||||
dict.Add("shout", shout);
|
||||
dict.Add("shout", Shout);
|
||||
}
|
||||
if (rating > 0 && rating < 6)
|
||||
if (Rating > 0 && Rating < 6)
|
||||
{
|
||||
dict.Add("rating", rating);
|
||||
dict.Add("rating", Rating);
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
public string gmt_offset { get; private set; }
|
||||
public string timezone { get; private set; }
|
||||
public int bid { get; private set; }
|
||||
public int? geolat { get; set; }
|
||||
public int? geolng { get; set; }
|
||||
public string GmtOffset { get; private set; }
|
||||
public string Timezone { get; private set; }
|
||||
public int Bid { get; private set; }
|
||||
public int? Geolat { get; set; }
|
||||
public int? Geolng { get; set; }
|
||||
|
||||
public string shout
|
||||
public string Shout
|
||||
{
|
||||
get { return _shout; }
|
||||
set
|
||||
@@ -57,11 +57,11 @@ namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("value", value,"Shout can be no more than 140 characters");
|
||||
}
|
||||
_shout = value;
|
||||
_shout = string.Copy(value);
|
||||
}
|
||||
}
|
||||
|
||||
public short rating
|
||||
public short Rating
|
||||
{
|
||||
get { return _rating; }
|
||||
set
|
||||
@@ -75,19 +75,19 @@ namespace Untappd.Net.Responses.Actions
|
||||
}
|
||||
|
||||
|
||||
public CheckIn(string gmt_offset, string timezone, int bid)
|
||||
public CheckIn(string gmtOffset, string timezone, int bid)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(gmt_offset))
|
||||
if (string.IsNullOrWhiteSpace(gmtOffset))
|
||||
{
|
||||
throw new ArgumentNullException("gmt_offset");
|
||||
throw new ArgumentNullException("gmtOffset");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(timezone))
|
||||
{
|
||||
throw new ArgumentNullException("timezone");
|
||||
}
|
||||
this.gmt_offset = string.Copy(gmt_offset);
|
||||
this.timezone = string.Copy(timezone);
|
||||
this.bid = bid;
|
||||
GmtOffset = string.Copy(gmtOffset);
|
||||
Timezone = string.Copy(timezone);
|
||||
Bid = bid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
using Untappd.Net.Request;
|
||||
|
||||
@@ -10,7 +6,7 @@ namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class PendingFriends : IAction
|
||||
{
|
||||
public Method RequestMethod { get; private set; }
|
||||
public Method RequestMethod { get {return Method.GET;} }
|
||||
public string EndPoint { get { return "v4/user/pending"; }}
|
||||
|
||||
public IDictionary<string, object> BodyParameters
|
||||
@@ -32,9 +28,5 @@ namespace Untappd.Net.Responses.Actions
|
||||
|
||||
public int? Offset { get; set; }
|
||||
public int? Limit { get; set; }
|
||||
public PendingFriends()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
src/Untappd.Net/Responses/Actions/RemoveFriend.cs
Normal file
22
src/Untappd.Net/Responses/Actions/RemoveFriend.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RestSharp;
|
||||
using Untappd.Net.Request;
|
||||
|
||||
namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class RemoveFriend : IAction
|
||||
{
|
||||
public Method RequestMethod { get { return Method.GET; } }
|
||||
public string EndPoint { get; private set; }
|
||||
public IDictionary<string, object> BodyParameters { get { return new Dictionary<string, object>(); } }
|
||||
public RemoveFriend(string target_id)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(target_id))
|
||||
{
|
||||
throw new ArgumentNullException("target_id");
|
||||
}
|
||||
EndPoint = string.Format("v4/friend/reject/{0}", target_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/Untappd.Net/Responses/Actions/RemoveFromWishList.cs
Normal file
22
src/Untappd.Net/Responses/Actions/RemoveFromWishList.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RestSharp;
|
||||
using Untappd.Net.Request;
|
||||
|
||||
namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class RemoveFromWishList : IAction
|
||||
{
|
||||
public Method RequestMethod { get {return Method.GET;} }
|
||||
public string EndPoint { get { return "v4/user/wishlist/delete"; } }
|
||||
public IDictionary<string, object> BodyParameters { get; private set; }
|
||||
public RemoveFromWishList(int beerId)
|
||||
{
|
||||
BodyParameters = new Dictionary<string, object>() { { "bid", beerId } };
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,9 @@ namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
public class ToastUntoast : IAction
|
||||
{
|
||||
public Method RequestMethod { get; private set; }
|
||||
public IDictionary<string, object> BodyParameters { get; private set; }
|
||||
public string CheckinId { get; private set; }
|
||||
public string EndPoint { get { return string.Format("v4/checkin/toast/{0}", CheckinId); } }
|
||||
public Method RequestMethod { get { return Method.POST; } }
|
||||
public IDictionary<string, object> BodyParameters { get { return new Dictionary<string, object>(); } }
|
||||
public string EndPoint { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -22,9 +21,7 @@ namespace Untappd.Net.Responses.Actions
|
||||
{
|
||||
throw new ArgumentNullException("checkinId");
|
||||
}
|
||||
CheckinId = string.Copy(checkinId);
|
||||
BodyParameters = new Dictionary<string, object>();
|
||||
RequestMethod = Method.POST;
|
||||
EndPoint = string.Format("v4/checkin/toast/{0}", checkinId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,14 @@
|
||||
<Compile Include="Request\IAction.cs" />
|
||||
<Compile Include="Request\RepositoryGet.cs" />
|
||||
<Compile Include="Request\RepositoryPost.cs" />
|
||||
<Compile Include="Responses\Actions\RemoveFromWishList.cs" />
|
||||
<Compile Include="Responses\Actions\AddToWishList.cs" />
|
||||
<Compile Include="Responses\Actions\AddComment.cs" />
|
||||
<Compile Include="Responses\Actions\CheckIn.cs" />
|
||||
<Compile Include="Responses\Actions\PendingFriends.cs" />
|
||||
<Compile Include="Responses\Actions\AcceptFriend.cs" />
|
||||
<Compile Include="Responses\Actions\RemoveFriend.cs" />
|
||||
<Compile Include="Responses\Actions\AddFriend.cs" />
|
||||
<Compile Include="Responses\Actions\ToastUntoast.cs" />
|
||||
<Compile Include="SingleObjectArrayConverter.cs" />
|
||||
<Compile Include="Client\AuthenticatedUntappdCredentials.cs" />
|
||||
|
||||
Reference in New Issue
Block a user