From c90c65ff8da837795ee210b55a335fa76230df28 Mon Sep 17 00:00:00 2001 From: Peter Curd Date: Thu, 18 Dec 2014 19:30:01 +0000 Subject: [PATCH 01/11] Added LibraryAPI class, interface, resource, and tests. Initial code for Library.getTracks method. Updated LastImageSet object to allow optional Mega size. --- .../IF.Lastfm.Core.Tests.csproj | 11 ++ .../LibraryApi/LibraryGetTracksSingle.json | 50 +++++++ .../Resources/LibraryApiResponses.Designer.cs | 73 +++++++++++ .../Resources/LibraryApiResponses.resx | 124 ++++++++++++++++++ .../Commands/LibraryApi/GetTracksCommand.cs | 76 +++++++++++ src/IF.Lastfm.Core/Api/ILibraryAPI.cs | 21 +++ src/IF.Lastfm.Core/Api/LibraryApi.cs | 35 +++++ src/IF.Lastfm.Core/IF.Lastfm.Core.csproj | 3 + src/IF.Lastfm.Core/Objects/LastImageSet.cs | 6 +- 9 files changed, 397 insertions(+), 2 deletions(-) create mode 100644 src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksSingle.json create mode 100644 src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs create mode 100644 src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx create mode 100644 src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs create mode 100644 src/IF.Lastfm.Core/Api/ILibraryAPI.cs create mode 100644 src/IF.Lastfm.Core/Api/LibraryApi.cs diff --git a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj index 06c2327..a672e66 100644 --- a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj +++ b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj @@ -79,6 +79,7 @@ + @@ -91,6 +92,11 @@ True AlbumApiResponses.resx + + True + True + LibraryApiResponses.resx + TrackApiResponses.resx True @@ -116,6 +122,7 @@ + @@ -133,6 +140,10 @@ ResXFileCodeGenerator AlbumApiResponses.Designer.cs + + ResXFileCodeGenerator + LibraryApiResponses.Designer.cs + ResXFileCodeGenerator TrackApiResponses.Designer.cs diff --git a/src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksSingle.json b/src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksSingle.json new file mode 100644 index 0000000..a8ae246 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksSingle.json @@ -0,0 +1,50 @@ +{ + "tracks": { + "track": { + "name": "Sultans of Swing", + "duration": "347000", + "playcount": "81", + "tagcount": "0", + "mbid": "0317e524-7f70-4910-bc12-95dd468a29fc", + "url": "http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dire Straits", + "mbid": "614e3804-7d34-41ba-857f-811bad7c2b7a", + "url": "http://www.last.fm/music/Dire+Straits" + }, + "album": { + "name": "Dire Straits (Remastered)", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/56827829.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/56827829.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/56827829.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/56827829.jpg", + "size": "extralarge" + } + ] + }, + "@attr": { + "user": "RJ", + "page": "0", + "perPage": "1", + "totalPages": "38949", + "total": "38949" + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs new file mode 100644 index 0000000..d52215c --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18444 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace IF.Lastfm.Core.Tests.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class LibraryApiResponses { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal LibraryApiResponses() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("IF.Lastfm.Core.Tests.Resources.LibraryApiResponses", typeof(LibraryApiResponses).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] LibraryGetTracksSingle { + get { + object obj = ResourceManager.GetObject("LibraryGetTracksSingle", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx new file mode 100644 index 0000000..eeba830 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + libraryapi\librarygettrackssingle.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs new file mode 100644 index 0000000..3688ae2 --- /dev/null +++ b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs @@ -0,0 +1,76 @@ +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Api.Helpers; +using IF.Lastfm.Core.Objects; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +namespace IF.Lastfm.Core.Api.Commands.LibraryApi +{ + internal class GetTracksCommand : GetAsyncCommandBase> + { + public string Username { get; private set; } + + public string Artist { get; private set; } + + public string Album { get; private set; } + + public DateTime From { get; private set; } + + public GetTracksCommand(ILastAuth auth, string username, string artist, string album, DateTime from) : base(auth) + { + Method = "library.getTracks"; + + Username = username; + Artist = artist; + Album = album; + From = from; + } + + public override void SetParameters() + { + Parameters.Add("user", Username); + Parameters.Add("artist", Artist); + Parameters.Add("album", Album); + Parameters.Add("from", From.ToUnixTimestamp().ToString()); + + AddPagingParameters(); + DisableCaching(); + } + + public async override Task> HandleResponse(HttpResponseMessage response) + { + var json = await response.Content.ReadAsStringAsync(); + + LastFmApiError error; + if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode) + { + JToken jtoken = JsonConvert.DeserializeObject(json).SelectToken("tracks"); + + var tracksToken = jtoken.SelectToken("track"); + + var tracks = new List(); + foreach (var track in tracksToken.Children()) + { + var t = LastTrack.ParseJToken(track); + + tracks.Add(t); + } + + var pageresponse = PageResponse.CreateSuccessResponse(tracks); + + var attrToken = jtoken.SelectToken("@attr"); + pageresponse.AddPageInfoFromJToken(attrToken); + + return pageresponse; + } + else + { + return LastResponse.CreateErrorResponse>(error); + } + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core/Api/ILibraryAPI.cs b/src/IF.Lastfm.Core/Api/ILibraryAPI.cs new file mode 100644 index 0000000..486f302 --- /dev/null +++ b/src/IF.Lastfm.Core/Api/ILibraryAPI.cs @@ -0,0 +1,21 @@ +using System; +using System.Threading.Tasks; +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Api.Helpers; +using IF.Lastfm.Core.Objects; + +namespace IF.Lastfm.Core.Api +{ + public interface ILibraryApi + { + ILastAuth Auth { get; } + + Task> GetTracks(string username, + string artist, + string album, + DateTime since, + int startIndex = 0, + int endIndex = LastFm.DefaultPageLength); + + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core/Api/LibraryApi.cs b/src/IF.Lastfm.Core/Api/LibraryApi.cs new file mode 100644 index 0000000..4062984 --- /dev/null +++ b/src/IF.Lastfm.Core/Api/LibraryApi.cs @@ -0,0 +1,35 @@ +using System; +using System.Threading.Tasks; +using IF.Lastfm.Core.Api.Commands.LibraryApi; +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Api.Helpers; +using IF.Lastfm.Core.Objects; + +namespace IF.Lastfm.Core.Api +{ + public class LibraryApi : ILibraryApi + { + public ILastAuth Auth { get; private set; } + + /// + /// Gets scrobbles and stuff + /// + /// + /// + /// + /// + /// + /// + /// + public async Task> GetTracks(string username, string artist, string album, DateTime since, int pagenumber = 0, int count = LastFm.DefaultPageLength) + { + var command = new GetTracksCommand(Auth, username, artist, album, since) + { + Page = pagenumber, + Count = count + }; + + return await command.ExecuteAsync(); + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj b/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj index 1b3ba4d..10fc65c 100644 --- a/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj +++ b/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj @@ -41,7 +41,9 @@ + + @@ -88,6 +90,7 @@ + diff --git a/src/IF.Lastfm.Core/Objects/LastImageSet.cs b/src/IF.Lastfm.Core/Objects/LastImageSet.cs index be479ad..2a536e9 100644 --- a/src/IF.Lastfm.Core/Objects/LastImageSet.cs +++ b/src/IF.Lastfm.Core/Objects/LastImageSet.cs @@ -11,13 +11,15 @@ public LastImageSet() { } - public LastImageSet(string s, string m, string l, string xl, string xxl) + public LastImageSet(string s, string m, string l, string xl, string xxl=null) { Small = new Uri(s); Medium = new Uri(m); Large = new Uri(l); ExtraLarge = new Uri(xl); - Mega = new Uri(xxl); + + if (xxl != null) + Mega = new Uri(xxl); } public Uri Small { get; set; } From 3e90340a80509b50eac8c55c062addc0d0215818 Mon Sep 17 00:00:00 2001 From: Peter Curd Date: Sat, 20 Dec 2014 13:53:27 +0000 Subject: [PATCH 02/11] Added tests for prototype LibraryGetTracks Starter reconstruction of test helper functions Added ApiResponses for User Added tests for GetRecentScrobbles --- .../Api/Commands/CommandTestsBase.cs | 46 + .../Commands/Library/GetTracksCommandTests.cs | 89 ++ .../UserApi/GetRecentScrobblesCommandTests.cs | 169 ++++ .../IF.Lastfm.Core.Tests.csproj | 18 + .../Objects/LastTrackTests.cs | 46 + .../Objects/ObjectsTestsBase.cs | 24 + .../LibraryApi/LibraryGetTracksMultiple.json | 793 ++++++++++++++++++ .../Resources/LibraryApiResponses.Designer.cs | 10 + .../Resources/LibraryApiResponses.resx | 3 + .../UserApi/UserGetRecentTracksEmpty.json | 10 + .../UserApi/UserGetRecentTracksError.json | 5 + .../UserApi/UserGetRecentTracksMissing.json | 5 + .../UserApi/UserGetRecentTracksMultiple.json | 733 ++++++++++++++++ .../UserApi/UserGetRecentTracksSingle.json | 47 ++ .../Resources/UserApiResponses.Designer.cs | 113 +++ .../Resources/UserApiResponses.resx | 136 +++ src/IF.Lastfm.Core/Objects/LastTrack.cs | 4 + 17 files changed, 2251 insertions(+) create mode 100644 src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs create mode 100644 src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs create mode 100644 src/IF.Lastfm.Core.Tests/Objects/LastTrackTests.cs create mode 100644 src/IF.Lastfm.Core.Tests/Objects/ObjectsTestsBase.cs create mode 100644 src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksMultiple.json create mode 100644 src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksEmpty.json create mode 100644 src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksError.json create mode 100644 src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMissing.json create mode 100644 src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMultiple.json create mode 100644 src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksSingle.json create mode 100644 src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs create mode 100644 src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs index 25b61d2..1603a3d 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs @@ -1,5 +1,10 @@ using IF.Lastfm.Core.Api; +using IF.Lastfm.Core.Api.Commands; +using IF.Lastfm.Core.Api.Helpers; +using IF.Lastfm.Core.Objects; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; +using Newtonsoft.Json; using System.Net; using System.Net.Http; using System.Text; @@ -25,5 +30,46 @@ protected HttpResponseMessage CreateResponseMessage(string message) return response; } + + public void CheckResult(object expected, object actual) + { + var expectedJson = JsonConvert.SerializeObject(expected, Formatting.Indented); + var actualJson = JsonConvert.SerializeObject(actual, Formatting.Indented); + + Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); + + + } + + public async Task CheckResult_Single(GetAsyncCommandBase> _command, object expected, byte[] Data) + { + + + var response = CreateResponseMessage(Encoding.UTF8.GetString(Data)); + //Check if object not array + var parsed = await _command.HandleResponse(response); + + Assert.IsTrue(parsed.Success); + + var actual = parsed.Content; + + CheckResult(expected, actual); + + } + + public async Task CheckResult_MultipleSample(GetAsyncCommandBase> _command, object expected, int arrayID, byte[] Data) + { + + + var response = CreateResponseMessage(Encoding.UTF8.GetString(Data)); + var parsed = await _command.HandleResponse(response); + + Assert.IsTrue(parsed.Success); + + var actual = parsed.Content[arrayID]; + + CheckResult(expected, actual); + + } } } diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs new file mode 100644 index 0000000..abf1ef1 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using IF.Lastfm.Core.Api.Commands.LibraryApi; +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Objects; +using IF.Lastfm.Core.Tests.Resources; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace IF.Lastfm.Core.Tests.Api.Commands.LibraryApi +{ + [TestClass] + public class GetTracksCommandTests : CommandTestsBase + { + private GetTracksCommand _command; + + public GetTracksCommandTests() + { + + + _command = new GetTracksCommand(MAuth.Object, "rj", "", "", DateTime.MinValue) + { + Count = 1 + }; + //_command = new GetTracksCommand(MAuth.Object, ) + //{ + // AlbumName = "Ray of Light", + // ArtistName = "Madonna" + //}; + //_command.SetParameters(); + + + } + + + [TestMethod] + public async Task HandleSuccessResponseSingleTrack() + { + + + var expectedTrack = new LastTrack + { + ArtistName = "Dire Straits", + Duration = new TimeSpan(0, 3, 47), + TotalPlayCount = 81, + Mbid = "0317e524-7f70-4910-bc12-95dd468a29fc", + Name = "Sultans of Swing", + ArtistMbid = "614e3804-7d34-41ba-857f-811bad7c2b7a", + Url = new Uri("http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", UriKind.Absolute), + + Id = "1934", + Images = new LastImageSet( + "http://userserve-ak.last.fm/serve/34s/56827829.jpg", + "http://userserve-ak.last.fm/serve/64s/56827829.jpg", + "http://userserve-ak.last.fm/serve/126/56827829.jpg", + "http://userserve-ak.last.fm/serve/300x300/56827829.jpg") + + }; + + var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksSingle)); + var parsed = await _command.HandleResponse(response); + + Assert.IsTrue(parsed.Success); + + var actual = parsed.Content; + Assert.IsTrue(actual.Count() == 1); + actual = null; + + var expectedJson = JsonConvert.SerializeObject(expectedTrack, Formatting.Indented); + var actualJson = JsonConvert.SerializeObject(parsed.Content, Formatting.Indented); + + Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); + } + + [TestMethod] + public async Task HandleErrorResponse() + { + var response = CreateResponseMessage(Encoding.UTF8.GetString(AlbumApiResponses.AlbumGetInfoMissing)); + + var parsed = await _command.HandleResponse(response); + + Assert.IsFalse(parsed.Success); + Assert.IsTrue(parsed.Error == LastFmApiError.MissingParameters); + } + } +} diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs new file mode 100644 index 0000000..c4ff2bf --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs @@ -0,0 +1,169 @@ +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IF.Lastfm.Core.Api.Commands.UserApi; +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Tests.Resources; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using IF.Lastfm.Core.Api.Commands.LibraryApi; +using IF.Lastfm.Core.Objects; +using System; +using Newtonsoft.Json; + +namespace IF.Lastfm.Core.Tests.Api.Commands.UserApi +{ + [TestClass] + public class GetRecentScrobblesCommandTests : CommandTestsBase + { + private GetRecentScrobblesCommand _command; + + private const string apiKey = "a6ab4b9376e54cdb06912bfbd9c1f288"; +private const string apiSecret = "3aa7202fd1bc6d5a7ac733246cbccc4b"; + + public GetRecentScrobblesCommandTests() + { + _command = new GetRecentScrobblesCommand(MAuth.Object, "rj", System.DateTime.MinValue) + { + Count = 1 + }; + } + + + + + + [TestMethod] + public async Task HandleSuccessResponse_User_GetRecentScrobbles_Multiple() + { + //Testing the second track returned + var expectedTrack = new LastTrack + { + ArtistName = "The Who", + // Duration = new TimeSpan(0, 3, 47), + //TotalPlayCount = 81, + TimePlayed = new DateTime(2014, 12, 19, 16, 13, 55,DateTimeKind.Utc), + Mbid = "79f3dc97-2297-47ee-8556-9a1bb4b48d53", + Name = "Pinball Wizard", + ArtistMbid = "9fdaa16b-a6c4-4831-b87c-bc9ca8ce7eaa", + AlbumName = "Tommy (Remastered)", + Url = new Uri("http://www.last.fm/music/The+Who/_/Pinball+Wizard", UriKind.Absolute), + + // Id = "1934", + Images = new LastImageSet( + "http://userserve-ak.last.fm/serve/34s/35234991.jpg", + "http://userserve-ak.last.fm/serve/64s/35234991.jpg", + "http://userserve-ak.last.fm/serve/126/35234991.jpg", + "http://userserve-ak.last.fm/serve/300x300/35234991.jpg") + + }; + + + await CheckResult_MultipleSample(_command, expectedTrack, 2, UserApiResponses.UserGetRecentTracksMultiple); + } + + [TestMethod] + public async Task HandleSuccessResponse_User_GetRecentScrobbles_Single() + { + //Broken until single objects work in the parser + var expectedTrack = new LastTrack + { + ArtistName = "Rick James", + // Duration = new TimeSpan(0, 3, 47), + TotalPlayCount = 81, + Mbid = "f22c19bf-1c88-4651-a0d3-8c50735f3c93", + Name = "Super Freak (Part 1) - 1981 Single Version", + ArtistMbid = "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c", + Url = new Uri("http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", UriKind.Absolute), + + // Id = "1934", + Images = new LastImageSet( + "http://userserve-ak.last.fm/serve/34s/90462319.jpg", + "http://userserve-ak.last.fm/serve/64s/90462319.jpg", + "http://userserve-ak.last.fm/serve/126/90462319.jpg", + "http://userserve-ak.last.fm/serve/300x300/90462319.jpg") + + }; + + + await CheckResult_Single(_command, expectedTrack, UserApiResponses.UserGetRecentTracksSingle); + //var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetRecentTracksSingle)); + //var parsed = await _command.HandleResponse(response); + + //Assert.IsTrue(parsed.Success); + + //var actual = parsed.Content; + + ////Check if object not array + + //var expectedJson = JsonConvert.SerializeObject(expectedTrack, Formatting.Indented); + //var actualJson = JsonConvert.SerializeObject(parsed.Content, Formatting.Indented); + + //Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); + } + + [TestMethod] + public async Task HandleErrorResponse_User_GetRecentScrobbles() + { + var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetRecentTracksError)); + + var parsed = await _command.HandleResponse(response); + + Assert.IsFalse(parsed.Success); + Assert.IsTrue(parsed.Error == LastFmApiError.MissingParameters); + } + + } +} + +//namespace IF.Lastfm.Core.Tests.Api.Commands.LibraryApi +//{ +// [TestClass] +// public class GetTracksCommandTests : CommandTestsBase +// { +// private GetTracksCommand _command; + + + + +// [TestMethod] +// public async Task HandleSuccessResponseSingleTrack() +// { + + +// var expectedTrack = new LastTrack +// { +// ArtistName = "Dire Straits", +// Duration = new TimeSpan(0, 3, 47), +// TotalPlayCount = 81, +// Mbid = "0317e524-7f70-4910-bc12-95dd468a29fc", +// Name = "Sultans of Swing", +// ArtistMbid = "614e3804-7d34-41ba-857f-811bad7c2b7a", +// Url = new Uri("http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", UriKind.Absolute), + +// Id = "1934", +// Images = new LastImageSet( +// "http://userserve-ak.last.fm/serve/34s/56827829.jpg", +// "http://userserve-ak.last.fm/serve/64s/56827829.jpg", +// "http://userserve-ak.last.fm/serve/126/56827829.jpg", +// "http://userserve-ak.last.fm/serve/300x300/56827829.jpg") + +// }; + +// var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksSingle)); +// var parsed = await _command.HandleResponse(response); + +// Assert.IsTrue(parsed.Success); + +// var actual = parsed.Content; +// Assert.IsTrue(actual.Count() == 1); +// actual = null; + +// var expectedJson = JsonConvert.SerializeObject(expectedTrack, Formatting.Indented); +// var actualJson = JsonConvert.SerializeObject(parsed.Content, Formatting.Indented); + +// Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); +// } + + +// } +//} diff --git a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj index a672e66..60c6f32 100644 --- a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj +++ b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj @@ -81,11 +81,14 @@ + + + True @@ -102,6 +105,11 @@ True True + + True + True + UserApiResponses.resx + @@ -122,11 +130,17 @@ + + + + + + @@ -148,6 +162,10 @@ ResXFileCodeGenerator TrackApiResponses.Designer.cs + + ResXFileCodeGenerator + UserApiResponses.Designer.cs + diff --git a/src/IF.Lastfm.Core.Tests/Objects/LastTrackTests.cs b/src/IF.Lastfm.Core.Tests/Objects/LastTrackTests.cs new file mode 100644 index 0000000..e0d0a4e --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Objects/LastTrackTests.cs @@ -0,0 +1,46 @@ +using System; +using IF.Lastfm.Core.Objects; +using Newtonsoft.Json.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; +using IF.Lastfm.Core.Tests.Resources; +using System.Threading.Tasks; +using System.Text; +using System.Collections.Generic; + +namespace IF.Lastfm.Core.Tests.Objects +{ + [TestClass] + public class LastTrackTests : ObjectsTestsBase + { + [TestMethod] + public async Task TestMethod1() + { + // var json = await response.Content.ReadAsStringAsync(); + var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksMultiple)); + + var json = await response.Content.ReadAsStringAsync(); + + JToken jtoken = JsonConvert.DeserializeObject(json).SelectToken("tracks"); + + + + var tracksToken = jtoken.SelectToken("track"); + + + var tracks = new List(); + foreach (var track in tracksToken.Children()) + { + var t = LastTrack.ParseJToken(track); + + tracks.Add(t); + } + + Assert.AreEqual(tracks.Count, 20); + + // var actual = parsed.Content; + //var token = JsonConvert.DeserializeObject(json);//.SelectToken("shouts"); ; + //LastTrack.ParseJToken(jtoken); + } + } +} diff --git a/src/IF.Lastfm.Core.Tests/Objects/ObjectsTestsBase.cs b/src/IF.Lastfm.Core.Tests/Objects/ObjectsTestsBase.cs new file mode 100644 index 0000000..ae3e599 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Objects/ObjectsTestsBase.cs @@ -0,0 +1,24 @@ +using IF.Lastfm.Core.Api; +using Moq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace IF.Lastfm.Core.Tests.Objects +{ + public abstract class ObjectsTestsBase + { + + + protected HttpResponseMessage CreateResponseMessage(string message) + { + var response = new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(message, Encoding.UTF8) + }; + + return response; + } + } +} diff --git a/src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksMultiple.json b/src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksMultiple.json new file mode 100644 index 0000000..8ee5dd7 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/LibraryApi/LibraryGetTracksMultiple.json @@ -0,0 +1,793 @@ +{ + "tracks": { + "track": [ + { + "name": "Sultans of Swing", + "duration": "347000", + "playcount": "81", + "tagcount": "0", + "mbid": "0317e524-7f70-4910-bc12-95dd468a29fc", + "url": "http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dire Straits", + "mbid": "614e3804-7d34-41ba-857f-811bad7c2b7a", + "url": "http://www.last.fm/music/Dire+Straits" + }, + "album": { + "name": "Dire Straits (Remastered)", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/56827829.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/56827829.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/56827829.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/56827829.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Superstition", + "duration": "248000", + "playcount": "56", + "tagcount": "0", + "mbid": "0161855d-0b98-4f2d-b2ab-446dbd8d6759", + "url": "http://www.last.fm/music/Stevie+Wonder/_/Superstition", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Stevie Wonder", + "mbid": "1ee18fb3-18a6-4c7f-8ba0-bc41cdd0462e", + "url": "http://www.last.fm/music/Stevie+Wonder" + }, + "album": { + "name": "Number Ones", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/99695819.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/99695819.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/99695819.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/99695819.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Pull Me Under", + "duration": "494000", + "playcount": "56", + "tagcount": "0", + "mbid": "4b2c1184-8d48-4dfa-84c4-f26e9729a626", + "url": "http://www.last.fm/music/Dream+Theater/_/Pull+Me+Under", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dream Theater", + "mbid": "28503ab7-8bf2-4666-a7bd-2644bfc7cb1d", + "url": "http://www.last.fm/music/Dream+Theater" + }, + "album": { + "name": "Images and Words", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/42406513.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/42406513.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/42406513.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/42406513.png", + "size": "extralarge" + } + ] + }, + { + "name": "The Pusher", + "duration": "349000", + "playcount": "55", + "tagcount": "1", + "mbid": "a1deb801-caea-4b66-9d35-537cb42c03b6", + "url": "http://www.last.fm/music/Steppenwolf/_/The+Pusher", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Steppenwolf", + "mbid": "12ff8858-bfcb-4812-a8dd-7e9debf0cbee", + "url": "http://www.last.fm/music/Steppenwolf" + }, + "album": { + "name": "16 Greatest Hits", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/84527157.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/84527157.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/84527157.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/84527157.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Take the Time", + "duration": "501000", + "playcount": "54", + "tagcount": "0", + "mbid": "55f96185-3de8-40d2-98dd-0f54846e1951", + "url": "http://www.last.fm/music/Dream+Theater/_/Take+the+Time", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dream Theater", + "mbid": "28503ab7-8bf2-4666-a7bd-2644bfc7cb1d", + "url": "http://www.last.fm/music/Dream+Theater" + }, + "album": { + "name": "Images and Words", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/42406513.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/42406513.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/42406513.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/42406513.png", + "size": "extralarge" + } + ] + }, + { + "name": "Another Day", + "duration": "263000", + "playcount": "54", + "tagcount": "0", + "mbid": "33f634b9-588c-49fd-83af-b1b1219b4db0", + "url": "http://www.last.fm/music/Dream+Theater/_/Another+Day", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dream Theater", + "mbid": "28503ab7-8bf2-4666-a7bd-2644bfc7cb1d", + "url": "http://www.last.fm/music/Dream+Theater" + }, + "album": { + "name": "Images and Words", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/42406513.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/42406513.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/42406513.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/42406513.png", + "size": "extralarge" + } + ] + }, + { + "name": "Learning to Live", + "duration": "690000", + "playcount": "54", + "tagcount": "0", + "mbid": "7aa216d0-94dc-48d2-bb3c-7116843b8bf3", + "url": "http://www.last.fm/music/Dream+Theater/_/Learning+to+Live", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dream Theater", + "mbid": "28503ab7-8bf2-4666-a7bd-2644bfc7cb1d", + "url": "http://www.last.fm/music/Dream+Theater" + }, + "album": { + "name": "Images and Words", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/42406513.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/42406513.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/42406513.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/42406513.png", + "size": "extralarge" + } + ] + }, + { + "name": "Three Minute Warning", + "duration": "1716000", + "playcount": "54", + "tagcount": "0", + "mbid": "b4ad3a39-5fd1-4021-b80d-e71eb8b2e20f", + "url": "http://www.last.fm/music/Liquid+Tension+Experiment/_/Three+Minute+Warning", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Liquid Tension Experiment", + "mbid": "bc641be9-ca36-4c61-9394-5230433f6646", + "url": "http://www.last.fm/music/Liquid+Tension+Experiment" + }, + "album": { + "name": "Liquid Tension Experiment", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/88566859.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/88566859.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/88566859.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/88566859.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Cowboys", + "duration": "279000", + "playcount": "53", + "tagcount": "0", + "mbid": "eca7d591-1fd9-4cea-9cbe-0f31f474041d", + "url": "http://www.last.fm/music/Portishead/_/Cowboys", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Portishead", + "mbid": "17e0ef75-fae9-4fa3-b6f6-39a8c986d686", + "url": "http://www.last.fm/music/Portishead" + }, + "album": { + "name": "Portishead", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/66825870.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/66825870.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/66825870.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/66825870.png", + "size": "extralarge" + } + ] + }, + { + "name": "Under a Glass Moon", + "duration": "423000", + "playcount": "47", + "tagcount": "0", + "mbid": "b0f7db49-8397-42c5-8e63-cb3b6f92b825", + "url": "http://www.last.fm/music/Dream+Theater/_/Under+a+Glass+Moon", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dream Theater", + "mbid": "28503ab7-8bf2-4666-a7bd-2644bfc7cb1d", + "url": "http://www.last.fm/music/Dream+Theater" + }, + "album": { + "name": "Images and Words", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/42406513.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/42406513.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/42406513.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/42406513.png", + "size": "extralarge" + } + ] + }, + { + "name": "Money for Nothing", + "duration": "503000", + "playcount": "46", + "tagcount": "0", + "mbid": "06622908-5da7-4bb9-9b6b-53bc8dc039ee", + "url": "http://www.last.fm/music/Dire+Straits/_/Money+for+Nothing", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dire Straits", + "mbid": "614e3804-7d34-41ba-857f-811bad7c2b7a", + "url": "http://www.last.fm/music/Dire+Straits" + }, + "album": { + "name": "Brothers In Arms - 20th Anniversary Edition", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/8801435.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/8801435.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/8801435.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/8801435.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Steamroller", + "duration": "177000", + "playcount": "44", + "tagcount": "0", + "mbid": "47cd0ce0-ff26-4bb0-adea-3b049f2321fd", + "url": "http://www.last.fm/music/James+Taylor/_/Steamroller", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "James Taylor", + "mbid": "0217fabf-0e84-4c36-b197-f1b6e1263506", + "url": "http://www.last.fm/music/James+Taylor" + }, + "album": { + "name": "Greatest Hits", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/87576587.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/87576587.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/87576587.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/87576587.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Fire and Rain", + "duration": "272000", + "playcount": "43", + "tagcount": "0", + "mbid": "6d8b6dc1-0aff-4e72-a180-0839af79e8c1", + "url": "http://www.last.fm/music/James+Taylor/_/Fire+and+Rain", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "James Taylor", + "mbid": "0217fabf-0e84-4c36-b197-f1b6e1263506", + "url": "http://www.last.fm/music/James+Taylor" + }, + "album": { + "name": "Sweet Baby James", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/69242572.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/69242572.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/69242572.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/69242572.png", + "size": "extralarge" + } + ] + }, + { + "name": "Gin And Juice", + "duration": "211000", + "playcount": "43", + "tagcount": "0", + "mbid": "1e9cc395-2fb9-45f2-8ac5-05cefa9668f1", + "url": "http://www.last.fm/music/Snoop+Dogg/_/Gin+And+Juice", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Snoop Dogg", + "mbid": "17d17695-f0e1-46fd-815f-bf577cc5f50d", + "url": "http://www.last.fm/music/Snoop+Dogg" + }, + "album": { + "name": "Doggystyle", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/100162457.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/100162457.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/100162457.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/100162457.png", + "size": "extralarge" + } + ] + }, + { + "name": "Wait for Sleep", + "duration": "153000", + "playcount": "43", + "tagcount": "0", + "mbid": "8ec3f9d2-945f-43bb-9ef2-63b6cbbe2653", + "url": "http://www.last.fm/music/Dream+Theater/_/Wait+for+Sleep", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dream Theater", + "mbid": "28503ab7-8bf2-4666-a7bd-2644bfc7cb1d", + "url": "http://www.last.fm/music/Dream+Theater" + }, + "album": { + "name": "Images and Words", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/42406513.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/42406513.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/42406513.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/42406513.png", + "size": "extralarge" + } + ] + }, + { + "name": "I Wish You Were Here", + "duration": "268000", + "playcount": "42", + "tagcount": "0", + "mbid": "890b1c78-6f6c-4917-a627-48e7f44c2568", + "url": "http://www.last.fm/music/Alpha+Blondy/_/I+Wish+You+Were+Here", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Alpha Blondy", + "mbid": "3906105b-189a-444e-b34a-e6dc5aa2c2e4", + "url": "http://www.last.fm/music/Alpha+Blondy" + }, + "album": { + "name": "Jah Victory", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/93692707.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/93692707.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/93692707.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/93692707.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Walk of Life", + "duration": "249000", + "playcount": "40", + "tagcount": "0", + "mbid": "0ed233bf-41c0-4b0c-b330-32d7444eab2a", + "url": "http://www.last.fm/music/Dire+Straits/_/Walk+of+Life", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dire Straits", + "mbid": "614e3804-7d34-41ba-857f-811bad7c2b7a", + "url": "http://www.last.fm/music/Dire+Straits" + }, + "album": { + "name": "Brothers In Arms - 20th Anniversary Edition", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/8801435.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/8801435.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/8801435.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/8801435.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "You've Got a Friend", + "duration": "307000", + "playcount": "39", + "tagcount": "0", + "mbid": "2e3a3cb0-5e5a-415b-89cd-dc0ae74c91be", + "url": "http://www.last.fm/music/James+Taylor/_/You%27ve+Got+a+Friend", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "James Taylor", + "mbid": "0217fabf-0e84-4c36-b197-f1b6e1263506", + "url": "http://www.last.fm/music/James+Taylor" + }, + "album": { + "name": "Mud Slide Slim and the Blue Horizon", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/83767473.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/83767473.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/83767473.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/83767473.png", + "size": "extralarge" + } + ] + }, + { + "name": "Telegraph Road", + "duration": "860000", + "playcount": "39", + "tagcount": "0", + "mbid": "f134485c-bf29-494c-888a-d4467d152609", + "url": "http://www.last.fm/music/Dire+Straits/_/Telegraph+Road", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Dire Straits", + "mbid": "614e3804-7d34-41ba-857f-811bad7c2b7a", + "url": "http://www.last.fm/music/Dire+Straits" + }, + "album": { + "name": "The Best of Dire Straits & Mark Knopfler - Private Investigations", + "position": "" + }, + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/98006973.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/98006973.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/98006973.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/98006973.jpg", + "size": "extralarge" + } + ] + }, + { + "name": "Midas Touch", + "duration": "234000", + "playcount": "39", + "tagcount": "0", + "mbid": "0128cb40-46b0-45c4-b451-a2d661f19732", + "url": "http://www.last.fm/music/Midnight+Star/_/Midas+Touch", + "streamable": { + "#text": "0", + "fulltrack": "0" + }, + "artist": { + "name": "Midnight Star", + "mbid": "3d30a740-e36b-45b9-a395-a3b3696d1d7c", + "url": "http://www.last.fm/music/Midnight+Star" + }, + "album": { + "name": "Soul Hits Of The 80's", + "position": "" + }, + "image": [ + { + "#text": "http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png", + "size": "small" + }, + { + "#text": "http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png", + "size": "medium" + }, + { + "#text": "http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png", + "size": "large" + }, + { + "#text": "http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png", + "size": "extralarge" + } + ] + } + ], + "@attr": { + "user": "RJ", + "page": "0", + "perPage": "20", + "totalPages": "1949", + "total": "38966" + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs index d52215c..4383df7 100644 --- a/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs +++ b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.Designer.cs @@ -60,6 +60,16 @@ internal LibraryApiResponses() { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] LibraryGetTracksMultiple { + get { + object obj = ResourceManager.GetObject("LibraryGetTracksMultiple", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// diff --git a/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx index eeba830..dfce2b6 100644 --- a/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx +++ b/src/IF.Lastfm.Core.Tests/Resources/LibraryApiResponses.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + libraryapi\librarygettracksmultiple.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + libraryapi\librarygettrackssingle.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksEmpty.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksEmpty.json new file mode 100644 index 0000000..c1159aa --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksEmpty.json @@ -0,0 +1,10 @@ +{ + "recenttracks": { + "#text": "\n", + "user": "RT", + "page": "0", + "perPage": "20", + "totalPages": "0", + "total": "0" + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksError.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksError.json new file mode 100644 index 0000000..17a1ac4 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksError.json @@ -0,0 +1,5 @@ +{ + "error": 6, + "message": "Invalid parameters - Your request is missing the [user] parameter", + "links": [] +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMissing.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMissing.json new file mode 100644 index 0000000..501b377 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMissing.json @@ -0,0 +1,5 @@ +{ + "error": 6, + "message": "No user with that name was found", + "links": [] +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMultiple.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMultiple.json new file mode 100644 index 0000000..911859f --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksMultiple.json @@ -0,0 +1,733 @@ +{ + "recenttracks": { + "track": [ + { + "artist": { + "#text": "Santana", + "mbid": "1bc6816a-d056-4113-9b0a-6c52e5c31a3c" + }, + "name": "No One to Depend On", + "streamable": "0", + "mbid": "3f8ed8da-dcc6-43dc-8266-3663007261a6", + "album": { + "#text": "Santana (III)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Santana/_/No+One+to+Depend+On", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/99461493.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/99461493.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/99461493.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/99461493.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:21", + "uts": "1419006075" + } + }, + { + "artist": { + "#text": "The Rolling Stones", + "mbid": "b071f9fa-14b0-4217-8e97-eb41da73f598" + }, + "name": "Love in Vain", + "streamable": "0", + "mbid": "3dde65c8-22c3-4637-b67e-b234177c847b", + "album": { + "#text": "Let It Bleed", + "mbid": "8bc2f5e2-122a-42db-b86c-fddedc77463a" + }, + "url": "http://www.last.fm/music/The+Rolling+Stones/_/Love+in+Vain", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/101739037.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/101739037.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/101739037.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/101739037.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:16", + "uts": "1419005816" + } + }, + { + "artist": { + "#text": "The Who", + "mbid": "9fdaa16b-a6c4-4831-b87c-bc9ca8ce7eaa" + }, + "name": "Pinball Wizard", + "streamable": "0", + "mbid": "79f3dc97-2297-47ee-8556-9a1bb4b48d53", + "album": { + "#text": "Tommy (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Who/_/Pinball+Wizard", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/35234991.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/35234991.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/35234991.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/35234991.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:13", + "uts": "1419005635" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "I'm So Glad", + "streamable": "0", + "mbid": "3dc91be5-c7ab-4af3-9557-19eb8e054d5a", + "album": { + "#text": "Fresh Cream (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/I%27m+So+Glad", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/89387215.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/89387215.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/89387215.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/89387215.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:09", + "uts": "1419005395" + } + }, + { + "artist": { + "#text": "The Yardbirds", + "mbid": "191de76f-a224-445d-b041-54df16d65bf7" + }, + "name": "Smokestack Lightning", + "streamable": "0", + "mbid": "580b35c9-b701-43d7-9ec3-6bd6f01534c2", + "album": { + "#text": "Five Live Yardbirds", + "mbid": "3fda56ac-efe1-4a26-9c86-116f5cc4b721" + }, + "url": "http://www.last.fm/music/The+Yardbirds/_/Smokestack+Lightning", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/91925037.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/91925037.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/91925037.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/91925037.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 16:04", + "uts": "1419005063" + } + }, + { + "artist": { + "#text": "Canned Heat", + "mbid": "815a0279-558c-4522-ac3b-6a1e259e95b5" + }, + "name": "One Kind Favor", + "streamable": "0", + "mbid": "5bde419b-9e93-46c6-baf5-ef58a0b3bb73", + "album": { + "#text": "Living The Blues", + "mbid": "ec82ab15-8c01-4aa0-810c-d184d20f229b" + }, + "url": "http://www.last.fm/music/Canned+Heat/_/One+Kind+Favor", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/100370719.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/100370719.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/100370719.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/100370719.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:59", + "uts": "1419004779" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "Politician", + "streamable": "0", + "mbid": "f2c2760c-ea5c-4ca0-8a8b-4199a41ffba0", + "album": { + "#text": "Wheels of Fire (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/Politician", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/75021714.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/75021714.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/75021714.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/75021714.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:55", + "uts": "1419004522" + } + }, + { + "artist": { + "#text": "The Doors", + "mbid": "9efff43b-3b29-4082-824e-bc82f646f93d" + }, + "name": "Light My Fire", + "streamable": "0", + "mbid": "05b7cd66-a700-4aa1-baf3-e1e41388f3cf", + "album": { + "#text": "The Doors", + "mbid": "8f3cf206-35f6-3c77-925e-766bdfbf6333" + }, + "url": "http://www.last.fm/music/The+Doors/_/Light+My+Fire", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/88289473.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/88289473.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/88289473.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/88289473.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:48", + "uts": "1419004096" + } + }, + { + "artist": { + "#text": "Full Metal Hammer", + "mbid": "" + }, + "name": "Since Ive Been Loving You", + "streamable": "0", + "mbid": "", + "album": { + "#text": "It's A Full Metal Hammer Thing", + "mbid": "" + }, + "url": "http://www.last.fm/music/Full+Metal+Hammer/_/Since+Ive+Been+Loving+You", + "image": [ + { + "#text": "", + "size": "small" + }, + { + "#text": "", + "size": "medium" + }, + { + "#text": "", + "size": "large" + }, + { + "#text": "", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:41", + "uts": "1419003662" + } + }, + { + "artist": { + "#text": "The Jimi Hendrix Experience", + "mbid": "33b3c323-77c2-417c-a5b4-af7e6a111cc9" + }, + "name": "Burning Of The Midnight Lamp", + "streamable": "0", + "mbid": "1a1c8a21-351d-4c43-8ed4-3fd3f5058e1b", + "album": { + "#text": "Electric Ladyland", + "mbid": "9fa7f446-b15c-3ad9-a4cc-3348e9140319" + }, + "url": "http://www.last.fm/music/The+Jimi+Hendrix+Experience/_/Burning+Of+The+Midnight+Lamp", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/96516997.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/96516997.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/96516997.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/96516997.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:37", + "uts": "1419003443" + } + }, + { + "artist": { + "#text": "Otis Rush", + "mbid": "40ee7c92-f44a-4d14-9aee-f87244465ee4" + }, + "name": "Double Trouble", + "streamable": "0", + "mbid": "f23c009e-19c4-4196-8fe2-236c28546bfc", + "album": { + "#text": "Live At Montreux 1986", + "mbid": "" + }, + "url": "http://www.last.fm/music/Otis+Rush/_/Double+Trouble", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/91112769.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/91112769.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/91112769.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/91112769.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:32", + "uts": "1419003132" + } + }, + { + "artist": { + "#text": "The Yardbirds", + "mbid": "191de76f-a224-445d-b041-54df16d65bf7" + }, + "name": "I Don't Care No More", + "streamable": "0", + "mbid": "30e22d26-15f7-4547-a0f4-b08feed1a7fc", + "album": { + "#text": "Rock Classics: Parable Of Arable Land", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Yardbirds/_/I+Don%27t+Care+No+More", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/54760139.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/54760139.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/54760139.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/174s/54760139.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:28", + "uts": "1419002911" + } + }, + { + "artist": { + "#text": "The Doors", + "mbid": "9efff43b-3b29-4082-824e-bc82f646f93d" + }, + "name": "Crawling King Snake", + "streamable": "0", + "mbid": "a08905e0-dc59-47fe-ae93-be5bb0d22a84", + "album": { + "#text": "L.A. Woman", + "mbid": "492025d7-a5fd-40f0-94f9-8841e9078bb3" + }, + "url": "http://www.last.fm/music/The+Doors/_/Crawling+King+Snake", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/88488175.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/88488175.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/88488175.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/88488175.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:23", + "uts": "1419002612" + } + }, + { + "artist": { + "#text": "Jimmy Page", + "mbid": "519774a4-3b18-4042-b8c0-927845a616c9" + }, + "name": "Prison Blues", + "streamable": "0", + "mbid": "f78a2ce9-3dba-439c-9e05-0783ccfa40c3", + "album": { + "#text": "Outrider", + "mbid": "a53095c1-a6ea-4bc9-a14c-6ecafeef738e" + }, + "url": "http://www.last.fm/music/Jimmy+Page/_/Prison+Blues", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/90138723.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/90138723.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/90138723.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/90138723.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:16", + "uts": "1419002181" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "Spoonful", + "streamable": "0", + "mbid": "f6f5d7f0-b368-45c0-8505-4b33ac696035", + "album": { + "#text": "Fresh Cream (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/Spoonful", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/89387215.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/89387215.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/89387215.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/89387215.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:09", + "uts": "1419001787" + } + }, + { + "artist": { + "#text": "The Doors", + "mbid": "9efff43b-3b29-4082-824e-bc82f646f93d" + }, + "name": "Back Door Man", + "streamable": "0", + "mbid": "1976f693-f35f-4534-b341-31d51f46b208", + "album": { + "#text": "The Doors", + "mbid": "8f3cf206-35f6-3c77-925e-766bdfbf6333" + }, + "url": "http://www.last.fm/music/The+Doors/_/Back+Door+Man", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/88289473.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/88289473.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/88289473.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/88289473.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:06", + "uts": "1419001574" + } + }, + { + "artist": { + "#text": "The Yardbirds", + "mbid": "191de76f-a224-445d-b041-54df16d65bf7" + }, + "name": "I Ain't Got You", + "streamable": "0", + "mbid": "19ee6ab9-1716-41e1-8aa7-cada544f5695", + "album": { + "#text": "Five Live", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Yardbirds/_/I+Ain%27t+Got+You", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/87032633.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/87032633.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/87032633.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/87032633.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:04", + "uts": "1419001453" + } + }, + { + "artist": { + "#text": "The Who", + "mbid": "9fdaa16b-a6c4-4831-b87c-bc9ca8ce7eaa" + }, + "name": "Substitute (Remixed Live At Leeds Version)", + "streamable": "0", + "mbid": "", + "album": { + "#text": "Live At Leeds (25th Anniversary Edition)", + "mbid": "" + }, + "url": "http://www.last.fm/music/The+Who/_/Substitute+(Remixed+Live+At+Leeds+Version)", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/82286267.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/82286267.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/82286267.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/82286267.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 15:01", + "uts": "1419001281" + } + }, + { + "artist": { + "#text": "Cream", + "mbid": "04cd0cfd-bfd1-4c36-bc38-95c35e2c045f" + }, + "name": "Tales of Brave Ulysses", + "streamable": "0", + "mbid": "f5e62507-07f1-45eb-83c6-6742d5260d06", + "album": { + "#text": "Disraeli Gears (Remastered)", + "mbid": "" + }, + "url": "http://www.last.fm/music/Cream/_/Tales+of+Brave+Ulysses", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/57500153.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/57500153.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/57500153.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/57500153.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 14:58", + "uts": "1419001115" + } + }, + { + "artist": { + "#text": "Jimi Hendrix", + "mbid": "06fb1c8b-566e-4cb2-985b-b467c90781d4" + }, + "name": "Johnny B. Goode (Live Berkeley Community Center, Berkeley, CA May 30, 1970)", + "streamable": "0", + "mbid": "", + "album": { + "#text": "In The West", + "mbid": "" + }, + "url": "http://www.last.fm/music/Jimi+Hendrix/_/Johnny+B.+Goode+(Live+Berkeley+Community+Center,+Berkeley,+CA+May+30,+1970)", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/78579114.png", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/78579114.png", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/78579114.png", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/78579114.png", + "size": "extralarge" + } + ], + "date": { + "#text": "19 Dec 2014, 14:53", + "uts": "1419000831" + } + } + ], + "@attr": { + "user": "RJ", + "page": "0", + "perPage": "20", + "totalPages": "3827", + "total": "76526" + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksSingle.json b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksSingle.json new file mode 100644 index 0000000..bbe8996 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApi/UserGetRecentTracksSingle.json @@ -0,0 +1,47 @@ +{ + "recenttracks": { + "track": { + "artist": { + "#text": "Rick James", + "mbid": "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c" + }, + "name": "Super Freak (Part 1) - 1981 Single Version", + "streamable": "0", + "mbid": "", + "album": { + "#text": "The Definitive Collection", + "mbid": "f22c19bf-1c88-4651-a0d3-8c50735f3c93" + }, + "url": "http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", + "image": [ + { + "#text": "http://userserve-ak.last.fm/serve/34s/90462319.jpg", + "size": "small" + }, + { + "#text": "http://userserve-ak.last.fm/serve/64s/90462319.jpg", + "size": "medium" + }, + { + "#text": "http://userserve-ak.last.fm/serve/126/90462319.jpg", + "size": "large" + }, + { + "#text": "http://userserve-ak.last.fm/serve/300x300/90462319.jpg", + "size": "extralarge" + } + ], + "date": { + "#text": "20 Dec 2014, 10:16", + "uts": "1419070612" + } + }, + "@attr": { + "user": "RJ", + "page": "0", + "perPage": "1", + "totalPages": "76536", + "total": "76536" + } + } +} \ No newline at end of file diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs new file mode 100644 index 0000000..39741e3 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.Designer.cs @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18444 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace IF.Lastfm.Core.Tests.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class UserApiResponses { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal UserApiResponses() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("IF.Lastfm.Core.Tests.Resources.UserApiResponses", typeof(UserApiResponses).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] UserGetRecentTracksEmpty { + get { + object obj = ResourceManager.GetObject("UserGetRecentTracksEmpty", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] UserGetRecentTracksError { + get { + object obj = ResourceManager.GetObject("UserGetRecentTracksError", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] UserGetRecentTracksMissing { + get { + object obj = ResourceManager.GetObject("UserGetRecentTracksMissing", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] UserGetRecentTracksMultiple { + get { + object obj = ResourceManager.GetObject("UserGetRecentTracksMultiple", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] UserGetRecentTracksSingle { + get { + object obj = ResourceManager.GetObject("UserGetRecentTracksSingle", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx new file mode 100644 index 0000000..99227f3 --- /dev/null +++ b/src/IF.Lastfm.Core.Tests/Resources/UserApiResponses.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + userapi\usergetrecenttracksempty.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + userapi\usergetrecenttrackserror.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + userapi\usergetrecenttracksmissing.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + userapi\usergetrecenttracksmultiple.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + UserApi\UserGetRecentTracksSingle.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/IF.Lastfm.Core/Objects/LastTrack.cs b/src/IF.Lastfm.Core/Objects/LastTrack.cs index a69da37..2dc4b51 100644 --- a/src/IF.Lastfm.Core/Objects/LastTrack.cs +++ b/src/IF.Lastfm.Core/Objects/LastTrack.cs @@ -35,6 +35,10 @@ public class LastTrack : ILastfmObject #endregion + public LastTrack() + { + } + /// /// Parses the given JToken into a track /// From 7ce8527f1ce4c9580297c94b8c9e6827c5583c1e Mon Sep 17 00:00:00 2001 From: Peter Curd Date: Sat, 20 Dec 2014 14:20:16 +0000 Subject: [PATCH 03/11] Tests for Multiple and Single track returns for GetRecentScrobbles --- .../UserApi/GetRecentScrobblesCommandTests.cs | 82 +++---------------- .../UserApi/GetRecentScrobblesCommand.cs | 28 +++++-- 2 files changed, 32 insertions(+), 78 deletions(-) diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs index c4ff2bf..d832ebc 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs @@ -9,6 +9,7 @@ using IF.Lastfm.Core.Objects; using System; using Newtonsoft.Json; +using System.Collections.Generic; namespace IF.Lastfm.Core.Tests.Api.Commands.UserApi { @@ -17,8 +18,8 @@ public class GetRecentScrobblesCommandTests : CommandTestsBase { private GetRecentScrobblesCommand _command; - private const string apiKey = "a6ab4b9376e54cdb06912bfbd9c1f288"; -private const string apiSecret = "3aa7202fd1bc6d5a7ac733246cbccc4b"; + //private const string apiKey = "a6ab4b9376e54cdb06912bfbd9c1f288"; + //private const string apiSecret = "3aa7202fd1bc6d5a7ac733246cbccc4b"; public GetRecentScrobblesCommandTests() { @@ -29,9 +30,6 @@ public GetRecentScrobblesCommandTests() } - - - [TestMethod] public async Task HandleSuccessResponse_User_GetRecentScrobbles_Multiple() { @@ -69,10 +67,13 @@ public async Task HandleSuccessResponse_User_GetRecentScrobbles_Single() { ArtistName = "Rick James", // Duration = new TimeSpan(0, 3, 47), - TotalPlayCount = 81, - Mbid = "f22c19bf-1c88-4651-a0d3-8c50735f3c93", + //TotalPlayCount = 81, + Mbid = "", Name = "Super Freak (Part 1) - 1981 Single Version", ArtistMbid = "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c", + + TimePlayed = new DateTime(2014,12,20,10,16,52, DateTimeKind.Utc), + AlbumName = "The Definitive Collection", Url = new Uri("http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", UriKind.Absolute), // Id = "1934", @@ -85,20 +86,10 @@ public async Task HandleSuccessResponse_User_GetRecentScrobbles_Single() }; - await CheckResult_Single(_command, expectedTrack, UserApiResponses.UserGetRecentTracksSingle); - //var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetRecentTracksSingle)); - //var parsed = await _command.HandleResponse(response); + var expected = new List { expectedTrack }; - //Assert.IsTrue(parsed.Success); + await CheckResult_Single(_command, expected, UserApiResponses.UserGetRecentTracksSingle); - //var actual = parsed.Content; - - ////Check if object not array - - //var expectedJson = JsonConvert.SerializeObject(expectedTrack, Formatting.Indented); - //var actualJson = JsonConvert.SerializeObject(parsed.Content, Formatting.Indented); - - //Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); } [TestMethod] @@ -114,56 +105,3 @@ public async Task HandleErrorResponse_User_GetRecentScrobbles() } } - -//namespace IF.Lastfm.Core.Tests.Api.Commands.LibraryApi -//{ -// [TestClass] -// public class GetTracksCommandTests : CommandTestsBase -// { -// private GetTracksCommand _command; - - - - -// [TestMethod] -// public async Task HandleSuccessResponseSingleTrack() -// { - - -// var expectedTrack = new LastTrack -// { -// ArtistName = "Dire Straits", -// Duration = new TimeSpan(0, 3, 47), -// TotalPlayCount = 81, -// Mbid = "0317e524-7f70-4910-bc12-95dd468a29fc", -// Name = "Sultans of Swing", -// ArtistMbid = "614e3804-7d34-41ba-857f-811bad7c2b7a", -// Url = new Uri("http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", UriKind.Absolute), - -// Id = "1934", -// Images = new LastImageSet( -// "http://userserve-ak.last.fm/serve/34s/56827829.jpg", -// "http://userserve-ak.last.fm/serve/64s/56827829.jpg", -// "http://userserve-ak.last.fm/serve/126/56827829.jpg", -// "http://userserve-ak.last.fm/serve/300x300/56827829.jpg") - -// }; - -// var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksSingle)); -// var parsed = await _command.HandleResponse(response); - -// Assert.IsTrue(parsed.Success); - -// var actual = parsed.Content; -// Assert.IsTrue(actual.Count() == 1); -// actual = null; - -// var expectedJson = JsonConvert.SerializeObject(expectedTrack, Formatting.Indented); -// var actualJson = JsonConvert.SerializeObject(parsed.Content, Formatting.Indented); - -// Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); -// } - - -// } -//} diff --git a/src/IF.Lastfm.Core/Api/Commands/UserApi/GetRecentScrobblesCommand.cs b/src/IF.Lastfm.Core/Api/Commands/UserApi/GetRecentScrobblesCommand.cs index 0d1eac4..fdc9cbe 100644 --- a/src/IF.Lastfm.Core/Api/Commands/UserApi/GetRecentScrobblesCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/UserApi/GetRecentScrobblesCommand.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; +using System.Linq; namespace IF.Lastfm.Core.Api.Commands.UserApi { @@ -41,16 +42,31 @@ public async override Task> HandleResponse(HttpResponseM if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode) { JToken jtoken = JsonConvert.DeserializeObject(json).SelectToken("recenttracks"); + + + + + IEnumerable tracks; var tracksToken = jtoken.SelectToken("track"); - var tracks = new List(); - foreach (var track in tracksToken.Children()) - { - var t = LastTrack.ParseJToken(track); + + tracks = tracksToken.Type == JTokenType.Array + ? tracksToken.Children().Select(t => LastTrack.ParseJToken(t)) + : new List() { LastTrack.ParseJToken(tracksToken) }; + + + + + + + //var tracks = new List(); + //foreach (var track in tracksToken.Children()) + //{ + // var t = LastTrack.ParseJToken(track); - tracks.Add(t); - } + // tracks.Add(t); + //} var pageresponse = PageResponse.CreateSuccessResponse(tracks); From 367724390dc869c7c4281c2e507f3259bb9fd33e Mon Sep 17 00:00:00 2001 From: Peter Curd Date: Sat, 20 Dec 2014 15:32:02 +0000 Subject: [PATCH 04/11] Added TotalPlayCount to Track parsing Added Name as a possible field for album name Allowed HandleResponse for GetTracksCommand handle single results as an object instead of an array Added working tests for GetTracksCommand --- .../Commands/Library/GetTracksCommandTests.cs | 55 +++++++++++++------ .../Commands/LibraryApi/GetTracksCommand.cs | 11 ++-- src/IF.Lastfm.Core/Objects/LastAlbum.cs | 5 ++ src/IF.Lastfm.Core/Objects/LastTrack.cs | 4 ++ 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs index abf1ef1..ee9f2ec 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs @@ -36,45 +36,68 @@ public GetTracksCommandTests() } + [TestMethod] - public async Task HandleSuccessResponseSingleTrack() + public async Task HandleSuccessResponse_Library_GetTracks_Multiple() { - - + //Testing the second track returned + var expectedTrack = new LastTrack + { + ArtistName = "Stevie Wonder", + Duration = new TimeSpan(0, 4, 8), + TotalPlayCount = 56, + //TimePlayed = new DateTime(2014, 12, 19, 16, 13, 55, DateTimeKind.Utc), + Mbid = "0161855d-0b98-4f2d-b2ab-446dbd8d6759", + Name = "Superstition", + ArtistMbid = "1ee18fb3-18a6-4c7f-8ba0-bc41cdd0462e", + AlbumName = "Number Ones", + Url = new Uri("http://www.last.fm/music/Stevie+Wonder/_/Superstition", UriKind.Absolute), + + // Id = "1934", + Images = new LastImageSet( + "http://userserve-ak.last.fm/serve/34s/99695819.jpg", + "http://userserve-ak.last.fm/serve/64s/99695819.jpg", + "http://userserve-ak.last.fm/serve/126/99695819.jpg", + "http://userserve-ak.last.fm/serve/300x300/99695819.jpg") + + }; + + + await CheckResult_MultipleSample(_command, expectedTrack, 1, LibraryApiResponses.LibraryGetTracksMultiple); + } + + [TestMethod] + public async Task HandleSuccessResponse_Library_GetTracks_Single() + { + //Broken until single objects work in the parser var expectedTrack = new LastTrack { ArtistName = "Dire Straits", - Duration = new TimeSpan(0, 3, 47), + Duration = new TimeSpan(0, 5, 47), TotalPlayCount = 81, Mbid = "0317e524-7f70-4910-bc12-95dd468a29fc", Name = "Sultans of Swing", ArtistMbid = "614e3804-7d34-41ba-857f-811bad7c2b7a", + AlbumName = "Dire Straits (Remastered)", Url = new Uri("http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", UriKind.Absolute), - Id = "1934", + //Id = "1934", Images = new LastImageSet( "http://userserve-ak.last.fm/serve/34s/56827829.jpg", "http://userserve-ak.last.fm/serve/64s/56827829.jpg", "http://userserve-ak.last.fm/serve/126/56827829.jpg", "http://userserve-ak.last.fm/serve/300x300/56827829.jpg") - + }; - var response = CreateResponseMessage(Encoding.UTF8.GetString(LibraryApiResponses.LibraryGetTracksSingle)); - var parsed = await _command.HandleResponse(response); - Assert.IsTrue(parsed.Success); + var expected = new List { expectedTrack }; - var actual = parsed.Content; - Assert.IsTrue(actual.Count() == 1); - actual = null; + await CheckResult_Single(_command, expected, LibraryApiResponses.LibraryGetTracksSingle); - var expectedJson = JsonConvert.SerializeObject(expectedTrack, Formatting.Indented); - var actualJson = JsonConvert.SerializeObject(parsed.Content, Formatting.Indented); - - Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); } + [TestMethod] public async Task HandleErrorResponse() { diff --git a/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs index 3688ae2..3a858c1 100644 --- a/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; +using System.Linq; namespace IF.Lastfm.Core.Api.Commands.LibraryApi { @@ -52,13 +53,9 @@ public async override Task> HandleResponse(HttpResponseM var tracksToken = jtoken.SelectToken("track"); - var tracks = new List(); - foreach (var track in tracksToken.Children()) - { - var t = LastTrack.ParseJToken(track); - - tracks.Add(t); - } + IEnumerable tracks = tracksToken.Type == JTokenType.Array + ? tracksToken.Children().Select(t => LastTrack.ParseJToken(t)) + : new List() { LastTrack.ParseJToken(tracksToken) }; var pageresponse = PageResponse.CreateSuccessResponse(tracks); diff --git a/src/IF.Lastfm.Core/Objects/LastAlbum.cs b/src/IF.Lastfm.Core/Objects/LastAlbum.cs index 7221fc1..aab6426 100644 --- a/src/IF.Lastfm.Core/Objects/LastAlbum.cs +++ b/src/IF.Lastfm.Core/Objects/LastAlbum.cs @@ -102,6 +102,11 @@ internal static string GetNameFromJToken(JToken albumToken) name = albumToken.Value("#text"); } + if (string.IsNullOrEmpty(name)) + { + name = albumToken.Value("name"); // Used in Library track lists + } + return name; } } diff --git a/src/IF.Lastfm.Core/Objects/LastTrack.cs b/src/IF.Lastfm.Core/Objects/LastTrack.cs index 2dc4b51..523d6b4 100644 --- a/src/IF.Lastfm.Core/Objects/LastTrack.cs +++ b/src/IF.Lastfm.Core/Objects/LastTrack.cs @@ -52,6 +52,10 @@ internal static LastTrack ParseJToken(JToken token) t.Id = token.Value("id"); t.Name = token.Value("name"); t.Mbid = token.Value("mbid"); + + //0 to null + t.TotalPlayCount = token.Value("playcount"); + t.Url = new Uri(token.Value("url"), UriKind.Absolute); var artistToken = token.SelectToken("artist"); From 596cd285fb2328bbe860b0733a77606d2bee81c9 Mon Sep 17 00:00:00 2001 From: Peter Curd Date: Sat, 20 Dec 2014 16:01:57 +0000 Subject: [PATCH 05/11] Updating GetTracksCommand to use new style CreateSuccessResponse --- .../Api/Commands/Library/GetTracksCommandTests.cs | 11 +---------- .../Api/Commands/LibraryApi/GetTracksCommand.cs | 12 +++--------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs index ee9f2ec..f5cf1d5 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs @@ -20,19 +20,10 @@ public class GetTracksCommandTests : CommandTestsBase public GetTracksCommandTests() { - _command = new GetTracksCommand(MAuth.Object, "rj", "", "", DateTime.MinValue) { Count = 1 - }; - //_command = new GetTracksCommand(MAuth.Object, ) - //{ - // AlbumName = "Ray of Light", - // ArtistName = "Madonna" - //}; - //_command.SetParameters(); - - + }; } diff --git a/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs index 3a858c1..9feff12 100644 --- a/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs @@ -53,16 +53,10 @@ public async override Task> HandleResponse(HttpResponseM var tracksToken = jtoken.SelectToken("track"); - IEnumerable tracks = tracksToken.Type == JTokenType.Array - ? tracksToken.Children().Select(t => LastTrack.ParseJToken(t)) - : new List() { LastTrack.ParseJToken(tracksToken) }; + var pageInfoToken = jtoken.SelectToken("@attr"); + + return PageResponse.CreateSuccessResponse(tracksToken, pageInfoToken, LastTrack.ParseJToken, false); - var pageresponse = PageResponse.CreateSuccessResponse(tracks); - - var attrToken = jtoken.SelectToken("@attr"); - pageresponse.AddPageInfoFromJToken(attrToken); - - return pageresponse; } else { From 73835fc447703847f8b31d6edd24d9ba813873e3 Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Mon, 22 Dec 2014 23:19:29 +0000 Subject: [PATCH 06/11] Style changes and a bit of tidying, rename some commands (#43) Also excluding Object tests temporarily --- .../Api/Commands/CommandTestsBase.cs | 31 ++++-------- ...sts.cs => LibraryGetTracksCommandTests.cs} | 44 ++++++----------- ....cs => UserGetRecentTracksCommandTests.cs} | 49 +++++-------------- .../IF.Lastfm.Core.Tests.csproj | 3 +- .../Api/Commands/LastAsyncCommandBase.cs | 2 - ...sCommand.cs => LibraryGetTracksCommand.cs} | 11 ++--- ...mmand.cs => UserGetRecentTracksCommand.cs} | 38 ++------------ src/IF.Lastfm.Core/Api/LibraryApi.cs | 19 ++----- src/IF.Lastfm.Core/Api/UserApi.cs | 24 ++------- src/IF.Lastfm.Core/IF.Lastfm.Core.csproj | 4 +- src/IF.Lastfm.Core/Objects/LastImageSet.cs | 4 +- src/IF.Lastfm.Core/Objects/LastTrack.cs | 6 +-- 12 files changed, 60 insertions(+), 175 deletions(-) rename src/IF.Lastfm.Core.Tests/Api/Commands/Library/{GetTracksCommandTests.cs => LibraryGetTracksCommandTests.cs} (73%) rename src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/{GetRecentScrobblesCommandTests.cs => UserGetRecentTracksCommandTests.cs} (66%) rename src/IF.Lastfm.Core/Api/Commands/LibraryApi/{GetTracksCommand.cs => LibraryGetTracksCommand.cs} (82%) rename src/IF.Lastfm.Core/Api/Commands/UserApi/{GetRecentScrobblesCommand.cs => UserGetRecentTracksCommand.cs} (53%) diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs index 1603a3d..51b5f7e 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs @@ -31,45 +31,34 @@ protected HttpResponseMessage CreateResponseMessage(string message) return response; } - public void CheckResult(object expected, object actual) + private static void JsonCompare(object expected, object actual) { var expectedJson = JsonConvert.SerializeObject(expected, Formatting.Indented); var actualJson = JsonConvert.SerializeObject(actual, Formatting.Indented); Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); - - } - public async Task CheckResult_Single(GetAsyncCommandBase> _command, object expected, byte[] Data) + protected async Task CompareResultsSingle(GetAsyncCommandBase> command, object expected, byte[] resource) { + var response = CreateResponseMessage(Encoding.UTF8.GetString(resource)); - - var response = CreateResponseMessage(Encoding.UTF8.GetString(Data)); - //Check if object not array - var parsed = await _command.HandleResponse(response); + var parsed = await command.HandleResponse(response); Assert.IsTrue(parsed.Success); - var actual = parsed.Content; - - CheckResult(expected, actual); - + JsonCompare(expected, actual); } - public async Task CheckResult_MultipleSample(GetAsyncCommandBase> _command, object expected, int arrayID, byte[] Data) + protected async Task CompareResultsMultiple(GetAsyncCommandBase> command, object expected, byte[] resource, int itemIndex) { + var response = CreateResponseMessage(Encoding.UTF8.GetString(resource)); - - var response = CreateResponseMessage(Encoding.UTF8.GetString(Data)); - var parsed = await _command.HandleResponse(response); + var parsed = await command.HandleResponse(response); Assert.IsTrue(parsed.Success); - - var actual = parsed.Content[arrayID]; - - CheckResult(expected, actual); - + var actual = parsed.Content[itemIndex]; + JsonCompare(expected, actual); } } } diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/LibraryGetTracksCommandTests.cs similarity index 73% rename from src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs rename to src/IF.Lastfm.Core.Tests/Api/Commands/Library/LibraryGetTracksCommandTests.cs index f5cf1d5..9abc67f 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/Library/GetTracksCommandTests.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/Library/LibraryGetTracksCommandTests.cs @@ -1,35 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using IF.Lastfm.Core.Api.Commands.LibraryApi; +using IF.Lastfm.Core.Api.Commands.LibraryApi; using IF.Lastfm.Core.Api.Enums; using IF.Lastfm.Core.Objects; using IF.Lastfm.Core.Tests.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -using Newtonsoft.Json; -namespace IF.Lastfm.Core.Tests.Api.Commands.LibraryApi +namespace IF.Lastfm.Core.Tests.Api.Commands.Library { [TestClass] - public class GetTracksCommandTests : CommandTestsBase + public class LibraryGetTracksCommandTests : CommandTestsBase { - private GetTracksCommand _command; + private readonly LibraryGetTracksCommand _command; - public GetTracksCommandTests() + public LibraryGetTracksCommandTests() { - - _command = new GetTracksCommand(MAuth.Object, "rj", "", "", DateTime.MinValue) + _command = new LibraryGetTracksCommand(MAuth.Object, "rj", "", "", DateTime.MinValue) { Count = 1 }; } - - - + [TestMethod] - public async Task HandleSuccessResponse_Library_GetTracks_Multiple() + public async Task HandleResponseMultiple() { //Testing the second track returned var expectedTrack = new LastTrack @@ -37,14 +32,11 @@ public async Task HandleSuccessResponse_Library_GetTracks_Multiple() ArtistName = "Stevie Wonder", Duration = new TimeSpan(0, 4, 8), TotalPlayCount = 56, - //TimePlayed = new DateTime(2014, 12, 19, 16, 13, 55, DateTimeKind.Utc), Mbid = "0161855d-0b98-4f2d-b2ab-446dbd8d6759", Name = "Superstition", ArtistMbid = "1ee18fb3-18a6-4c7f-8ba0-bc41cdd0462e", AlbumName = "Number Ones", Url = new Uri("http://www.last.fm/music/Stevie+Wonder/_/Superstition", UriKind.Absolute), - - // Id = "1934", Images = new LastImageSet( "http://userserve-ak.last.fm/serve/34s/99695819.jpg", "http://userserve-ak.last.fm/serve/64s/99695819.jpg", @@ -53,14 +45,12 @@ public async Task HandleSuccessResponse_Library_GetTracks_Multiple() }; - - await CheckResult_MultipleSample(_command, expectedTrack, 1, LibraryApiResponses.LibraryGetTracksMultiple); + await CompareResultsMultiple(_command, expectedTrack, LibraryApiResponses.LibraryGetTracksMultiple, 1); } [TestMethod] - public async Task HandleSuccessResponse_Library_GetTracks_Single() + public async Task HandleResponseSingle() { - //Broken until single objects work in the parser var expectedTrack = new LastTrack { ArtistName = "Dire Straits", @@ -71,24 +61,18 @@ public async Task HandleSuccessResponse_Library_GetTracks_Single() ArtistMbid = "614e3804-7d34-41ba-857f-811bad7c2b7a", AlbumName = "Dire Straits (Remastered)", Url = new Uri("http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing", UriKind.Absolute), - - //Id = "1934", Images = new LastImageSet( "http://userserve-ak.last.fm/serve/34s/56827829.jpg", "http://userserve-ak.last.fm/serve/64s/56827829.jpg", "http://userserve-ak.last.fm/serve/126/56827829.jpg", "http://userserve-ak.last.fm/serve/300x300/56827829.jpg") - }; - var expected = new List { expectedTrack }; - await CheckResult_Single(_command, expected, LibraryApiResponses.LibraryGetTracksSingle); - + await CompareResultsSingle(_command, expected, LibraryApiResponses.LibraryGetTracksSingle); } - - + [TestMethod] public async Task HandleErrorResponse() { diff --git a/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs b/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/UserGetRecentTracksCommandTests.cs similarity index 66% rename from src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs rename to src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/UserGetRecentTracksCommandTests.cs index d832ebc..28af364 100644 --- a/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/GetRecentScrobblesCommandTests.cs +++ b/src/IF.Lastfm.Core.Tests/Api/Commands/UserApi/UserGetRecentTracksCommandTests.cs @@ -1,73 +1,56 @@ -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using IF.Lastfm.Core.Api.Commands.UserApi; +using IF.Lastfm.Core.Api.Commands.UserApi; using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Objects; using IF.Lastfm.Core.Tests.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; -using IF.Lastfm.Core.Api.Commands.LibraryApi; -using IF.Lastfm.Core.Objects; using System; -using Newtonsoft.Json; using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; namespace IF.Lastfm.Core.Tests.Api.Commands.UserApi { [TestClass] - public class GetRecentScrobblesCommandTests : CommandTestsBase + public class UserGetRecentTracksCommandTests : CommandTestsBase { - private GetRecentScrobblesCommand _command; + private UserGetRecentTracksCommand _command; - //private const string apiKey = "a6ab4b9376e54cdb06912bfbd9c1f288"; - //private const string apiSecret = "3aa7202fd1bc6d5a7ac733246cbccc4b"; - - public GetRecentScrobblesCommandTests() + public UserGetRecentTracksCommandTests() { - _command = new GetRecentScrobblesCommand(MAuth.Object, "rj", System.DateTime.MinValue) + _command = new UserGetRecentTracksCommand(MAuth.Object, "rj", DateTime.MinValue) { Count = 1 }; } - [TestMethod] - public async Task HandleSuccessResponse_User_GetRecentScrobbles_Multiple() + public async Task HandleResponseMultiple() { - //Testing the second track returned var expectedTrack = new LastTrack { ArtistName = "The Who", - // Duration = new TimeSpan(0, 3, 47), - //TotalPlayCount = 81, TimePlayed = new DateTime(2014, 12, 19, 16, 13, 55,DateTimeKind.Utc), Mbid = "79f3dc97-2297-47ee-8556-9a1bb4b48d53", Name = "Pinball Wizard", ArtistMbid = "9fdaa16b-a6c4-4831-b87c-bc9ca8ce7eaa", AlbumName = "Tommy (Remastered)", Url = new Uri("http://www.last.fm/music/The+Who/_/Pinball+Wizard", UriKind.Absolute), - - // Id = "1934", Images = new LastImageSet( "http://userserve-ak.last.fm/serve/34s/35234991.jpg", "http://userserve-ak.last.fm/serve/64s/35234991.jpg", "http://userserve-ak.last.fm/serve/126/35234991.jpg", "http://userserve-ak.last.fm/serve/300x300/35234991.jpg") - }; - - await CheckResult_MultipleSample(_command, expectedTrack, 2, UserApiResponses.UserGetRecentTracksMultiple); + await CompareResultsMultiple(_command, expectedTrack, UserApiResponses.UserGetRecentTracksMultiple, 2); } [TestMethod] - public async Task HandleSuccessResponse_User_GetRecentScrobbles_Single() + public async Task HandleResponseSingle() { - //Broken until single objects work in the parser var expectedTrack = new LastTrack { ArtistName = "Rick James", - // Duration = new TimeSpan(0, 3, 47), - //TotalPlayCount = 81, Mbid = "", Name = "Super Freak (Part 1) - 1981 Single Version", ArtistMbid = "cba9cec2-be8d-41bd-91b4-a1cd7de39b0c", @@ -75,25 +58,20 @@ public async Task HandleSuccessResponse_User_GetRecentScrobbles_Single() TimePlayed = new DateTime(2014,12,20,10,16,52, DateTimeKind.Utc), AlbumName = "The Definitive Collection", Url = new Uri("http://www.last.fm/music/Rick+James/_/Super+Freak+(Part+1)+-+1981+Single+Version", UriKind.Absolute), - - // Id = "1934", Images = new LastImageSet( "http://userserve-ak.last.fm/serve/34s/90462319.jpg", "http://userserve-ak.last.fm/serve/64s/90462319.jpg", "http://userserve-ak.last.fm/serve/126/90462319.jpg", "http://userserve-ak.last.fm/serve/300x300/90462319.jpg") - }; - var expected = new List { expectedTrack }; - await CheckResult_Single(_command, expected, UserApiResponses.UserGetRecentTracksSingle); - + await CompareResultsSingle(_command, expected, UserApiResponses.UserGetRecentTracksSingle); } [TestMethod] - public async Task HandleErrorResponse_User_GetRecentScrobbles() + public async Task HandleErrorResponse() { var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetRecentTracksError)); @@ -102,6 +80,5 @@ public async Task HandleErrorResponse_User_GetRecentScrobbles() Assert.IsFalse(parsed.Success); Assert.IsTrue(parsed.Error == LastFmApiError.MissingParameters); } - } } diff --git a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj index 60c6f32..6d3bb29 100644 --- a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj +++ b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj @@ -87,8 +87,6 @@ - - True @@ -157,6 +155,7 @@ ResXFileCodeGenerator LibraryApiResponses.Designer.cs + Designer ResXFileCodeGenerator diff --git a/src/IF.Lastfm.Core/Api/Commands/LastAsyncCommandBase.cs b/src/IF.Lastfm.Core/Api/Commands/LastAsyncCommandBase.cs index f3bca4d..9972353 100644 --- a/src/IF.Lastfm.Core/Api/Commands/LastAsyncCommandBase.cs +++ b/src/IF.Lastfm.Core/Api/Commands/LastAsyncCommandBase.cs @@ -54,8 +54,6 @@ protected void DisableCaching() public abstract Task HandleResponse(HttpResponseMessage response); - /// - /// protected HttpClient GetHttpClient() { var client = new HttpClient(); diff --git a/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/LibraryGetTracksCommand.cs similarity index 82% rename from src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs rename to src/IF.Lastfm.Core/Api/Commands/LibraryApi/LibraryGetTracksCommand.cs index 9feff12..d152699 100644 --- a/src/IF.Lastfm.Core/Api/Commands/LibraryApi/GetTracksCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/LibraryApi/LibraryGetTracksCommand.cs @@ -4,14 +4,12 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; -using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -using System.Linq; namespace IF.Lastfm.Core.Api.Commands.LibraryApi { - internal class GetTracksCommand : GetAsyncCommandBase> + internal class LibraryGetTracksCommand : GetAsyncCommandBase> { public string Username { get; private set; } @@ -21,7 +19,7 @@ internal class GetTracksCommand : GetAsyncCommandBase> public DateTime From { get; private set; } - public GetTracksCommand(ILastAuth auth, string username, string artist, string album, DateTime from) : base(auth) + public LibraryGetTracksCommand(ILastAuth auth, string username, string artist, string album, DateTime from) : base(auth) { Method = "library.getTracks"; @@ -49,14 +47,11 @@ public async override Task> HandleResponse(HttpResponseM LastFmApiError error; if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode) { - JToken jtoken = JsonConvert.DeserializeObject(json).SelectToken("tracks"); - + var jtoken = JsonConvert.DeserializeObject(json).SelectToken("tracks"); var tracksToken = jtoken.SelectToken("track"); - var pageInfoToken = jtoken.SelectToken("@attr"); return PageResponse.CreateSuccessResponse(tracksToken, pageInfoToken, LastTrack.ParseJToken, false); - } else { diff --git a/src/IF.Lastfm.Core/Api/Commands/UserApi/GetRecentScrobblesCommand.cs b/src/IF.Lastfm.Core/Api/Commands/UserApi/UserGetRecentTracksCommand.cs similarity index 53% rename from src/IF.Lastfm.Core/Api/Commands/UserApi/GetRecentScrobblesCommand.cs rename to src/IF.Lastfm.Core/Api/Commands/UserApi/UserGetRecentTracksCommand.cs index fdc9cbe..0f1eec7 100644 --- a/src/IF.Lastfm.Core/Api/Commands/UserApi/GetRecentScrobblesCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/UserApi/UserGetRecentTracksCommand.cs @@ -11,13 +11,13 @@ namespace IF.Lastfm.Core.Api.Commands.UserApi { - internal class GetRecentScrobblesCommand : GetAsyncCommandBase> + internal class UserGetRecentTracksCommand : GetAsyncCommandBase> { public string Username { get; private set; } public DateTime From { get; private set; } - public GetRecentScrobblesCommand(ILastAuth auth, string username, DateTime from) : base(auth) + public UserGetRecentTracksCommand(ILastAuth auth, string username, DateTime from) : base(auth) { Method = "user.getRecentTracks"; @@ -41,39 +41,11 @@ public async override Task> HandleResponse(HttpResponseM LastFmApiError error; if (LastFm.IsResponseValid(json, out error) && response.IsSuccessStatusCode) { - JToken jtoken = JsonConvert.DeserializeObject(json).SelectToken("recenttracks"); - - - - - IEnumerable tracks; - - var tracksToken = jtoken.SelectToken("track"); - - - tracks = tracksToken.Type == JTokenType.Array - ? tracksToken.Children().Select(t => LastTrack.ParseJToken(t)) - : new List() { LastTrack.ParseJToken(tracksToken) }; - - - - - - - //var tracks = new List(); - //foreach (var track in tracksToken.Children()) - //{ - // var t = LastTrack.ParseJToken(track); - - // tracks.Add(t); - //} - - var pageresponse = PageResponse.CreateSuccessResponse(tracks); - + var jtoken = JsonConvert.DeserializeObject(json).SelectToken("recenttracks"); + var itemsToken = jtoken.SelectToken("track"); var attrToken = jtoken.SelectToken("@attr"); - pageresponse.AddPageInfoFromJToken(attrToken); - return pageresponse; + return PageResponse.CreateSuccessResponse(itemsToken, attrToken, LastTrack.ParseJToken, false); } else { diff --git a/src/IF.Lastfm.Core/Api/LibraryApi.cs b/src/IF.Lastfm.Core/Api/LibraryApi.cs index 4062984..355ffa7 100644 --- a/src/IF.Lastfm.Core/Api/LibraryApi.cs +++ b/src/IF.Lastfm.Core/Api/LibraryApi.cs @@ -1,9 +1,8 @@ -using System; -using System.Threading.Tasks; -using IF.Lastfm.Core.Api.Commands.LibraryApi; -using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Api.Commands.LibraryApi; using IF.Lastfm.Core.Api.Helpers; using IF.Lastfm.Core.Objects; +using System; +using System.Threading.Tasks; namespace IF.Lastfm.Core.Api { @@ -11,19 +10,9 @@ public class LibraryApi : ILibraryApi { public ILastAuth Auth { get; private set; } - /// - /// Gets scrobbles and stuff - /// - /// - /// - /// - /// - /// - /// - /// public async Task> GetTracks(string username, string artist, string album, DateTime since, int pagenumber = 0, int count = LastFm.DefaultPageLength) { - var command = new GetTracksCommand(Auth, username, artist, album, since) + var command = new LibraryGetTracksCommand(Auth, username, artist, album, since) { Page = pagenumber, Count = count diff --git a/src/IF.Lastfm.Core/Api/UserApi.cs b/src/IF.Lastfm.Core/Api/UserApi.cs index a277998..7736c97 100644 --- a/src/IF.Lastfm.Core/Api/UserApi.cs +++ b/src/IF.Lastfm.Core/Api/UserApi.cs @@ -1,9 +1,9 @@ -using System; -using System.Threading.Tasks; -using IF.Lastfm.Core.Api.Commands.UserApi; +using IF.Lastfm.Core.Api.Commands.UserApi; using IF.Lastfm.Core.Api.Enums; using IF.Lastfm.Core.Api.Helpers; using IF.Lastfm.Core.Objects; +using System; +using System.Threading.Tasks; namespace IF.Lastfm.Core.Api { @@ -16,14 +16,6 @@ public UserApi(ILastAuth auth) Auth = auth; } - /// - /// Gets the top albums for the given user. - /// - /// - /// - /// - /// - /// public async Task> GetTopAlbums(string username, LastStatsTimeSpan span, int pagenumber = 0, int count = LastFm.DefaultPageLength) { var command = new GetTopAlbumsCommand(Auth, username, span) @@ -35,17 +27,9 @@ public async Task> GetTopAlbums(string username, LastSta return await command.ExecuteAsync(); } - /// - /// Gets scrobbles and stuff - /// - /// - /// - /// - /// - /// public async Task> GetRecentScrobbles(string username, DateTime since, int pagenumber = 0, int count = LastFm.DefaultPageLength) { - var command = new GetRecentScrobblesCommand(Auth, username, since) + var command = new UserGetRecentTracksCommand(Auth, username, since) { Page = pagenumber, Count = count diff --git a/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj b/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj index 10fc65c..4d7c41b 100644 --- a/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj +++ b/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj @@ -41,7 +41,7 @@ - + @@ -72,7 +72,7 @@ - + diff --git a/src/IF.Lastfm.Core/Objects/LastImageSet.cs b/src/IF.Lastfm.Core/Objects/LastImageSet.cs index 2a536e9..934b182 100644 --- a/src/IF.Lastfm.Core/Objects/LastImageSet.cs +++ b/src/IF.Lastfm.Core/Objects/LastImageSet.cs @@ -11,7 +11,7 @@ public LastImageSet() { } - public LastImageSet(string s, string m, string l, string xl, string xxl=null) + public LastImageSet(string s, string m, string l, string xl, string xxl = null) { Small = new Uri(s); Medium = new Uri(m); @@ -19,7 +19,9 @@ public LastImageSet(string s, string m, string l, string xl, string xxl=null) ExtraLarge = new Uri(xl); if (xxl != null) + { Mega = new Uri(xxl); + } } public Uri Small { get; set; } diff --git a/src/IF.Lastfm.Core/Objects/LastTrack.cs b/src/IF.Lastfm.Core/Objects/LastTrack.cs index 523d6b4..88e35ac 100644 --- a/src/IF.Lastfm.Core/Objects/LastTrack.cs +++ b/src/IF.Lastfm.Core/Objects/LastTrack.cs @@ -34,11 +34,7 @@ public class LastTrack : ILastfmObject public int? Rank { get; set; } #endregion - - public LastTrack() - { - } - + /// /// Parses the given JToken into a track /// From 564b0dc8de8f855744c7174b2c97ed74a4b508f5 Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Mon, 22 Dec 2014 23:29:53 +0000 Subject: [PATCH 07/11] Forgot to commit the project file..... http://i.imgur.com/QDgKUpw.jpg --- src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj index 6d3bb29..d0c1160 100644 --- a/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj +++ b/src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj @@ -79,9 +79,9 @@ - + - + From 65c21565ab55b6a1d4621a3f2b65f4dbb8f19dc1 Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Mon, 22 Dec 2014 23:34:04 +0000 Subject: [PATCH 08/11] Make ILastFmObject internal so it's only visible to Syro, closes #44 --- src/IF.Lastfm.Core/Objects/ILastFmObject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IF.Lastfm.Core/Objects/ILastFmObject.cs b/src/IF.Lastfm.Core/Objects/ILastFmObject.cs index e54848e..966548b 100644 --- a/src/IF.Lastfm.Core/Objects/ILastFmObject.cs +++ b/src/IF.Lastfm.Core/Objects/ILastFmObject.cs @@ -1,6 +1,6 @@ namespace IF.Lastfm.Core.Objects { - public interface ILastfmObject + internal interface ILastfmObject { } From dd0fdd24307eb08fd09e1df751aec753b8040d16 Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Mon, 22 Dec 2014 23:38:55 +0000 Subject: [PATCH 09/11] Update PROGRESS.md - 105 remain --- PROGRESS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PROGRESS.md b/PROGRESS.md index 96ec1b0..7b46411 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -1,4 +1,4 @@ -# Api Progress ![Progress](http://progressed.io/bar/21) +# Api Progress ![Progress](http://progressed.io/bar/22) These are all the Last.fm API methods currently available. @@ -6,7 +6,7 @@ These are all the Last.fm API methods currently available. - Methods ~~marked with strikethrough~~ aren't currently implemented. Pull requests are welcome! - Methods _marked with an asterisk *_ aren't listed on [the Last.fm documentation](http://www.last.fm/api), so they might not work! -This list is generated by the [ProgressReport](https://github.com/inflatablefriends/lastfm/tree/master/src/IF.Lastfm.ProgressReport) tool in the solution. Last updated on 08 December 2014 10:51 +This list is generated by the [ProgressReport](https://github.com/inflatablefriends/lastfm/tree/master/src/IF.Lastfm.ProgressReport) tool in the solution. Last updated on 22 December 2014 23:37 ## Album - [album.getInfo](http://www.last.fm/api/show/album.getInfo) @@ -89,12 +89,12 @@ This list is generated by the [ProgressReport](https://github.com/inflatablefrie ## Library +- [library.getTracks](http://www.last.fm/api/show/library.getTracks) - ~~[library.addAlbum](http://www.last.fm/api/show/library.addAlbum)~~ - ~~[library.addArtist](http://www.last.fm/api/show/library.addArtist)~~ - ~~[library.addTrack](http://www.last.fm/api/show/library.addTrack)~~ - ~~[library.getAlbums](http://www.last.fm/api/show/library.getAlbums)~~ - ~~[library.getArtists](http://www.last.fm/api/show/library.getArtists)~~ -- ~~[library.getTracks](http://www.last.fm/api/show/library.getTracks)~~ - ~~[library.removeAlbum](http://www.last.fm/api/show/library.removeAlbum)~~ - ~~[library.removeArtist](http://www.last.fm/api/show/library.removeArtist)~~ - ~~[library.removeScrobble](http://www.last.fm/api/show/library.removeScrobble)~~ From 063a7466a0e4f12daaac76a08d03473f0d07474d Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Mon, 22 Dec 2014 23:40:39 +0000 Subject: [PATCH 10/11] Version 0.1.3 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 0dcc966..875ce61 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -40,7 +40,7 @@ - release # don't forget to update this! - version: 0.1.2.{build} + version: 0.1.3.{build} assembly_info: patch: true From f267ab17359f2feb92e65e504d9f9b0c47772846 Mon Sep 17 00:00:00 2001 From: Rikki Tooley Date: Tue, 23 Dec 2014 00:07:37 +0000 Subject: [PATCH 11/11] Remove CatchRequestExceptions option, closes #23 --- .../Api/Commands/GetAsyncCommandBase.cs | 11 ++--------- .../Api/Commands/PostAsyncCommandBase.cs | 9 +-------- src/IF.Lastfm.Core/LastFm.cs | 11 ----------- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/src/IF.Lastfm.Core/Api/Commands/GetAsyncCommandBase.cs b/src/IF.Lastfm.Core/Api/Commands/GetAsyncCommandBase.cs index 0446ee0..abe1022 100644 --- a/src/IF.Lastfm.Core/Api/Commands/GetAsyncCommandBase.cs +++ b/src/IF.Lastfm.Core/Api/Commands/GetAsyncCommandBase.cs @@ -14,7 +14,7 @@ protected GetAsyncCommandBase(ILastAuth auth) Auth = auth; } - public async override Task ExecuteAsync() + public override async Task ExecuteAsync() { SetParameters(); @@ -30,14 +30,7 @@ public async override Task ExecuteAsync() } catch (HttpRequestException) { - if (LastFm.CatchRequestExceptions) - { - return LastResponse.CreateErrorResponse(LastFmApiError.RequestFailed); - } - else - { - throw; - } + throw; } } diff --git a/src/IF.Lastfm.Core/Api/Commands/PostAsyncCommandBase.cs b/src/IF.Lastfm.Core/Api/Commands/PostAsyncCommandBase.cs index 0520208..d03cb5c 100644 --- a/src/IF.Lastfm.Core/Api/Commands/PostAsyncCommandBase.cs +++ b/src/IF.Lastfm.Core/Api/Commands/PostAsyncCommandBase.cs @@ -39,14 +39,7 @@ public override async Task ExecuteAsync() } catch (HttpRequestException) { - if (LastFm.CatchRequestExceptions) - { - return LastResponse.CreateErrorResponse(LastFmApiError.RequestFailed); - } - else - { - throw; - } + return LastResponse.CreateErrorResponse(LastFmApiError.RequestFailed); } } } diff --git a/src/IF.Lastfm.Core/LastFm.cs b/src/IF.Lastfm.Core/LastFm.cs index db6e97b..18b4ac6 100644 --- a/src/IF.Lastfm.Core/LastFm.cs +++ b/src/IF.Lastfm.Core/LastFm.cs @@ -27,17 +27,6 @@ public class LastFm #endregion - /// - /// Determines whether commands should throw HttpRequestExceptions or wrap them - /// in the response. - /// - /// Using this can make client code neater, but it violates the principles of - /// separation of concerns and single responsibility a bit. This property won't - /// get removed but please only use it if you understand what it does! - /// - [Obsolete] - public static bool CatchRequestExceptions { get; set; } - #region Api helper methods public static string FormatApiUrl(string method, string apikey, Dictionary parameters = null, bool secure = false)