Skip to content

Commit

Permalink
Command for Current Queue implemented + tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci committed Apr 13, 2017
1 parent 6cfbb61 commit 6426d98
Show file tree
Hide file tree
Showing 19 changed files with 584 additions and 39 deletions.
32 changes: 31 additions & 1 deletion src/MpcNET.Test/LibMpcTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MpcNET.Test
{
Expand All @@ -23,5 +26,32 @@ public static void Cleanup()
}

internal static Mpc Mpc { get; private set; }

private static async Task SendCommand(string command)
{
var response = await Mpc.SendAsync(new PassthroughCommand(command));
TestOutput.WriteLine(response);
}
private static async Task SendCommand<T>(IMpcCommand<T> command)
{
var response = await Mpc.SendAsync(command);
TestOutput.WriteLine(response);
}

private class PassthroughCommand : IMpcCommand<IList<string>>
{
public PassthroughCommand(string command)
{
Value = command;
}

public string Value { get; }

public IList<string> FormatResponse(IList<KeyValuePair<string, string>> response)
{
var result = response.Select(atrb => $"{atrb.Key}: {atrb.Value}").ToList();
return result;
}
}
}
}
1 change: 0 additions & 1 deletion src/MpcNET.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
1 change: 1 addition & 0 deletions src/MpcNET.Test/Server/StartLocal.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mpd.exe mpd.conf -v
30 changes: 30 additions & 0 deletions src/MpcNET.Test/Server/mpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
log_file "mpd_log.txt"

db_file "mpd.db"

bind_to_address "any"

music_directory "Music"

playlist_directory "Playlists"

port "6600"

audio_output {
type "null"
name "Enabled output to be disabled"
enabled "true"
mixer_type "none"
}
audio_output {
type "null"
name "Disabled output to be enabled"
enabled "false"
mixer_type "none"
}
audio_output {
type "null"
name "Enabled output to be toggled"
enabled "true"
mixer_type "none"
}
88 changes: 88 additions & 0 deletions src/MpcNET.Test/Server/mpd_log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Apr 12 14:17 : client: [0] opened from 127.0.0.1:65192
Apr 12 14:17 : client: [0] expired
Apr 12 14:17 : client: [0] closed
Apr 12 14:17 : client: [1] opened from 127.0.0.1:65193
Apr 12 14:17 : client: [1] expired
Apr 12 14:17 : client: [1] closed
Apr 12 14:17 : client: [2] opened from 127.0.0.1:65194
Apr 12 14:17 : client: [2] expired
Apr 12 14:17 : client: [2] closed
Apr 12 14:17 : client: [3] opened from 127.0.0.1:65195
Apr 12 14:17 : client: [3] expired
Apr 12 14:17 : client: [3] closed
Apr 12 14:18 : client: [4] opened from 127.0.0.1:65196
Apr 12 14:18 : client: [4] expired
Apr 12 14:18 : client: [4] closed
Apr 12 14:18 : client: [5] opened from 127.0.0.1:65203
Apr 12 14:18 : client: [5] expired
Apr 12 14:18 : client: [5] closed
Apr 12 14:19 : client: [6] opened from 127.0.0.1:65204
Apr 12 14:19 : client: [6] process command "stats"
Apr 12 14:19 : client: [6] command returned 0
Apr 12 14:19 : client: [6] expired
Apr 12 14:19 : client: [6] closed
Apr 12 14:20 : client: [7] opened from 127.0.0.1:65220
Apr 12 14:20 : client: [7] process command "stats"
Apr 12 14:20 : client: [7] command returned 0
Apr 12 14:20 : client: [7] expired
Apr 12 14:20 : client: [7] closed
Apr 12 14:20 : client: [8] opened from 127.0.0.1:65221
Apr 12 14:20 : client: [8] process command "status"
Apr 12 14:20 : client: [8] command returned 0
Apr 12 14:20 : client: [8] expired
Apr 12 14:20 : client: [8] closed
Apr 12 14:23 : client: [9] opened from 127.0.0.1:65226
Apr 12 14:23 : client: [9] process command "stats"
Apr 12 14:23 : client: [9] command returned 0
Apr 12 14:23 : client: [9] expired
Apr 12 14:23 : client: [9] closed
Apr 12 14:23 : client: [10] opened from 127.0.0.1:65227
Apr 12 14:23 : client: [10] process command "stats"
Apr 12 14:23 : client: [10] command returned 0
Apr 12 14:23 : client: [10] expired
Apr 12 14:23 : client: [10] closed
Apr 12 14:23 : client: [11] opened from 127.0.0.1:65228
Apr 12 14:23 : client: [11] process command "stats"
Apr 12 14:23 : client: [11] command returned 0
Apr 12 14:23 : client: [11] expired
Apr 12 14:23 : client: [11] closed
Apr 12 14:23 : client: [12] opened from 127.0.0.1:65229
Apr 12 14:23 : client: [12] process command "status"
Apr 12 14:23 : client: [12] command returned 0
Apr 12 14:23 : client: [12] expired
Apr 12 14:23 : client: [12] closed
Apr 12 14:23 : client: [13] opened from 127.0.0.1:65230
Apr 12 14:23 : client: [13] process command "stats"
Apr 12 14:23 : client: [13] command returned 0
Apr 12 14:23 : client: [13] expired
Apr 12 14:23 : client: [13] closed
Apr 12 14:25 : client: [14] opened from 127.0.0.1:65236
Apr 12 14:25 : client: [14] process command "listplaylists"
Apr 12 14:25 : client: [14] command returned 0
Apr 12 14:25 : client: [14] expired
Apr 12 14:25 : client: [14] closed
Apr 12 14:28 : client: [15] opened from 127.0.0.1:65383
Apr 12 14:28 : client: [15] process command "listplaylists"
Apr 12 14:28 : client: [15] command returned 0
Apr 12 14:28 : client: [15] expired
Apr 12 14:28 : client: [15] closed
Apr 12 14:29 : client: [16] opened from 127.0.0.1:65385
Apr 12 14:29 : client: [16] process command "listplaylistinfo Playlist One"
Apr 12 14:29 : client: [16] command returned -1
Apr 12 14:29 : client: [16] expired
Apr 12 14:29 : client: [16] closed
Apr 12 14:29 : client: [17] opened from 127.0.0.1:65386
Apr 12 14:29 : client: [17] process command "listplaylistinfo "Playlist One""
Apr 12 14:29 : database: get song: teaspoon-stirring-mug-of-coffee.mp3
Apr 12 14:29 : database: get song: whistle-kettle-boiling.mp3
Apr 12 14:29 : database: get song: wine-glass-double-chink-clink-cheers.mp3
Apr 12 14:29 : database: get song: Directory With Spaces/coin-spin-light.mp3
Apr 12 14:29 : database: get song: Directory With Spaces/finger-snap-click.mp3
Apr 12 14:29 : client: [17] command returned 0
Apr 12 14:29 : client: [17] expired
Apr 12 14:29 : client: [17] closed
Apr 12 14:32 : client: [18] opened from 127.0.0.1:65446
Apr 12 14:32 : client: [18] process command "statstastats"
Apr 12 14:32 : client: [18] command returned -1
Apr 12 14:32 : client: [18] process command "stats"
Apr 12 14:3
8 changes: 7 additions & 1 deletion src/MpcNET.Test/TestOutput.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using System;
using MpcNET.Message;

