From 894d81c7407c913d2d5853bacd4f0e542c0b2e7f Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Sun, 16 Apr 2017 19:03:35 +0100 Subject: [PATCH] Add small integration test for Lastfm.User.GetInfoAsync() - proves #100 is fixed, can add checks for the other fields later --- .../Commands/UserGetInfoTests.cs | 22 +++++++++++++++++++ .../IF.Lastfm.Core.Tests.Integration.csproj | 1 + .../Api/Commands/User/GetInfoCommand.cs | 3 +-- src/IF.Lastfm.Core/Objects/LastUser.cs | 8 ++----- 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/IF.Lastfm.Core.Tests.Integration/Commands/UserGetInfoTests.cs diff --git a/src/IF.Lastfm.Core.Tests.Integration/Commands/UserGetInfoTests.cs b/src/IF.Lastfm.Core.Tests.Integration/Commands/UserGetInfoTests.cs new file mode 100644 index 0000000..6cf0704 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests.Integration/Commands/UserGetInfoTests.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; + +namespace IF.Lastfm.Core.Tests.Integration.Commands +{ + public class UserGetInfoTests : CommandIntegrationTestsBase + { + [Test] + public async Task GetInfo_Success() + { + var response = await Lastfm.User.GetInfoAsync(INTEGRATION_TEST_USER); + var user = response.Content; + + Assert.AreEqual(INTEGRATION_TEST_USER, user.Name); + Assert.IsTrue(user.Playcount > 0); + } + } +} diff --git a/src/IF.Lastfm.Core.Tests.Integration/IF.Lastfm.Core.Tests.Integration.csproj b/src/IF.Lastfm.Core.Tests.Integration/IF.Lastfm.Core.Tests.Integration.csproj index a4c8a0e..bc90c6c 100644 --- a/src/IF.Lastfm.Core.Tests.Integration/IF.Lastfm.Core.Tests.Integration.csproj +++ b/src/IF.Lastfm.Core.Tests.Integration/IF.Lastfm.Core.Tests.Integration.csproj @@ -73,6 +73,7 @@ + diff --git a/src/IF.Lastfm.Core/Api/Commands/User/GetInfoCommand.cs b/src/IF.Lastfm.Core/Api/Commands/User/GetInfoCommand.cs index 5346d46..a885cc4 100644 --- a/src/IF.Lastfm.Core/Api/Commands/User/GetInfoCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/User/GetInfoCommand.cs @@ -29,8 +29,7 @@ public override async Task> HandleResponse(HttpResponseMe { var json = await response.Content.ReadAsStringAsync(); - LastResponseStatus status; - if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode) + if (LastFm.IsResponseValid(json, out LastResponseStatus status) && response.IsSuccessStatusCode) { var jtoken = JsonConvert.DeserializeObject(json); var userToken = jtoken.SelectToken("user"); diff --git a/src/IF.Lastfm.Core/Objects/LastUser.cs b/src/IF.Lastfm.Core/Objects/LastUser.cs index a62a958..d0f081b 100644 --- a/src/IF.Lastfm.Core/Objects/LastUser.cs +++ b/src/IF.Lastfm.Core/Objects/LastUser.cs @@ -7,8 +7,6 @@ namespace IF.Lastfm.Core.Objects { public class LastUser : ILastfmObject { - #region Properties - public string Name { get; private set; } public string FullName { get; private set; } public LastImageSet Avatar { get; private set; } @@ -23,8 +21,6 @@ public class LastUser : ILastfmObject public int Bootstrap { get; private set; } public string Type { get; private set; } - #endregion - /// /// Parses the given to a /// . @@ -33,7 +29,7 @@ public class LastUser : ILastfmObject /// Parsed LastUser. internal static LastUser ParseJToken(JToken token) { - var u = new LastUser() + var u = new LastUser { Name = token.Value("name"), FullName = token.Value("realname"), @@ -43,7 +39,7 @@ internal static LastUser ParseJToken(JToken token) Playlists = token.Value("playlists"), Gender = ParseGender(token.Value("gender")), IsSubscriber = Convert.ToBoolean(token.Value("subscriber")), - TimeRegistered = token.SelectToken("registered").Value("unixtime").FromUnixTime().DateTime, + TimeRegistered = token.Value("registered.unixtime").FromUnixTime().DateTime, Bootstrap = token.Value("bootstrap"), Type = token.Value("type") };