Skip to content

Commit

Permalink
GH-502 GH-489: Add parameter TraktExtendedInfo in `TraktListsModule…
Browse files Browse the repository at this point in the history
….GetPopularListsAsync()`
  • Loading branch information
henrikfroehling committed Jul 5, 2023
1 parent a3223fb commit f5a3c51
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 15 deletions.
8 changes: 7 additions & 1 deletion Source/Lib/Trakt.NET/Modules/TraktListsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ internal TraktListsModule(TraktClient client) : base(client)
/// See <a href="https://trakt.docs.apiary.io/#reference/lists/popular/get-popular-lists">"Trakt API Doc - Lists: Popular"</a> for more information.
/// </para>
/// </summary>
/// <param name="extendedInfo">
/// The extended info, which determines how much data about the list items 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 @@ -44,11 +48,13 @@ internal TraktListsModule(TraktClient client) : base(client)
/// </para>
/// </returns>
/// <exception cref="TraktException">Thrown, if the request fails.</exception>
public Task<TraktPagedResponse<ITraktList>> GetPopularListsAsync(TraktPagedParameters pagedParameters = null,
public Task<TraktPagedResponse<ITraktList>> GetPopularListsAsync(TraktExtendedInfo extendedInfo = null,
TraktPagedParameters pagedParameters = null,
CancellationToken cancellationToken = default)
{
var request = new ListsPopularRequest
{
ExtendedInfo = extendedInfo,
Page = pagedParameters?.Page,
Limit = pagedParameters?.Limit
};
Expand Down
2 changes: 1 addition & 1 deletion Source/Lib/Trakt.NET/Requests/Lists/ListsPopularRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
internal sealed class ListsPopularRequest : AListsRequest
{
public override string UriTemplate => "lists/popular{?page,limit}";
public override string UriTemplate => "lists/popular{?extended,page,limit}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,32 @@ public async Task Test_TraktListsModule_GetPopularLists()
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktListsModule_GetPopularLists_With_ExtendedInfo()
{
TraktClient client = TestUtility.GetMockClient($"{GET_POPULAR_LISTS_URI}?extended={EXTENDED_INFO}",
LISTS_JSON, 1, 10, 1, ITEM_COUNT);

TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(EXTENDED_INFO);

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

[Fact]
public async Task Test_TraktListsModule_GetPopularLists_With_Page()
{
TraktClient client = TestUtility.GetMockClient($"{GET_POPULAR_LISTS_URI}?page={PAGE}",
LISTS_JSON, PAGE, 10, 1, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -60,7 +78,7 @@ public async Task Test_TraktListsModule_GetPopularLists_With_Limit()
LISTS_JSON, 1, LIMIT, 1, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(null, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -73,13 +91,71 @@ public async Task Test_TraktListsModule_GetPopularLists_With_Limit()
}

[Fact]
public async Task Test_TraktListsModule_GetPopularLists_Complete()
public async Task Test_TraktListsModule_GetPopularLists_With_ExtendedInfo_And_Page()
{
TraktClient client = TestUtility.GetMockClient($"{GET_POPULAR_LISTS_URI}?extended={EXTENDED_INFO}&page={PAGE}",
LISTS_JSON, PAGE, 10, 1, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(EXTENDED_INFO, pagedParameters);

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

[Fact]
public async Task Test_TraktListsModule_GetPopularLists_With_ExtendedInfo_And_Limit()
{
TraktClient client = TestUtility.GetMockClient($"{GET_POPULAR_LISTS_URI}?extended={EXTENDED_INFO}&limit={LIMIT}",
LISTS_JSON, 1, LIMIT, 1, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(null, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(EXTENDED_INFO, pagedParameters);

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

[Fact]
public async Task Test_TraktListsModule_GetPopularLists_With_Page_And_Limit()
{
TraktClient client = TestUtility.GetMockClient($"{GET_POPULAR_LISTS_URI}?page={PAGE}&limit={LIMIT}",
LISTS_JSON, PAGE, LIMIT, 1, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

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

[Fact]
public async Task Test_TraktListsModule_GetPopularLists_Complete()
{
TraktClient client = TestUtility.GetMockClient(
$"{GET_POPULAR_LISTS_URI}?extended={EXTENDED_INFO}&page={PAGE}&limit={LIMIT}",
LISTS_JSON, PAGE, LIMIT, 1, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(PAGE, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(EXTENDED_INFO, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -98,7 +174,7 @@ public async Task Test_TraktListsModule_GetPopularLists_Paging_HasPreviousPage_A
LISTS_JSON, 2, LIMIT, 5, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -119,7 +195,7 @@ public async Task Test_TraktListsModule_GetPopularLists_Paging_Only_HasPreviousP
LISTS_JSON, 2, LIMIT, 2, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -140,7 +216,7 @@ public async Task Test_TraktListsModule_GetPopularLists_Paging_Only_HasNextPage(
LISTS_JSON, 1, LIMIT, 2, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -161,7 +237,7 @@ public async Task Test_TraktListsModule_GetPopularLists_Paging_Not_HasPreviousPa
LISTS_JSON, 1, LIMIT, 1, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand All @@ -182,7 +258,7 @@ public async Task Test_TraktListsModule_GetPopularLists_Paging_GetPreviousPage()
LISTS_JSON, 2, LIMIT, 2, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand Down Expand Up @@ -219,7 +295,7 @@ public async Task Test_TraktListsModule_GetPopularLists_Paging_GetNextPage()
LISTS_JSON, 1, LIMIT, 2, ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(pagedParameters);
TraktPagedResponse<ITraktList> response = await client.Lists.GetPopularListsAsync(null, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task Test_TraktListsModule_GetTrendingLists()
public async Task Test_TraktListsModule_GetTrendingLists_With_ExtendedInfo()
{
TraktClient client = TestUtility.GetMockClient($"{GET_TRENDING_LISTS_URI}?extended={EXTENDED_INFO}",
LISTS_JSON, PAGE, 10, 1, ITEM_COUNT);
LISTS_JSON, 1, 10, 1, ITEM_COUNT);

TraktPagedResponse<ITraktList> response = await client.Lists.GetTrendingListsAsync(EXTENDED_INFO);

Expand All @@ -48,7 +48,7 @@ public async Task Test_TraktListsModule_GetTrendingLists_With_ExtendedInfo()
response.Value.Should().NotBeNull().And.HaveCount(ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(ITEM_COUNT);
response.Limit.Should().Be(10u);
response.Page.Should().Be(PAGE);
response.Page.Should().Be(1u);
response.PageCount.Should().HaveValue().And.Be(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ListsPopularRequest_Tests
public void Test_ListsPopularRequest_Has_Valid_UriTemplate()
{
var request = new ListsPopularRequest();
request.UriTemplate.Should().Be("lists/popular{?page,limit}");
request.UriTemplate.Should().Be("lists/popular{?extended,page,limit}");
}
}
}

0 comments on commit f5a3c51

Please sign in to comment.