Skip to content

Commit

Permalink
GH-502 GH-494: Add parameter TraktExtendedInfo in `TraktCommentsMod…
Browse files Browse the repository at this point in the history
…ule.GetCommentRepliesAsync()`
  • Loading branch information
henrikfroehling committed Jul 7, 2023
1 parent 93401c5 commit a62e0d2
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 18 deletions.
8 changes: 7 additions & 1 deletion Source/Lib/Trakt.NET/Modules/TraktCommentsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ public Task<TraktNoContentResponse> UnlikeCommentAsync(uint commentId, Cancellat
/// </para>
/// </summary>
/// <param name="commentId">The id of the comment, for which the replies should be queried.</param>
/// <param name="extendedInfo">
/// The extended info, which determines how much data about the comment's media item should be queried.
/// See also <seealso cref="TraktExtendedInfo" />.
/// </param>
/// <param name="pagedParameters">Specifies pagination parameters. <see cref="TraktPagedParameters" />.</param>
/// <param name="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
Expand All @@ -678,12 +682,14 @@ public Task<TraktNoContentResponse> UnlikeCommentAsync(uint commentId, Cancellat
/// </returns>
/// <exception cref="TraktException">Thrown, if the request fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktPagedResponse<ITraktComment>> GetCommentRepliesAsync(uint commentId, TraktPagedParameters pagedParameters = null,
public Task<TraktPagedResponse<ITraktComment>> GetCommentRepliesAsync(uint commentId, TraktExtendedInfo extendedInfo = null,
TraktPagedParameters pagedParameters = null,
CancellationToken cancellationToken = default)
{
var request = new CommentRepliesRequest
{
Id = commentId.ToString(),
ExtendedInfo = extendedInfo,
Page = pagedParameters?.Page,
Limit = pagedParameters?.Limit,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Extensions;
using Interfaces;
using Objects.Basic;
using Parameters;
using System.Collections.Generic;

internal sealed class CommentRepliesRequest : AGetRequest<ITraktComment>, IHasId, ISupportsPagination
Expand All @@ -13,11 +14,13 @@ internal sealed class CommentRepliesRequest : AGetRequest<ITraktComment>, IHasId

public RequestObjectType RequestObjectType => RequestObjectType.Comments;

internal TraktExtendedInfo ExtendedInfo { get; set; }

public uint? Page { get; set; }

public uint? Limit { get; set; }

public override string UriTemplate => "comments/{id}/replies{?page,limit}";
public override string UriTemplate => "comments/{id}/replies{?extended,page,limit}";

public override IDictionary<string, object> GetUriPathParameters()
{
Expand All @@ -26,6 +29,9 @@ public override IDictionary<string, object> GetUriPathParameters()
["id"] = Id
};

if (ExtendedInfo != null && ExtendedInfo.HasAnySet)
uriParams.Add("extended", ExtendedInfo.ToString());

if (Page.HasValue)
uriParams.Add("page", Page.Value.ToString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,32 @@ public async Task Test_TraktCommentsModule_GetCommentReplies()
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktCommentsModule_GetCommentReplies_With_ExtendedInfo()
{
TraktClient client = TestUtility.GetMockClient($"{GET_COMMENT_REPLIES_URI}?extended={EXTENDED_INFO}",
COMMENT_REPLIES_JSON, PAGE, 10, 1, COMMENT_REPLIES_ITEM_COUNT);

TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, EXTENDED_INFO);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENT_REPLIES_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENT_REPLIES_ITEM_COUNT);
response.Limit.Should().Be(10u);
response.Page.Should().Be(PAGE);
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktCommentsModule_GetCommentReplies_With_Page()
{
TraktClient client = TestUtility.GetMockClient($"{GET_COMMENT_REPLIES_URI}?page={PAGE}",
COMMENT_REPLIES_JSON, PAGE, 10, 1, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -61,7 +79,7 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_With_Limit()
COMMENT_REPLIES_JSON, 1, LIMIT, 1, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(null, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -74,13 +92,70 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_With_Limit()
}

[Fact]
public async Task Test_TraktCommentsModule_GetCommentReplies_Complete()
public async Task Test_TraktCommentsModule_GetCommentReplies_With_Page_And_Limit()
{
TraktClient client = TestUtility.GetMockClient($"{GET_COMMENT_REPLIES_URI}?page={PAGE}&limit={LIMIT}",
COMMENT_REPLIES_JSON, PAGE, LIMIT, 1, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENT_REPLIES_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENT_REPLIES_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(PAGE);
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktCommentsModule_GetCommentReplies_With_ExtendedInfo_And_Page()
{
TraktClient client = TestUtility.GetMockClient($"{GET_COMMENT_REPLIES_URI}?extended={EXTENDED_INFO}&page={PAGE}",
COMMENT_REPLIES_JSON, PAGE, 10, 1, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, EXTENDED_INFO, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENT_REPLIES_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENT_REPLIES_ITEM_COUNT);
response.Limit.Should().Be(10u);
response.Page.Should().Be(PAGE);
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktCommentsModule_GetCommentReplies_With_ExtendedInfo_And_Limit()
{
TraktClient client = TestUtility.GetMockClient($"{GET_COMMENT_REPLIES_URI}?extended={EXTENDED_INFO}&limit={LIMIT}",
COMMENT_REPLIES_JSON, 1, LIMIT, 1, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(null, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, EXTENDED_INFO, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENT_REPLIES_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENT_REPLIES_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(1u);
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktCommentsModule_GetCommentReplies_Complete()
{
TraktClient client = TestUtility.GetMockClient($"{GET_COMMENT_REPLIES_URI}?extended={EXTENDED_INFO}&page={PAGE}&limit={LIMIT}",
COMMENT_REPLIES_JSON, PAGE, LIMIT, 1, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, EXTENDED_INFO, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -99,7 +174,7 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_Paging_HasPreviousP
COMMENT_REPLIES_JSON, 2, LIMIT, 5, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -120,7 +195,7 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_Paging_Only_HasPrev
COMMENT_REPLIES_JSON, 2, LIMIT, 2, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -141,7 +216,7 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_Paging_Only_HasNext
COMMENT_REPLIES_JSON, 1, LIMIT, 2, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -162,7 +237,7 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_Paging_Not_HasPrevi
COMMENT_REPLIES_JSON, 1, LIMIT, 1, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -183,7 +258,7 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_Paging_GetPreviousP
COMMENT_REPLIES_JSON, 2, LIMIT, 2, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand Down Expand Up @@ -220,7 +295,7 @@ public async Task Test_TraktCommentsModule_GetCommentReplies_Paging_GetNextPage(
COMMENT_REPLIES_JSON, 1, LIMIT, 2, COMMENT_REPLIES_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, pagedParameters);
TraktPagedResponse<ITraktComment> response = await client.Comments.GetCommentRepliesAsync(GET_COMMENT_REPLIES_ID, null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using Trakt.NET.Tests.Utility.Traits;
using TraktNet.Exceptions;
using TraktNet.Parameters;
using TraktNet.Requests.Base;
using TraktNet.Requests.Comments;
using Xunit;
Expand All @@ -31,7 +32,7 @@ public void Test_CommentRepliesRequest_Returns_Valid_RequestObjectType()
public void Test_CommentRepliesRequest_Has_Valid_UriTemplate()
{
var request = new CommentRepliesRequest();
request.UriTemplate.Should().Be("comments/{id}/replies{?page,limit}");
request.UriTemplate.Should().Be("comments/{id}/replies{?extended,page,limit}");
}

[Fact]
Expand Down Expand Up @@ -69,6 +70,7 @@ public void Test_CommentRepliesRequest_Returns_Valid_UriPathParameters(IDictiona
public class CommentRepliesRequest_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;

Expand All @@ -80,18 +82,46 @@ public class CommentRepliesRequest_TestData : IEnumerable<object[]>
private static readonly CommentRepliesRequest _request2 = new CommentRepliesRequest
{
Id = _id,
Page = _page
ExtendedInfo = _extendedInfo
};

private static readonly CommentRepliesRequest _request3 = new CommentRepliesRequest
{
Id = _id,
Limit = _limit
Page = _page
};

private static readonly CommentRepliesRequest _request4 = new CommentRepliesRequest
{
Id = _id,
Limit = _limit
};

private static readonly CommentRepliesRequest _request5 = new CommentRepliesRequest
{
Id = _id,
Page = _page,
Limit = _limit
};

private static readonly CommentRepliesRequest _request6 = new CommentRepliesRequest
{
Id = _id,
ExtendedInfo = _extendedInfo,
Page = _page
};

private static readonly CommentRepliesRequest _request7 = new CommentRepliesRequest
{
Id = _id,
ExtendedInfo = _extendedInfo,
Limit = _limit
};

private static readonly CommentRepliesRequest _request8 = new CommentRepliesRequest
{
Id = _id,
ExtendedInfo = _extendedInfo,
Page = _page,
Limit = _limit
};
Expand All @@ -103,8 +133,9 @@ public CommentRepliesRequest_TestData()
SetupPathParamters();
}

private void SetupPathParamters()
private static void SetupPathParamters()
{
var strExtendedInfo = _extendedInfo.ToString();
var strPage = _page.ToString();
var strLimit = _limit.ToString();

Expand All @@ -116,18 +147,46 @@ private void SetupPathParamters()
_data.Add(new object[] { _request2.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["page"] = strPage
["extended"] = strExtendedInfo
}});

_data.Add(new object[] { _request3.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["limit"] = strLimit
["page"] = strPage
}});

_data.Add(new object[] { _request4.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["limit"] = strLimit
}});

_data.Add(new object[] { _request5.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["page"] = strPage,
["limit"] = strLimit
}});

_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
}});
Expand Down

0 comments on commit a62e0d2

Please sign in to comment.