Skip to content

Commit

Permalink
GH-157: Add paging tests for episodes module
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikfroehling authored May 5, 2023
1 parent 82a8f6b commit 0f89ffc
Show file tree
Hide file tree
Showing 2 changed files with 322 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,164 @@ public async Task Test_TraktEpisodesModule_GetEpisodeCommments_Complete()
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeCommments_Paging_HasPreviousPage_And_HasNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 2, LIMIT, 5, COMMENTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Episodes.GetEpisodeCommentsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, COMMENT_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(5);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeTrue();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeCommments_Paging_Only_HasPreviousPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 2, LIMIT, 2, COMMENTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Episodes.GetEpisodeCommentsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, COMMENT_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeFalse();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeCommments_Paging_Only_HasNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 1, LIMIT, 2, COMMENTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Episodes.GetEpisodeCommentsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, COMMENT_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(1);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeFalse();
response.HasNextPage.Should().BeTrue();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeCommments_Paging_Not_HasPreviousPage_Or_HasNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 1, LIMIT, 1, COMMENTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Episodes.GetEpisodeCommentsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, COMMENT_SORT_ORDER, pagedParameters);

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

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeCommments_Paging_GetPreviousPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 2, LIMIT, 2, COMMENTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Episodes.GetEpisodeCommentsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, COMMENT_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeFalse();

TestUtility.ResetMockClient(client, $"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 1, LIMIT, 2, COMMENTS_ITEM_COUNT);

response = await response.GetPreviousPageAsync();

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(1);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeFalse();
response.HasNextPage.Should().BeTrue();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeCommments_Paging_GetNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 1, LIMIT, 2, COMMENTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktComment> response = await client.Episodes.GetEpisodeCommentsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, COMMENT_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(1);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeFalse();
response.HasNextPage.Should().BeTrue();

TestUtility.ResetMockClient(client, $"{GET_EPISODE_COMMENTS_URI}/{COMMENT_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_COMMENTS_JSON, 2, LIMIT, 2, COMMENTS_ITEM_COUNT);

response = await response.GetNextPageAsync();

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(COMMENTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(COMMENTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeFalse();
}

[Theory]
[InlineData(HttpStatusCode.NotFound, typeof(TraktEpisodeNotFoundException))]
[InlineData(HttpStatusCode.Unauthorized, typeof(TraktAuthorizationException))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,170 @@ public async Task Test_TraktEpisodesModule_GetEpisodeLists_Complete()
response.PageCount.Should().HaveValue().And.Be(1);
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeLists_Paging_HasPreviousPage_And_HasNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_LISTS_JSON, 2, LIMIT, 5, LISTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Episodes.GetEpisodeListsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, LIST_TYPE,
LIST_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(LISTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(LISTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(5);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeTrue();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeLists_Paging_Only_HasPreviousPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_LISTS_JSON, 2, LIMIT, 2, LISTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Episodes.GetEpisodeListsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, LIST_TYPE,
LIST_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(LISTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(LISTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeFalse();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeLists_Paging_Only_HasNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_LISTS_JSON, 1, LIMIT, 2, LISTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Episodes.GetEpisodeListsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, LIST_TYPE,
LIST_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(LISTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(LISTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(1);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeFalse();
response.HasNextPage.Should().BeTrue();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeLists_Paging_Not_HasPreviousPage_Or_HasNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_LISTS_JSON, 1, LIMIT, 1, LISTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Episodes.GetEpisodeListsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, LIST_TYPE,
LIST_SORT_ORDER, pagedParameters);

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

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeLists_Paging_GetPreviousPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_LISTS_JSON, 2, LIMIT, 2, LISTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(2, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Episodes.GetEpisodeListsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, LIST_TYPE,
LIST_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(LISTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(LISTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeFalse();

TestUtility.ResetMockClient(client, $"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_LISTS_JSON, 1, LIMIT, 2, LISTS_ITEM_COUNT);

response = await response.GetPreviousPageAsync();

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(LISTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(LISTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(1);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeFalse();
response.HasNextPage.Should().BeTrue();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodeLists_Paging_GetNextPage()
{
TraktClient client = TestUtility.GetMockClient($"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=1&limit={LIMIT}",
EPISODE_LISTS_JSON, 1, LIMIT, 2, LISTS_ITEM_COUNT);

var pagedParameters = new TraktPagedParameters(1, LIMIT);
TraktPagedResponse<ITraktList> response = await client.Episodes.GetEpisodeListsAsync(SHOW_ID, SEASON_NR, EPISODE_NR, LIST_TYPE,
LIST_SORT_ORDER, pagedParameters);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(LISTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(LISTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(1);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeFalse();
response.HasNextPage.Should().BeTrue();

TestUtility.ResetMockClient(client, $"{GET_EPISODE_LISTS_URI}/{LIST_TYPE.UriName}/{LIST_SORT_ORDER.UriName}?page=2&limit={LIMIT}",
EPISODE_LISTS_JSON, 2, LIMIT, 2, LISTS_ITEM_COUNT);

response = await response.GetNextPageAsync();

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
response.HasValue.Should().BeTrue();
response.Value.Should().NotBeNull().And.HaveCount(LISTS_ITEM_COUNT);
response.ItemCount.Should().HaveValue().And.Be(LISTS_ITEM_COUNT);
response.Limit.Should().Be(LIMIT);
response.Page.Should().Be(2);
response.PageCount.Should().HaveValue().And.Be(2);
response.HasPreviousPage.Should().BeTrue();
response.HasNextPage.Should().BeFalse();
}

[Theory]
[InlineData(HttpStatusCode.NotFound, typeof(TraktEpisodeNotFoundException))]
[InlineData(HttpStatusCode.Unauthorized, typeof(TraktAuthorizationException))]
Expand Down

0 comments on commit 0f89ffc

Please sign in to comment.