diff --git a/LibMpc/Commands/Commands.Database.cs b/LibMpc/Commands/Commands.Database.cs index 3d4a1cd..a791b8a 100644 --- a/LibMpc/Commands/Commands.Database.cs +++ b/LibMpc/Commands/Commands.Database.cs @@ -16,7 +16,7 @@ namespace LibMpc /// /// Finds songs in the database that is exactly "searchText". /// - public class Find : IMpcCommand> + public class Find : IMpcCommand> { private readonly ITag _tag; private readonly string _searchText; @@ -29,25 +29,19 @@ namespace LibMpc public string Value => string.Join(" ", "find", _tag.Value, _searchText); - public IEnumerable FormatResponse(IList> response) + public IEnumerable FormatResponse(IList> response) { var results = new List(); - var mpdFile = MpdFile.EmptyFile; foreach (var line in response) { if (line.Key.Equals("file")) { - if (mpdFile.IsInitialized) - { - results.Add(mpdFile); - } - - mpdFile = new MpdFile(line.Value); + results.Add(new MpdFile(line.Value)); } else { - mpdFile.AddTag(line.Key, line.Value); + results.Last().AddTag(line.Key, line.Value); } } diff --git a/LibMpc/Types/IMpdFile.cs b/LibMpc/Types/IMpdFile.cs new file mode 100644 index 0000000..2c2ed69 --- /dev/null +++ b/LibMpc/Types/IMpdFile.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +namespace LibMpc.Types +{ + public interface IMpdFilePath + { + string File { get; } + } + + public interface IMpdFile : IMpdFilePath + { + int Time { get; } + string Album { get; } + string Artist { get; } + string Title { get; } + string Track { get; } + string Name { get; } + string Genre { get; } + string Date { get; } + string Composer { get; } + string Performer { get; } + string Comment { get; } + int Disc { get; } + int Pos { get; } + int Id { get; } + IDictionary UnknownTags { get; } + } +} \ No newline at end of file diff --git a/LibMpc/Types/MpdFile.cs b/LibMpc/Types/MpdFile.cs index c57372f..22133e1 100644 --- a/LibMpc/Types/MpdFile.cs +++ b/LibMpc/Types/MpdFile.cs @@ -5,10 +5,8 @@ namespace LibMpc.Types /// /// The MpdFile class contains all meta data for a file of the MPD. /// - public class MpdFile + public class MpdFile : IMpdFile { - public static readonly MpdFile EmptyFile = new MpdFile(string.Empty); - private const string TagTime = "Time"; private const string TagArtist = "Artist"; private const string TagAlbum = "Album"; @@ -28,8 +26,9 @@ namespace LibMpc.Types public MpdFile(string file) { + file.CheckNotNull(); + File = file; - IsInitialized = !string.IsNullOrEmpty(File); } public string File { get; } @@ -49,8 +48,6 @@ namespace LibMpc.Types public int Id { get; private set; } = -1; public IDictionary UnknownTags => _unknownTags; - internal bool IsInitialized { get; } - internal void AddTag(string tag, string value) { switch (tag) diff --git a/LibMpcTest/Tests/DatabaseCommandsTest.cs b/LibMpcTest/Tests/DatabaseCommandsTest.cs index e8a7c56..b6194cc 100644 --- a/LibMpcTest/Tests/DatabaseCommandsTest.cs +++ b/LibMpcTest/Tests/DatabaseCommandsTest.cs @@ -27,7 +27,7 @@ namespace LibMpcTest TestOutput.WriteLine("FindGenreTest Result:"); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); - Assert.True(response.Response.Body.Count().Equals(6)); + Assert.True(response.Response.Body.Count().Equals(7)); } } } \ No newline at end of file