Skip to content

Commit

Permalink
Fix ArtistGetTopTagsCommandTests
Browse files Browse the repository at this point in the history
- also add validation to Artist.GetTopTagsCommand.
  • Loading branch information
rikkit committed May 26, 2016
1 parent 8ea1a0c commit 68e36f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ArtistGetTopTagsCommandTests : CommandTestsBase
[SetUp]
public void Initialise()
{
_command = new GetTopTagsCommand(MAuth.Object, "");
_command = new GetTopTagsCommand(MAuth.Object);
}

[Test]
Expand Down
23 changes: 18 additions & 5 deletions src/IF.Lastfm.Core/Api/Commands/Artist/GetTopTagsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,36 @@ internal class GetTopTagsCommand : GetAsyncCommandBase<PageResponse<LastTag>>

public GetTopTagsCommand(ILastAuth auth) : base(auth)
{

}

public override void SetParameters()
{
if (ArtistMbid != null)
var hasMbid = !string.IsNullOrEmpty(ArtistMbid);
var hasName = !string.IsNullOrEmpty(ArtistName);

if (!hasMbid && !hasName)
{
throw new InvalidOperationException($"Either {nameof(ArtistMbid)} or {nameof(ArtistName)} must be set");
}

if (hasMbid && hasName)
{
throw new InvalidOperationException($"");
}

if (hasMbid)
{
Parameters.Add("mbid", ArtistMbid);
}
else
{
Parameters.Add("artist", ArtistName);
}

Parameters.Add("autocorrect", Convert.ToInt32(Autocorrect).ToString());
}

public async override Task<PageResponse<LastTag>> HandleResponse(HttpResponseMessage response)
public override async Task<PageResponse<LastTag>> HandleResponse(HttpResponseMessage response)
{
var json = await response.Content.ReadAsStringAsync();

Expand All @@ -47,7 +60,7 @@ public async override Task<PageResponse<LastTag>> HandleResponse(HttpResponseMes
var resultsToken = jtoken.SelectToken("toptags");
var itemsToken = resultsToken.SelectToken("tag");

return PageResponse<LastTag>.CreateSuccessResponse(itemsToken, token => LastTag.ParseJToken(token));
return PageResponse<LastTag>.CreateSuccessResponse(itemsToken, LastTag.ParseJToken);
}
else
{
Expand Down

0 comments on commit 68e36f0

Please sign in to comment.