diff --git a/LibMpc/Commands/Commands.Database.cs b/LibMpc/Commands/Commands.Database.cs index 20d78d0..9f9844e 100644 --- a/LibMpc/Commands/Commands.Database.cs +++ b/LibMpc/Commands/Commands.Database.cs @@ -67,20 +67,39 @@ namespace LibMpc // TODO: findadd - public class ListAll : IMpcCommand>> + public class ListAll : IMpcCommand>>> { public string Value => "listall"; - public IDictionary>> FormatResponse(IList> response) + public IDictionary>>> FormatResponse(IList> response) { - var results = new Dictionary>> + var results = new Dictionary>>> { - { "result", new List>() } + { "directories", new List>>() } }; - - foreach (var keyValuePair in response) + + // Add by default the root directory + results["directories"].Add(new Dictionary> { - results["result"].Add(keyValuePair); + { "path", new List() }, + { "files", new List() } + }); + + foreach (var line in response) + { + if (line.Key.Equals("file")) + { + results["directories"].Last()["files"].Add(line.Value); + } + + if (line.Key.Equals("directory")) + { + results["directories"].Add(new Dictionary> + { + { "path", new []{ line.Value } }, + { "files", new List() } + }); + } } return results; diff --git a/LibMpcTest/LibMpcTest.cs b/LibMpcTest/LibMpcTest.cs index 868a680..ace1279 100644 --- a/LibMpcTest/LibMpcTest.cs +++ b/LibMpcTest/LibMpcTest.cs @@ -53,7 +53,8 @@ namespace LibMpcTest Console.Out.WriteLine("ListAllTest Result:"); Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); - // TODO: Assert + Assert.True(response.Response.Body.Keys.Contains("directories")); + Assert.True(response.Response.Body["directories"].Count.Equals(5)); } public void Dispose()