Skip to content

Commit

Permalink
GH-125: Add tests for new requests
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikfroehling committed May 31, 2020
1 parent e2a46fb commit f84109b
Show file tree
Hide file tree
Showing 4 changed files with 767 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
namespace TraktNet.Modules.Tests.TraktEpisodesModule
{
using FluentAssertions;
using System;
using System.Net;
using System.Threading.Tasks;
using Trakt.NET.Tests.Utility;
using Trakt.NET.Tests.Utility.Traits;
using TraktNet.Exceptions;
using TraktNet.Objects.Basic;
using TraktNet.Responses;
using Xunit;

[Category("Modules.Episodes")]
public partial class TraktEpisodesModule_Tests
{
private readonly string GET_EPISODE_PEOPLE_URI = $"shows/{SHOW_ID}/seasons/{SEASON_NR}/episodes/{EPISODE_NR}/people";

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodePeople()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, EPISODE_PEOPLE_JSON);
TraktResponse<ITraktCastAndCrew> response = await client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);

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

ITraktCastAndCrew responseValue = response.Value;

responseValue.Cast.Should().NotBeNull().And.HaveCount(3);
responseValue.Crew.Should().NotBeNull();
responseValue.Crew.Production.Should().NotBeNull().And.HaveCount(2);
responseValue.Crew.Art.Should().NotBeNull().And.HaveCount(1);
responseValue.Crew.Crew.Should().NotBeNull().And.HaveCount(1);
responseValue.Crew.CostumeAndMakeup.Should().BeNull();
responseValue.Crew.Directing.Should().BeNull();
responseValue.Crew.Writing.Should().NotBeNull().And.HaveCount(3);
responseValue.Crew.Sound.Should().NotBeNull().And.HaveCount(1);
responseValue.Crew.Camera.Should().BeNull();
responseValue.Crew.Lighting.Should().BeNull();
responseValue.Crew.VisualEffects.Should().BeNull();
responseValue.Crew.Editing.Should().BeNull();
}

[Fact]
public async Task Test_TraktEpisodesModule_GetEpisodePeople_With_ExtendedInfo()
{
TraktClient client = TestUtility.GetMockClient(
$"{GET_EPISODE_PEOPLE_URI}?extended={EXTENDED_INFO}",
EPISODE_PEOPLE_JSON);

TraktResponse<ITraktCastAndCrew> response = await client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR, EXTENDED_INFO);

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

ITraktCastAndCrew responseValue = response.Value;

responseValue.Cast.Should().NotBeNull().And.HaveCount(3);
responseValue.Crew.Should().NotBeNull();
responseValue.Crew.Production.Should().NotBeNull().And.HaveCount(2);
responseValue.Crew.Art.Should().NotBeNull().And.HaveCount(1);
responseValue.Crew.Crew.Should().NotBeNull().And.HaveCount(1);
responseValue.Crew.CostumeAndMakeup.Should().BeNull();
responseValue.Crew.Directing.Should().BeNull();
responseValue.Crew.Writing.Should().NotBeNull().And.HaveCount(3);
responseValue.Crew.Sound.Should().NotBeNull().And.HaveCount(1);
responseValue.Crew.Camera.Should().BeNull();
responseValue.Crew.Lighting.Should().BeNull();
responseValue.Crew.VisualEffects.Should().BeNull();
responseValue.Crew.Editing.Should().BeNull();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_NotFoundException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.NotFound);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktEpisodeNotFoundException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_AuthorizationException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.Unauthorized);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktAuthorizationException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_BadRequestException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.BadRequest);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktBadRequestException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ForbiddenException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.Forbidden);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktForbiddenException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_MethodNotFoundException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.MethodNotAllowed);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktMethodNotFoundException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ConflictException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.Conflict);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktConflictException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ServerException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.InternalServerError);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktServerException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_BadGatewayException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, HttpStatusCode.BadGateway);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktBadGatewayException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_PreconditionFailedException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)412);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktPreconditionFailedException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ValidationException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)422);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktValidationException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_RateLimitException()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)429);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktRateLimitException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ServerUnavailableException_503()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)503);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktServerUnavailableException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ServerUnavailableException_504()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)504);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktServerUnavailableException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ServerUnavailableException_520()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)520);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktServerUnavailableException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ServerUnavailableException_521()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)521);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktServerUnavailableException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_Throws_ServerUnavailableException_522()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, (HttpStatusCode)522);
Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, EPISODE_NR);
act.Should().Throw<TraktServerUnavailableException>();
}

