From a06f01bfa7f16bd3f1ccd82159c13d0a98913de3 Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Sat, 4 Apr 2015 14:57:21 +0100 Subject: [PATCH] Fixing the change from yesterday --- src/IF.Lastfm.Core.Tests/LastFmTests.cs | 20 +++++++++++++++++++ .../Api/Commands/Album/GetInfoCommand.cs | 1 - src/IF.Lastfm.Core/LastFm.cs | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/IF.Lastfm.Core.Tests/LastFmTests.cs b/src/IF.Lastfm.Core.Tests/LastFmTests.cs index 614433a..7704a35 100644 --- a/src/IF.Lastfm.Core.Tests/LastFmTests.cs +++ b/src/IF.Lastfm.Core.Tests/LastFmTests.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.Text; +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Tests.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -21,5 +24,22 @@ public void ApiUrlFormatReturnsCorrectly() Assert.AreEqual(expected, actual); } + + [TestMethod] + public void IsResponseValid() + { + LastResponseStatus status; + + Assert.IsFalse(LastFm.IsResponseValid(null, out status)); + Assert.IsFalse(LastFm.IsResponseValid("{invalid json", out status)); + + var error6 = Encoding.UTF8.GetString(ArtistApiResponses.ArtistGetTagsError); + Assert.IsFalse(LastFm.IsResponseValid(error6, out status)); + Assert.AreEqual(LastResponseStatus.MissingParameters, status); + + var goodResponse = Encoding.UTF8.GetString(ArtistApiResponses.ArtistGetInfoSuccess); + Assert.IsTrue(LastFm.IsResponseValid(goodResponse, out status)); + Assert.AreEqual(LastResponseStatus.Successful, status); + } } } diff --git a/src/IF.Lastfm.Core/Api/Commands/Album/GetInfoCommand.cs b/src/IF.Lastfm.Core/Api/Commands/Album/GetInfoCommand.cs index 138fd8c..3a2c5f0 100644 --- a/src/IF.Lastfm.Core/Api/Commands/Album/GetInfoCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/Album/GetInfoCommand.cs @@ -67,5 +67,4 @@ public async override Task> HandleResponse(HttpResponseM } } } - } diff --git a/src/IF.Lastfm.Core/LastFm.cs b/src/IF.Lastfm.Core/LastFm.cs index efce964..13f8f09 100644 --- a/src/IF.Lastfm.Core/LastFm.cs +++ b/src/IF.Lastfm.Core/LastFm.cs @@ -102,7 +102,7 @@ public static bool IsResponseValid(string json, out LastResponseStatus status) return false; } - var codeString = jo.Value("Status"); + var codeString = jo.Value("error"); if (string.IsNullOrWhiteSpace(codeString) && json.Length > 1) { status = LastResponseStatus.Successful;