From 679748b2079b10aeb0cad2efa840078221d1e35f Mon Sep 17 00:00:00 2001 From: glucaci Date: Mon, 30 Jan 2017 11:52:35 +0100 Subject: [PATCH] ListPlaylistInfo command and UnitTest. --- LibMpc/Commands/Commands.Playlists.cs | 31 +++++++++++++++++++++++ LibMpcTest/Tests/PlaylistsCommandsTest.cs | 18 +++++++++++++ 2 files changed, 49 insertions(+) diff --git a/LibMpc/Commands/Commands.Playlists.cs b/LibMpc/Commands/Commands.Playlists.cs index 0d5bb67..9250ab3 100644 --- a/LibMpc/Commands/Commands.Playlists.cs +++ b/LibMpc/Commands/Commands.Playlists.cs @@ -40,6 +40,37 @@ namespace LibMpc } } + public class ListPlaylistInfo : IMpcCommand> + { + private readonly string _playlistName; + + public ListPlaylistInfo(string playlistName) + { + _playlistName = playlistName; + } + + public string Value => string.Join(" ", "listplaylistinfo", $"\"{_playlistName}\""); + + public IEnumerable FormatResponse(IList> response) + { + var results = new List(); + + foreach (var line in response) + { + if (line.Key.Equals("file")) + { + results.Add(new MpdFile(line.Value)); + } + else + { + results.Last().AddTag(line.Key, line.Value); + } + } + + return results; + } + } + /// /// Prints a list of the playlist directory. /// diff --git a/LibMpcTest/Tests/PlaylistsCommandsTest.cs b/LibMpcTest/Tests/PlaylistsCommandsTest.cs index 41a0a26..a65297c 100644 --- a/LibMpcTest/Tests/PlaylistsCommandsTest.cs +++ b/LibMpcTest/Tests/PlaylistsCommandsTest.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Xunit; using LibMpc; using System.Linq; +using Xunit.Abstractions; namespace LibMpcTest { @@ -22,6 +23,23 @@ namespace LibMpcTest Assert.True(response.Response.Body.Count().Equals(numberOfFiles)); } + [Theory] + [InlineData("Playlist One", 5)] + [InlineData("Playlist Two", 3)] + [InlineData("_My Playlist", 5)] + public async Task ListPlaylistInfoTest(string playlistName, int numberOfFiles) + { + var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylistInfo(playlistName)); + + TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:"); + TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); + + Assert.True(response.Response.Body.Count().Equals(numberOfFiles)); + Assert.True(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Artist))); + Assert.True(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Title))); + Assert.True(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Date))); + } + [Fact] public async Task ListPlaylistsTest() {