namespace MpcNET.Test
{
internal class TestOutput
internal static class TestOutput
{
internal static void WriteLine(string value)
{
Console.Out.WriteLine(value);
}

internal static void WriteLine<T>(IMpdMessage<T> message)
{
Console.Out.WriteLine(message.ToString());
}
}
}
7 changes: 3 additions & 4 deletions src/MpcNET.Test/Tests/DatabaseCommandsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MpcNET.Tags;
using Newtonsoft.Json;

namespace MpcNET.Test
{
Expand All @@ -14,18 +13,18 @@ public async Task ListAllTest()
var response = await Mpc.SendAsync(new Commands.Database.ListAll());

TestOutput.WriteLine("ListAllTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
TestOutput.WriteLine(response);

Assert.IsTrue(response.Response.Body.Count().Equals(7));
}

[TestMethod]
public async Task FindGenreTest()
{
var response = await Test.LibMpcTest.Mpc.SendAsync(new Commands.Database.Find(MpdTags.Genre, "soundfx"));
var response = await Mpc.SendAsync(new Commands.Database.Find(MpdTags.Genre, "soundfx"));

TestOutput.WriteLine("FindGenreTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
TestOutput.WriteLine(response);

Assert.IsTrue(response.Response.Body.Count().Equals(7));
}
Expand Down
16 changes: 16 additions & 0 deletions src/MpcNET.Test/Tests/MpdMessageExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using MpcNET.Message;

namespace MpcNET.Test
{
public static class MpdMessageExtension
{
public static bool HasSuccessResponse<T>(this IMpdMessage<T> message)
{
return message.Response.State.Connected &&
message.Response.State.Status == "OK" &&
!message.Response.State.Error &&
message.Response.State.ErrorMessage == string.Empty &&
message.Response.State.MpdError == string.Empty;
}
}
}
9 changes: 4 additions & 5 deletions src/MpcNET.Test/Tests/OutputCommandsTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace MpcNET.Test
{
Expand All @@ -16,7 +15,7 @@ public async Task DisableOutputTest()
var response = await Mpc.SendAsync(new Commands.Output.DisableOutput(0));

TestOutput.WriteLine("DisableOutputTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
TestOutput.WriteLine(response);

Assert.IsTrue(response.Response.Body.Equals(string.Empty));
Assert.IsTrue(response.Response.State.Status.Equals("OK"));
Expand All @@ -35,7 +34,7 @@ public async Task EnableOutputTest()
var response = await Mpc.SendAsync(new Commands.Output.EnableOutput(1));

TestOutput.WriteLine("EnableOutputTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
TestOutput.WriteLine(response);

Assert.IsTrue(response.Response.Body.Equals(string.Empty));
Assert.IsTrue(response.Response.State.Status.Equals("OK"));
Expand All @@ -53,7 +52,7 @@ public async Task ToggleOutputTest()
var response = await Mpc.SendAsync(new Commands.Output.ToggleOutput(2));

TestOutput.WriteLine("ToggleOutputTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
TestOutput.WriteLine(response);

Assert.IsTrue(response.Response.Body.Equals(string.Empty));
Assert.IsTrue(response.Response.State.Status.Equals("OK"));
Expand All @@ -68,7 +67,7 @@ public async Task LisOutputsTest()
var response = await Mpc.SendAsync(new Commands.Output.Outputs());

TestOutput.WriteLine("LisOutputsTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
TestOutput.WriteLine(response);

Assert.IsTrue(response.Response.Body.Count().Equals(3));
}
Expand Down

0 comments on commit 6426d98

Please sign in to comment.