Skip to content

Commit

Permalink
GH-502 GH-490: Add parameter TraktExtendedInfo in `TraktListsModule…
Browse files Browse the repository at this point in the history
….GetListAsync()`
  • Loading branch information
henrikfroehling committed Jul 6, 2023
1 parent ea11060 commit e0bdfc2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 8 deletions.
10 changes: 8 additions & 2 deletions Source/Lib/Trakt.NET/Modules/TraktListsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,26 @@ public Task<TraktPagedResponse<ITraktList>> GetTrendingListsAsync(TraktExtendedI
/// </para>
/// </summary>
/// <param name="listIdOrSlug">The list's Trakt-Id or -Slug. See also <seealso cref="ITraktListIds" />.</param>
/// <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="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
/// If provided, the exception <see cref="OperationCanceledException" /> should be catched.
/// </param>
/// <returns>An <see cref="ITraktList" /> instance with the queried list's data.</returns>
/// <exception cref="TraktException">Thrown, if the request fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktResponse<ITraktList>> GetListAsync(string listIdOrSlug, CancellationToken cancellationToken = default)
public Task<TraktResponse<ITraktList>> GetListAsync(string listIdOrSlug, TraktExtendedInfo extendedInfo = null,
CancellationToken cancellationToken = default)
{
var requestHandler = new RequestHandler(Client);

return requestHandler.ExecuteSingleItemRequestAsync(new SingleListRequest
{
Id = listIdOrSlug
Id = listIdOrSlug,
ExtendedInfo = extendedInfo
},
cancellationToken);
}
Expand Down
22 changes: 18 additions & 4 deletions Source/Lib/Trakt.NET/Requests/Lists/SingleListRequest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
using TraktNet.Objects.Get.Lists;

namespace TraktNet.Requests.Lists
namespace TraktNet.Requests.Lists
{
using Objects.Get.Lists;
using Parameters;
using System.Collections.Generic;

internal class SingleListRequest : AListRequest<ITraktList>
{
public override string UriTemplate => "lists/{id}";
internal TraktExtendedInfo ExtendedInfo { get; set; }

public override string UriTemplate => "lists/{id}{?extended}";

public override IDictionary<string, object> GetUriPathParameters()
{
var uriParams = base.GetUriPathParameters();

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

return uriParams;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class TraktListsModule_Tests
private readonly string GET_LIST_URI = $"lists/{LIST_ID}";

[Fact]
public async Task Test_TraktListsModule_GetList()
public async Task Test_TraktListsModule_GetList_Without_ExtendedInfo()
{
TraktClient client = TestUtility.GetMockClient(GET_LIST_URI, SINGLE_LIST_JSON);

Expand Down Expand Up @@ -59,6 +59,48 @@ public async Task Test_TraktListsModule_GetList()
responseValue.User.Ids.Slug.Should().Be("sean");
}

[Fact]
public async Task Test_TraktListsModule_GetList_Complete()
{
TraktClient client = TestUtility.GetMockClient($"{GET_LIST_URI}?extended={EXTENDED_INFO}", SINGLE_LIST_JSON);

TraktResponse<ITraktList> response = await client.Lists.GetListAsync(LIST_ID, EXTENDED_INFO);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull();

ITraktList responseValue = response.Value;

responseValue.Should().NotBeNull();
responseValue.Name.Should().Be("Star Wars in machete order");
responseValue.Description.Should().Be("Next time you want to introduce someone to Star Wars for the first time, watch the films with them in this order: IV, V, II, III, VI.");
responseValue.Privacy.Should().Be(TraktListPrivacy.Public);
responseValue.DisplayNumbers.Should().BeTrue();
responseValue.AllowComments.Should().BeFalse();
responseValue.SortBy.Should().Be(TraktSortBy.Rank);
responseValue.SortHow.Should().Be(TraktSortHow.Ascending);
responseValue.CreatedAt.Should().Be(DateTime.Parse("2014-10-11T17:00:54.000Z").ToUniversalTime());
responseValue.UpdatedAt.Should().Be(DateTime.Parse("2014-11-09T17:00:54.000Z").ToUniversalTime());
responseValue.ItemCount.Should().Be(5);
responseValue.CommentCount.Should().Be(1);
responseValue.Likes.Should().Be(2);

responseValue.Ids.Should().NotBeNull();
responseValue.Ids.Trakt.Should().Be(55);
responseValue.Ids.Slug.Should().Be("star-wars-in-machete-order");

responseValue.User.Should().NotBeNull();
responseValue.User.Username.Should().Be("sean");
responseValue.User.IsPrivate.Should().BeFalse();
responseValue.User.Name.Should().Be("Sean Rudford");
responseValue.User.IsVIP.Should().BeTrue();
responseValue.User.IsVIP_EP.Should().BeFalse();
responseValue.User.Ids.Should().NotBeNull();
responseValue.User.Ids.Slug.Should().Be("sean");
}

[Theory]
[InlineData(HttpStatusCode.NotFound, typeof(TraktListNotFoundException))]
[InlineData(HttpStatusCode.Unauthorized, typeof(TraktAuthorizationException))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace TraktNet.Requests.Tests.Lists
{
using FluentAssertions;
using System.Collections.Generic;
using Trakt.NET.Tests.Utility.Traits;
using TraktNet.Parameters;
using TraktNet.Requests.Base;
using TraktNet.Requests.Lists;
using Xunit;
Expand All @@ -27,7 +29,30 @@ public void Test_SingleListRequest_Returns_Valid_RequestObjectType()
public void Test_SingleListRequest_Has_Valid_UriTemplate()
{
var request = new SingleListRequest();
request.UriTemplate.Should().Be("lists/{id}");
request.UriTemplate.Should().Be("lists/{id}{?extended}");
}

[Fact]
public void Test_SingleListRequest_Returns_Valid_UriPathParameters()
{
var request = new SingleListRequest { Id = "123" };

request.GetUriPathParameters().Should().NotBeNull()
.And.HaveCount(1)
.And.Contain(new Dictionary<string, object>
{
["id"] = "123"
});

request = new SingleListRequest { Id = "123", ExtendedInfo = new TraktExtendedInfo { Full = true } };

request.GetUriPathParameters().Should().NotBeNull()
.And.HaveCount(2)
.And.Contain(new Dictionary<string, object>
{
["id"] = "123",
["extended"] = "full"
});
}
}
}

0 comments on commit e0bdfc2

Please sign in to comment.