This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-109: Add request implementation for comment like
- Loading branch information
1 parent
7feba0c
commit 6e1b42a
Showing
4 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
Source/Lib/TraktApiSharp/Requests/Comments/CommentLikesRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace TraktApiSharp.Requests.Comments | ||
{ | ||
using Base; | ||
using Extensions; | ||
using Interfaces; | ||
using Objects.Basic; | ||
using Parameters; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
internal sealed class CommentLikesRequest : AGetRequest<ITraktCommentLike>, IHasId, ISupportsExtendedInfo, ISupportsPagination | ||
{ | ||
public string Id { get; set; } | ||
|
||
public TraktExtendedInfo ExtendedInfo { get; set; } | ||
|
||
public RequestObjectType RequestObjectType => RequestObjectType.Comments; | ||
|
||
public uint? Page { get; set; } | ||
|
||
public uint? Limit { get; set; } | ||
|
||
public override string UriTemplate => "comments/{id}/likes{?extended,page,limit}"; | ||
|
||
public override IDictionary<string, object> GetUriPathParameters() | ||
{ | ||
var uriParams = new Dictionary<string, object> | ||
{ | ||
["id"] = Id | ||
}; | ||
|
||
if (ExtendedInfo != null && ExtendedInfo.HasAnySet) | ||
uriParams.Add("extended", ExtendedInfo.ToString()); | ||
|
||
if (Page.HasValue) | ||
uriParams.Add("page", Page.Value.ToString()); | ||
|
||
if (Limit.HasValue) | ||
uriParams.Add("limit", Limit.Value.ToString()); | ||
|
||
return uriParams; | ||
} | ||
|
||
public override void Validate() | ||
{ | ||
if (Id == null) | ||
throw new ArgumentNullException(nameof(Id)); | ||
|
||
if (Id == string.Empty || Id.ContainsSpace()) | ||
throw new ArgumentException("comment id not valid", nameof(Id)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
Source/Tests/TraktApiSharp.Tests/Requests/Comments/CommentLikesRequest_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
namespace TraktApiSharp.Tests.Requests.Comments | ||
{ | ||
using FluentAssertions; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Traits; | ||
using TraktApiSharp.Requests.Base; | ||
using TraktApiSharp.Requests.Comments; | ||
using TraktApiSharp.Requests.Parameters; | ||
using Xunit; | ||
|
||
[Category("Requests.Comments")] | ||
public class CommentLikesRequest_Tests | ||
{ | ||
[Fact] | ||
public void Test_CommentLikesRequest_Has_AuthorizationRequirement_NotRequired() | ||
{ | ||
var request = new CommentLikesRequest(); | ||
request.AuthorizationRequirement.Should().Be(AuthorizationRequirement.NotRequired); | ||
} | ||
|
||
[Fact] | ||
public void Test_CommentLikesRequest_Returns_Valid_RequestObjectType() | ||
{ | ||
var request = new CommentLikesRequest(); | ||
request.RequestObjectType.Should().Be(RequestObjectType.Comments); | ||
} | ||
|
||
[Fact] | ||
public void Test_CommentLikesRequest_Has_Valid_UriTemplate() | ||
{ | ||
var request = new CommentLikesRequest(); | ||
request.UriTemplate.Should().Be("comments/{id}/likes{?extended,page,limit}"); | ||
} | ||
|
||
[Fact] | ||
public void Test_CommentLikesRequest_Validate_Throws_Exceptions() | ||
{ | ||
// id is null | ||
var request = new CommentLikesRequest(); | ||
|
||
Action act = () => request.Validate(); | ||
act.Should().Throw<ArgumentNullException>(); | ||
|
||
// empty id | ||
request = new CommentLikesRequest { Id = string.Empty }; | ||
|
||
act = () => request.Validate(); | ||
act.Should().Throw<ArgumentException>(); | ||
|
||
// id with spaces | ||
request = new CommentLikesRequest { Id = "invalid id" }; | ||
|
||
act = () => request.Validate(); | ||
act.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
[Theory, ClassData(typeof(CommentLikesRequest_TestData))] | ||
public void Test_CommentLikesRequest_Returns_Valid_UriPathParameters(IDictionary<string, object> values, | ||
IDictionary<string, object> expected) | ||
{ | ||
values.Should().NotBeNull().And.HaveCount(expected.Count); | ||
|
||
if (expected.Count > 0) | ||
values.Should().Contain(expected); | ||
} | ||
|
||
public class CommentLikesRequest_TestData : IEnumerable<object[]> | ||
{ | ||
private const string _id = "123"; | ||
private static readonly TraktExtendedInfo _extendedInfo = new TraktExtendedInfo { Full = true }; | ||
private const int _page = 5; | ||
private const int _limit = 20; | ||
|
||
private static readonly CommentLikesRequest _request1 = new CommentLikesRequest | ||
{ | ||
Id = _id | ||
}; | ||
|
||
private static readonly CommentLikesRequest _request2 = new CommentLikesRequest | ||
{ | ||
Id = _id, | ||
Page = _page | ||
}; | ||
|
||
private static readonly CommentLikesRequest _request3 = new CommentLikesRequest | ||
{ | ||
Id = _id, | ||
Limit = _limit | ||
}; | ||
|
||
private static readonly CommentLikesRequest _request4 = new CommentLikesRequest | ||
{ | ||
Id = _id, | ||
Page = _page, | ||
Limit = _limit | ||
}; | ||
|
||
private static readonly CommentLikesRequest _request5 = new CommentLikesRequest | ||
{ | ||
Id = _id, | ||
ExtendedInfo = _extendedInfo | ||
}; | ||
|
||
private static readonly CommentLikesRequest _request6 = new CommentLikesRequest | ||
{ | ||
Id = _id, | ||
ExtendedInfo = _extendedInfo, | ||
Page = _page | ||
}; | ||
|
||
private static readonly CommentLikesRequest _request7 = new CommentLikesRequest | ||
{ | ||
Id = _id, | ||
ExtendedInfo = _extendedInfo, | ||
Limit = _limit | ||
}; | ||
|
||
private static readonly CommentLikesRequest _request8 = new CommentLikesRequest | ||
{ | ||
Id = _id, | ||
ExtendedInfo = _extendedInfo, | ||
Page = _page, | ||
Limit = _limit | ||
}; | ||
|
||
private static readonly List<object[]> _data = new List<object[]>(); | ||
|
||
public CommentLikesRequest_TestData() | ||
{ | ||
SetupPathParamters(); | ||
} | ||
|
||
private void SetupPathParamters() | ||
{ | ||
var strExtendedInfo = _extendedInfo.ToString(); | ||
var strPage = _page.ToString(); | ||
var strLimit = _limit.ToString(); | ||
|
||
_data.Add(new object[] { _request1.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id | ||
}}); | ||
|
||
_data.Add(new object[] { _request2.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id, | ||
["page"] = strPage | ||
}}); | ||
|
||
_data.Add(new object[] { _request3.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id, | ||
["limit"] = strLimit | ||
}}); | ||
|
||
_data.Add(new object[] { _request4.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id, | ||
["page"] = strPage, | ||
["limit"] = strLimit | ||
}}); | ||
|
||
_data.Add(new object[] { _request5.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id, | ||
["extended"] = strExtendedInfo | ||
}}); | ||
|
||
_data.Add(new object[] { _request6.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id, | ||
["extended"] = strExtendedInfo, | ||
["page"] = strPage | ||
}}); | ||
|
||
_data.Add(new object[] { _request7.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id, | ||
["extended"] = strExtendedInfo, | ||
["limit"] = strLimit | ||
}}); | ||
|
||
_data.Add(new object[] { _request8.GetUriPathParameters(), new Dictionary<string, object> | ||
{ | ||
["id"] = _id, | ||
["extended"] = strExtendedInfo, | ||
["page"] = strPage, | ||
["limit"] = strLimit | ||
}}); | ||
} | ||
|
||
public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters