Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Commit

Permalink
GH-109: Add request implementation for comment like
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikfroehling committed Jun 15, 2018
1 parent 7feba0c commit 6e1b42a
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Source/Lib/TraktApiSharp/Requests/Comments/CommentLikesRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace TraktApiSharp.Requests.Comments
{
using Base;
using Extensions;
using Interfaces;
using Objects.Basic;
using Parameters;
using System;
using System.Collections.Generic;

internal sealed class CommentLikesRequest : AGetRequest<ITraktCommentLike>, IHasId, ISupportsExtendedInfo, ISupportsPagination
{
public string Id { get; set; }

public TraktExtendedInfo ExtendedInfo { get; set; }

public RequestObjectType RequestObjectType => RequestObjectType.Comments;

public uint? Page { get; set; }

public uint? Limit { get; set; }

public override string UriTemplate => "comments/{id}/likes{?extended,page,limit}";

public override IDictionary<string, object> GetUriPathParameters()
{
var uriParams = new Dictionary<string, object>
{
["id"] = Id
};

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

if (Page.HasValue)
uriParams.Add("page", Page.Value.ToString());

if (Limit.HasValue)
uriParams.Add("limit", Limit.Value.ToString());

return uriParams;
}

public override void Validate()
{
if (Id == null)
throw new ArgumentNullException(nameof(Id));

if (Id == string.Empty || Id.ContainsSpace())
throw new ArgumentException("comment id not valid", nameof(Id));
}
}
}
1 change: 1 addition & 0 deletions Source/Lib/TraktApiSharp/TraktApiSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@
<Compile Include="Requests\Certifications\MovieCertificationsRequest.cs" />
<Compile Include="Requests\Certifications\ShowCertificationsRequest.cs" />
<Compile Include="Requests\Comments\CommentItemRequest.cs" />
<Compile Include="Requests\Comments\CommentLikesRequest.cs" />
<Compile Include="Requests\Episodes\AEpisodeRequest%271.cs" />
<Compile Include="Requests\Episodes\EpisodeListsRequest.cs" />
<Compile Include="Requests\Episodes\EpisodeTranslationsRequest.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
namespace TraktApiSharp.Tests.Requests.Comments
{
using FluentAssertions;
using System;
using System.Collections;
using System.Collections.Generic;
using Traits;
using TraktApiSharp.Requests.Base;
using TraktApiSharp.Requests.Comments;
using TraktApiSharp.Requests.Parameters;
using Xunit;

[Category("Requests.Comments")]
public class CommentLikesRequest_Tests
{
[Fact]
public void Test_CommentLikesRequest_Has_AuthorizationRequirement_NotRequired()
{
var request = new CommentLikesRequest();
request.AuthorizationRequirement.Should().Be(AuthorizationRequirement.NotRequired);
}

[Fact]
public void Test_CommentLikesRequest_Returns_Valid_RequestObjectType()
{
var request = new CommentLikesRequest();
request.RequestObjectType.Should().Be(RequestObjectType.Comments);
}

[Fact]
public void Test_CommentLikesRequest_Has_Valid_UriTemplate()
{
var request = new CommentLikesRequest();
request.UriTemplate.Should().Be("comments/{id}/likes{?extended,page,limit}");
}

[Fact]
public void Test_CommentLikesRequest_Validate_Throws_Exceptions()
{
// id is null
var request = new CommentLikesRequest();

Action act = () => request.Validate();
act.Should().Throw<ArgumentNullException>();

// empty id
request = new CommentLikesRequest { Id = string.Empty };

act = () => request.Validate();
act.Should().Throw<ArgumentException>();

// id with spaces
request = new CommentLikesRequest { Id = "invalid id" };

act = () => request.Validate();
act.Should().Throw<ArgumentException>();
}

[Theory, ClassData(typeof(CommentLikesRequest_TestData))]
public void Test_CommentLikesRequest_Returns_Valid_UriPathParameters(IDictionary<string, object> values,
IDictionary<string, object> expected)
{
values.Should().NotBeNull().And.HaveCount(expected.Count);

if (expected.Count > 0)
values.Should().Contain(expected);
}

public class CommentLikesRequest_TestData : IEnumerable<object[]>
{
private const string _id = "123";
private static readonly TraktExtendedInfo _extendedInfo = new TraktExtendedInfo { Full = true };
private const int _page = 5;
private const int _limit = 20;

private static readonly CommentLikesRequest _request1 = new CommentLikesRequest
{
Id = _id
};

private static readonly CommentLikesRequest _request2 = new CommentLikesRequest
{
Id = _id,
Page = _page
};

private static readonly CommentLikesRequest _request3 = new CommentLikesRequest
{
Id = _id,
Limit = _limit
};

private static readonly CommentLikesRequest _request4 = new CommentLikesRequest
{
Id = _id,
Page = _page,
Limit = _limit
};

private static readonly CommentLikesRequest _request5 = new CommentLikesRequest
{
Id = _id,
ExtendedInfo = _extendedInfo
};

private static readonly CommentLikesRequest _request6 = new CommentLikesRequest
{
Id = _id,
ExtendedInfo = _extendedInfo,
Page = _page
};

private static readonly CommentLikesRequest _request7 = new CommentLikesRequest
{
Id = _id,
ExtendedInfo = _extendedInfo,
Limit = _limit
};

private static readonly CommentLikesRequest _request8 = new CommentLikesRequest
{
Id = _id,
ExtendedInfo = _extendedInfo,
Page = _page,
Limit = _limit
};

private static readonly List<object[]> _data = new List<object[]>();

public CommentLikesRequest_TestData()
{
SetupPathParamters();
}

private void SetupPathParamters()
{
var strExtendedInfo = _extendedInfo.ToString();
var strPage = _page.ToString();
var strLimit = _limit.ToString();

_data.Add(new object[] { _request1.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id
}});

_data.Add(new object[] { _request2.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["page"] = strPage
}});

_data.Add(new object[] { _request3.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["limit"] = strLimit
}});

_data.Add(new object[] { _request4.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["page"] = strPage,
["limit"] = strLimit
}});

_data.Add(new object[] { _request5.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["extended"] = strExtendedInfo
}});

_data.Add(new object[] { _request6.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["extended"] = strExtendedInfo,
["page"] = strPage
}});

_data.Add(new object[] { _request7.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["extended"] = strExtendedInfo,
["limit"] = strLimit
}});

_data.Add(new object[] { _request8.GetUriPathParameters(), new Dictionary<string, object>
{
["id"] = _id,
["extended"] = strExtendedInfo,
["page"] = strPage,
["limit"] = strLimit
}});
}

public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@
<Compile Include="Requests\Checkins\OAuth\CheckinRequest%272_Tests.cs" />
<Compile Include="Requests\Checkins\OAuth\CheckinsDeleteRequest_Tests.cs" />
<Compile Include="Requests\Comments\CommentItemRequest_Tests.cs" />
<Compile Include="Requests\Comments\CommentLikesRequest_Tests.cs" />
<Compile Include="Requests\Comments\OAuth\CommentDeleteRequest_Tests.cs" />
<Compile Include="Requests\Comments\OAuth\CommentLikeRequest_Tests.cs" />
<Compile Include="Requests\Comments\OAuth\CommentPostRequest%271_Tests.cs" />
Expand Down

0 comments on commit 6e1b42a

Please sign in to comment.