[Fact]
public void Test_TraktEpisodesModule_GetEpisodePeople_ArgumentExceptions()
{
TraktClient client = TestUtility.GetMockClient(GET_EPISODE_PEOPLE_URI, EPISODE_PEOPLE_JSON);

Func<Task<TraktResponse<ITraktCastAndCrew>>> act = () => client.Episodes.GetEpisodePeopleAsync(null, SEASON_NR, EPISODE_NR);
act.Should().Throw<ArgumentException>();

act = () => client.Episodes.GetEpisodePeopleAsync(string.Empty, SEASON_NR, EPISODE_NR);
act.Should().Throw<ArgumentException>();

act = () => client.Episodes.GetEpisodePeopleAsync("show id", SEASON_NR, EPISODE_NR);
act.Should().Throw<ArgumentException>();

act = () => client.Episodes.GetEpisodePeopleAsync(SHOW_ID, SEASON_NR, 0);
act.Should().Throw<ArgumentOutOfRangeException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,166 @@ public partial class TraktEpisodesModule_Tests
""vip_ep"": true
}
]";

private const string EPISODE_PEOPLE_JSON =
@"{
""cast"": [
{
""character"": ""Rick Grimes"",
""person"": {
""name"": ""Andrew Lincoln"",
""ids"": {
""trakt"": 413156,
""slug"": ""andrew-lincoln"",
""imdb"": ""nm0511088"",
""tmdb"": 7062,
""tvrage"": 61194
}
}
},
{
""character"": ""Daryl Dixon"",
""person"": {
""name"": ""Norman Reedus"",
""ids"": {
""trakt"": 5158,
""slug"": ""norman-reedus"",
""imdb"": ""nm0005342"",
""tmdb"": 4886,
""tvrage"": 26542
}
}
},
{
""character"": ""Glenn Rhee"",
""person"": {
""name"": ""Steven Yeun"",
""ids"": {
""trakt"": 436936,
""slug"": ""steven-yeun"",
""imdb"": ""nm3081796"",
""tmdb"": 215055,
""tvrage"": null
}
}
}
],
""crew"": {
""production"": [
{
""job"": ""Casting"",
""person"": {
""name"": ""Sharon Bialy"",
""ids"": {
""trakt"": 3025,
""slug"": ""sharon-bialy"",
""imdb"": ""nm0080544"",
""tmdb"": 6479,
""tvrage"": null
}
}
},
{
""job"": ""Executive Producer"",
""person"": {
""name"": ""Gregory Nicotero"",
""ids"": {
""trakt"": 6779,
""slug"": ""gregory-nicotero"",
""imdb"": ""nm0630524"",
""tmdb"": 59287,
""tvrage"": null
}
}
}
],
""crew"": [
{
""job"": ""Makeup Effects"",
""person"": {
""name"": ""Gregory Nicotero"",
""ids"": {
""trakt"": 6779,
""slug"": ""gregory-nicotero"",
""imdb"": ""nm0630524"",
""tmdb"": 59287,
""tvrage"": null
}
}
}
],
""art"": [
{
""job"": ""Production Design"",
""person"": {
""name"": ""Graham 'Grace' Walker"",
""ids"": {
""trakt"": 42993,
""slug"": ""graham-grace-walker"",
""imdb"": ""nm0907767"",
""tmdb"": 62743,
""tvrage"": null
}
}
}
],
""sound"": [
{
""job"": ""Music"",
""person"": {
""name"": ""Bear McCreary"",
""ids"": {
""trakt"": 45352,
""slug"": ""bear-mccreary"",
""imdb"": ""nm0566970"",
""tmdb"": 59811,
""tvrage"": null
}
}
}
],
""writing"": [
{
""job"": ""Comic Book"",
""person"": {
""name"": ""Robert Kirkman"",
""ids"": {
""trakt"": 214252,
""slug"": ""robert-kirkman"",
""imdb"": ""nm3079117"",
""tmdb"": 1223867,
""tvrage"": 330021
}
}
},
{
""job"": ""Comic Book"",
""person"": {
""name"": ""Charlie Adlard"",
""ids"": {
""trakt"": 466776,
""slug"": ""charlie-adlard"",
""imdb"": ""nm1891501"",
""tmdb"": 1223881,
""tvrage"": null
}
}
},
{
""job"": ""Comic Book"",
""person"": {
""name"": ""Tony Moore"",
""ids"": {
""trakt"": 570113,
""slug"": ""tony-moore"",
""imdb"": ""nm3877885"",
""tmdb"": 1223882,
""tvrage"": null
}
}
}
]
}
}";
}
}
Loading

0 comments on commit f84109b

Please sign in to comment.