-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-586: Add support for "lists/{id}/like" DELETE request
- Loading branch information
1 parent
fd74168
commit fb410d8
Showing
5 changed files
with
334 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace TraktNet.Requests.Lists | ||
{ | ||
using Base; | ||
using Exceptions; | ||
using Extensions; | ||
using Interfaces; | ||
using System.Collections.Generic; | ||
|
||
internal sealed class ListUnlikeRequest : ADeleteRequest, IHasId | ||
{ | ||
public string Id { get; set; } | ||
|
||
public RequestObjectType RequestObjectType => RequestObjectType.Lists; | ||
|
||
public override string UriTemplate => "lists/{id}/like"; | ||
|
||
public override IDictionary<string, object> GetUriPathParameters() | ||
=> new Dictionary<string, object> | ||
{ | ||
["id"] = Id | ||
}; | ||
|
||
public override void Validate() | ||
{ | ||
if (Id == null) | ||
throw new TraktRequestValidationException(nameof(Id), "list id must not be null"); | ||
|
||
if (Id == string.Empty || Id.ContainsSpace()) | ||
throw new TraktRequestValidationException(nameof(Id), "list id not valid"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
Source/Tests/Trakt.NET.Modules.Tests/TraktListsModule/TraktListsModule_UnlikeList_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
namespace TraktNet.Modules.Tests.TraktListsModule | ||
{ | ||
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.Get.Lists; | ||
using TraktNet.Responses; | ||
using Xunit; | ||
|
||
[TestCategory("Modules.Lists")] | ||
public partial class TraktListsModule_Tests | ||
{ | ||
private readonly string UNLIKE_LIST_URI = $"lists/{LIST_ID}/like"; | ||
|
||
[Fact] | ||
public async Task Test_TraktListsModule_UnlikeList() | ||
{ | ||
TraktClient client = TestUtility.GetOAuthMockClient(UNLIKE_LIST_URI, HttpStatusCode.NoContent); | ||
TraktNoContentResponse response = await client.Lists.UnlikeListAsync(LIST_ID); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_TraktListsModule_UnlikeList_With_TraktID() | ||
{ | ||
const uint traktID = 55; | ||
|
||
TraktClient client = TestUtility.GetOAuthMockClient($"lists/{traktID}/like", HttpStatusCode.NoContent); | ||
TraktNoContentResponse response = await client.Lists.UnlikeListAsync(traktID); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_TraktListsModule_UnlikeList_With_ListIds_TraktID() | ||
{ | ||
const uint traktID = 55; | ||
|
||
var listIds = new TraktListIds | ||
{ | ||
Trakt = traktID | ||
}; | ||
|
||
TraktClient client = TestUtility.GetOAuthMockClient($"lists/{traktID}/like", HttpStatusCode.NoContent); | ||
TraktNoContentResponse response = await client.Lists.UnlikeListAsync(listIds); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_TraktListsModule_UnlikeList_With_ListIds_Slug() | ||
{ | ||
const string listSlug = "incredible-thoughts"; | ||
|
||
var listIds = new TraktListIds | ||
{ | ||
Slug = listSlug | ||
}; | ||
|
||
TraktClient client = TestUtility.GetOAuthMockClient($"lists/{listSlug}/like", HttpStatusCode.NoContent); | ||
TraktNoContentResponse response = await client.Lists.UnlikeListAsync(listIds); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_TraktListsModule_UnlikeList_With_ListIds() | ||
{ | ||
const uint traktID = 55; | ||
const string listSlug = "incredible-thoughts"; | ||
|
||
var listIds = new TraktListIds | ||
{ | ||
Trakt = traktID, | ||
Slug = listSlug | ||
}; | ||
|
||
TraktClient client = TestUtility.GetOAuthMockClient($"lists/{traktID}/like", HttpStatusCode.NoContent); | ||
TraktNoContentResponse response = await client.Lists.UnlikeListAsync(listIds); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(HttpStatusCode.NotFound, typeof(TraktListNotFoundException))] | ||
[InlineData(HttpStatusCode.Unauthorized, typeof(TraktAuthorizationException))] | ||
[InlineData(HttpStatusCode.BadRequest, typeof(TraktBadRequestException))] | ||
[InlineData(HttpStatusCode.Forbidden, typeof(TraktForbiddenException))] | ||
[InlineData(HttpStatusCode.MethodNotAllowed, typeof(TraktMethodNotFoundException))] | ||
[InlineData(HttpStatusCode.Conflict, typeof(TraktConflictException))] | ||
[InlineData(HttpStatusCode.InternalServerError, typeof(TraktServerException))] | ||
[InlineData(HttpStatusCode.BadGateway, typeof(TraktBadGatewayException))] | ||
[InlineData(HttpStatusCode.PreconditionFailed, typeof(TraktPreconditionFailedException))] | ||
[InlineData(HttpStatusCode.UnprocessableEntity, typeof(TraktValidationException))] | ||
[InlineData(HttpStatusCode.TooManyRequests, typeof(TraktRateLimitException))] | ||
[InlineData(HttpStatusCode.ServiceUnavailable, typeof(TraktServerUnavailableException))] | ||
[InlineData(HttpStatusCode.GatewayTimeout, typeof(TraktServerUnavailableException))] | ||
[InlineData((HttpStatusCode)520, typeof(TraktServerUnavailableException))] | ||
[InlineData((HttpStatusCode)521, typeof(TraktServerUnavailableException))] | ||
[InlineData((HttpStatusCode)522, typeof(TraktServerUnavailableException))] | ||
public async Task Test_TraktListsModule_UnlikeList_Throws_API_Exception(HttpStatusCode statusCode, Type exceptionType) | ||
{ | ||
TraktClient client = TestUtility.GetOAuthMockClient(UNLIKE_LIST_URI, statusCode); | ||
|
||
try | ||
{ | ||
await client.Lists.UnlikeListAsync(LIST_ID); | ||
Assert.False(true); | ||
} | ||
catch (Exception exception) | ||
{ | ||
(exception.GetType() == exceptionType).Should().BeTrue(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Test_TraktListsModule_UnlikeList_Throws_ArgumentExceptions() | ||
{ | ||
TraktClient client = TestUtility.GetOAuthMockClient(UNLIKE_LIST_URI, HttpStatusCode.NoContent); | ||
|
||
Func<Task<TraktNoContentResponse>> act = () => client.Lists.UnlikeListAsync(default(ITraktListIds)); | ||
await act.Should().ThrowAsync<ArgumentNullException>(); | ||
|
||
act = () => client.Lists.UnlikeListAsync(0); | ||
await act.Should().ThrowAsync<ArgumentException>(); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Source/Tests/Trakt.NET.Requests.Tests/Lists/ListUnlikeRequest_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace TraktNet.Requests.Tests.Lists | ||
{ | ||
using FluentAssertions; | ||
using System; | ||
using System.Collections.Generic; | ||
using Trakt.NET.Tests.Utility.Traits; | ||
using TraktNet.Exceptions; | ||
using TraktNet.Requests.Base; | ||
using TraktNet.Requests.Lists; | ||
using Xunit; | ||
|
||
[TestCategory("Requests.Lists")] | ||
public class ListUnlikeRequest_Tests | ||
{ | ||
[Fact] | ||
public void Test_ListUnlikeRequest_Has_AuthorizationRequirement_Required() | ||
{ | ||
var request = new ListUnlikeRequest(); | ||
request.AuthorizationRequirement.Should().Be(AuthorizationRequirement.Required); | ||
} | ||
|
||
[Fact] | ||
public void Test_ListUnlikeRequest_Returns_Valid_RequestObjectType() | ||
{ | ||
var requestMock = new ListUnlikeRequest(); | ||
requestMock.RequestObjectType.Should().Be(RequestObjectType.Lists); | ||
} | ||
|
||
[Fact] | ||
public void Test_ListUnlikeRequest_Has_Valid_UriTemplate() | ||
{ | ||
var request = new ListUnlikeRequest(); | ||
request.UriTemplate.Should().Be("lists/{id}/like"); | ||
} | ||
|
||
[Fact] | ||
public void Test_ListUnlikeRequest_Returns_Valid_UriPathParameters() | ||
{ | ||
var request = new ListUnlikeRequest { Id = "123" }; | ||
|
||
request.GetUriPathParameters().Should().NotBeNull() | ||
.And.HaveCount(1) | ||
.And.Contain(new Dictionary<string, object> | ||
{ | ||
["id"] = "123" | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void Test_ListUnlikeRequest_Validate_Throws_Exceptions() | ||
{ | ||
// id is null | ||
var request = new ListUnlikeRequest(); | ||
|
||
Action act = () => request.Validate(); | ||
act.Should().Throw<TraktRequestValidationException>(); | ||
|
||
// empty id | ||
request = new ListUnlikeRequest { Id = string.Empty }; | ||
|
||
act = () => request.Validate(); | ||
act.Should().Throw<TraktRequestValidationException>(); | ||
|
||
// id with spaces | ||
request = new ListUnlikeRequest { Id = "invalid id" }; | ||
|
||
act = () => request.Validate(); | ||
act.Should().Throw<TraktRequestValidationException>(); | ||
} | ||
} | ||
} |