From 68e36f01390faa5b42b6ddc8330f85ffe0bbec27 Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Thu, 26 May 2016 23:29:32 +0100 Subject: [PATCH] Fix ArtistGetTopTagsCommandTests - also add validation to Artist.GetTopTagsCommand. --- .../Commands/ArtistGetTopTagsCommandTests.cs | 2 +- .../Api/Commands/Artist/GetTopTagsCommand.cs | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/ArtistGetTopTagsCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/ArtistGetTopTagsCommandTests.cs index dc56bdf6..f2614fe5 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/ArtistGetTopTagsCommandTests.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/ArtistGetTopTagsCommandTests.cs @@ -18,7 +18,7 @@ public class ArtistGetTopTagsCommandTests : CommandTestsBase [SetUp] public void Initialise() { - _command = new GetTopTagsCommand(MAuth.Object, ""); + _command = new GetTopTagsCommand(MAuth.Object); } [Test] diff --git a/src/IF.Lastfm.Core/Api/Commands/Artist/GetTopTagsCommand.cs b/src/IF.Lastfm.Core/Api/Commands/Artist/GetTopTagsCommand.cs index 05d148c0..52f1f468 100644 --- a/src/IF.Lastfm.Core/Api/Commands/Artist/GetTopTagsCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/Artist/GetTopTagsCommand.cs @@ -20,12 +20,24 @@ internal class GetTopTagsCommand : GetAsyncCommandBase> 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); } @@ -33,10 +45,11 @@ public override void SetParameters() { Parameters.Add("artist", ArtistName); } + Parameters.Add("autocorrect", Convert.ToInt32(Autocorrect).ToString()); } - public async override Task> HandleResponse(HttpResponseMessage response) + public override async Task> HandleResponse(HttpResponseMessage response) { var json = await response.Content.ReadAsStringAsync(); @@ -47,7 +60,7 @@ public async override Task> HandleResponse(HttpResponseMes var resultsToken = jtoken.SelectToken("toptags"); var itemsToken = resultsToken.SelectToken("tag"); - return PageResponse.CreateSuccessResponse(itemsToken, token => LastTag.ParseJToken(token)); + return PageResponse.CreateSuccessResponse(itemsToken, LastTag.ParseJToken); } else {