1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-07-18 05:27:37 +00:00

Rewrote most of the library

This commit is contained in:
Kim Hugener-Ohlsen
2018-03-02 12:14:26 +01:00
parent a2c012dd7e
commit 245efd6477
181 changed files with 3927 additions and 3020 deletions

View File

@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MpcNET.Test
{
[TestClass]
public partial class LibMpcTest
{
private static MpdMock _mpdMock;
[ClassInitialize]
public static void Init(TestContext context)
{
_mpdMock = new MpdMock();
_mpdMock.Start();
Mpc = new MpcMock().Client;
}
[ClassCleanup]
public static void Cleanup()
{
_mpdMock.Dispose();
}
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;
}
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Net;
using System.Threading.Tasks;
namespace MpcNET.Test
{
public class MpcMock : IDisposable
{
public MpcMock()
{
var mpdEndpoint = new IPEndPoint(IPAddress.Loopback, 6600);
Client = new Mpc(mpdEndpoint);
var connected = Task.Run(async () => await Client.ConnectAsync()).Result;
TestOutput.WriteLine($"Connected to MPD : {connected}; Version: {Client.Version}");
}
public Mpc Client { get; }
public void Dispose()
{
Client?.DisconnectAsync().GetAwaiter().GetResult();
TestOutput.WriteLine($"Disconnected from MPD.");
}
}
}

View File

@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>MpcNET.Test</AssemblyName>
<PackageId>MpcNET.Test</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace>MpcNET.Test</RootNamespace>
<SignAssembly>False</SignAssembly>
<DelaySign>True</DelaySign>
</PropertyGroup>
<ItemGroup>
<None Remove="MpcNET.Test.csproj.DotSettings" />
</ItemGroup>
<ItemGroup>
<None Update="Server\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MpcNET\MpcNET.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,57 @@
using System.IO;
using System.Text;
namespace MpcNET.Test
{
public class MpdConf
{
private const string MPD_CONF_FILE = "mpd.conf";
private const string MPD_LOG_FILE = "mpd_log.txt";
private const string MPD_DB_FILE = "mpd.db";
public static void Create(string rootDirectory)
{
File.Create(Path.Combine(rootDirectory, MPD_LOG_FILE)).Dispose();
CreateConfFile(rootDirectory);
}
private static void CreateConfFile(string rootDirectory)
{
var builder = new StringBuilder();
builder.AppendLine($"log_file \"{Path.Combine(rootDirectory, MPD_LOG_FILE).Replace("\\", "\\\\")}\"");
builder.AppendLine($"db_file \"{Path.Combine(rootDirectory, MPD_DB_FILE).Replace("\\", "\\\\")}\"");
builder.AppendLine("bind_to_address \"any\"");
builder.AppendLine($"music_directory \"{Path.Combine(rootDirectory, "Music").Replace("\\", "\\\\")}\"");
builder.AppendLine($"playlist_directory \"{Path.Combine(rootDirectory, "Playlists").Replace("\\", "\\\\")}\"");
builder.AppendLine("port \"6600\"");
builder.AppendLine("audio_output {");
builder.AppendLine("type \"null\"");
builder.AppendLine("name \"Enabled output to be disabled\"");
builder.AppendLine("enabled \"true\"");
builder.AppendLine("mixer_type \"none\"");
builder.AppendLine("}");
builder.AppendLine("audio_output {");
builder.AppendLine("type \"null\"");
builder.AppendLine("name \"Disabled output to be enabled\"");
builder.AppendLine("enabled \"false\"");
builder.AppendLine("mixer_type \"none\"");
builder.AppendLine("}");
builder.AppendLine("audio_output {");
builder.AppendLine("type \"null\"");
builder.AppendLine("name \"Enabled output to be toggled\"");
builder.AppendLine("enabled \"true\"");
builder.AppendLine("mixer_type \"none\"");
builder.AppendLine("}");
var mpdConfContent = builder.ToString();
using (var file = File.CreateText(Path.Combine(rootDirectory, MPD_CONF_FILE)))
{
file.Write(mpdConfContent);
file.Flush();
}
}
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace MpcNET.Test
{
public class MpdMock : IDisposable
{
public void Start()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
SendCommand("/usr/bin/pkill mpd");
}
MpdConf.Create(Path.Combine(AppContext.BaseDirectory, "Server"));
var server = GetServer();
Process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = server.FileName,
WorkingDirectory = server.WorkingDirectory,
Arguments = server.Arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
}
};
TestOutput.WriteLine($"Starting Server: {Process.StartInfo.FileName} {Process.StartInfo.Arguments}");
Process.Start();
TestOutput.WriteLine($"Output: {Process.StandardOutput.ReadToEnd()}");
TestOutput.WriteLine($"Error: {Process.StandardError.ReadToEnd()}");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
SendCommand("/bin/netstat -ntpl");
}
}
public Process Process { get; private set; }
private Server GetServer()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return Server.Linux;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Server.Windows;
}
throw new NotSupportedException("OS not supported");
}
private void SendCommand(string command)
{
var netcat = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
WorkingDirectory = "/bin/",
Arguments = $"-c \"sudo {command}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
}
};
netcat.Start();
netcat.WaitForExit();
TestOutput.WriteLine(command);
TestOutput.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}");
TestOutput.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}");
}
public void Dispose()
{
Process?.Kill();
Process?.Dispose();
TestOutput.WriteLine("Server Stopped.");
}
private class Server
{
public static Server Linux = new Server(
fileName: "/bin/bash",
workingDirectory: "/bin/",
arguments: $"-c \"sudo /usr/bin/mpd {Path.Combine(AppContext.BaseDirectory, "Server", "mpd.conf")} -v\"");
public static Server Windows = new Server(
fileName: Path.Combine(AppContext.BaseDirectory, "Server", "mpd.exe"),
workingDirectory: Path.Combine(AppContext.BaseDirectory, "Server"),
arguments: $"{Path.Combine(AppContext.BaseDirectory, "Server", "mpd.conf")} -v");
private Server(string fileName, string workingDirectory, string arguments)
{
FileName = fileName;
WorkingDirectory = workingDirectory;
Arguments = arguments;
}
public string FileName { get; }
public string WorkingDirectory { get; }
public string Arguments { get; }
}
}
}

View File

@ -0,0 +1,18 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LibMpcTest")]
[assembly: AssemblyTrademark("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("69f1d68f-9cd5-4ea6-9b47-2a7a9bf8ced9")]

Binary file not shown.

View File

@ -0,0 +1,5 @@
teaspoon-stirring-mug-of-coffee.mp3
whistle-kettle-boiling.mp3
wine-glass-double-chink-clink-cheers.mp3
Directory With Spaces/coin-spin-light.mp3
Directory With Spaces/finger-snap-click.mp3

View File

@ -0,0 +1,3 @@
A long name directory with some spaces/pouring-water-into-mug-of-coffee.mp3
A long name directory with some spaces/Sub Directory Two/short-trouser-pants-zip-closing.mp3
Directory/2-Kids-Laughing.mp3

View File

@ -0,0 +1,5 @@
A long name directory with some spaces/Ghost-Sounds.mp3
Directory/ambient-noise-server-room.mp3
Directory With Spaces/SubDirectory One/central-locking-Ford-Mondeo-Mk-3.mp3
_My Directory/gas-fire-lighting.mp3
A long name directory with some spaces/Sub Directory Two/starting-engine-Ford-Mondeo-Mk-3-diesel.mp3

View File

@ -0,0 +1 @@
mpd.exe mpd.conf -v

View File

@ -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"
}

View File

@ -0,0 +1,163 @@
info_begin
format: 1
mpd_version: 0.17.4
fs_charset: cp1252
tag: Artist
tag: ArtistSort
tag: Album
tag: AlbumArtist
tag: AlbumArtistSort
tag: Title
tag: Track
tag: Name
tag: Genre
tag: Date
tag: Composer
tag: Performer
tag: Disc
tag: MUSICBRAINZ_ARTISTID
tag: MUSICBRAINZ_ALBUMID
tag: MUSICBRAINZ_ALBUMARTISTID
tag: MUSICBRAINZ_TRACKID
info_end
directory: A long name directory with some spaces
mtime: 1482142041
begin: A long name directory with some spaces
directory: Sub Directory Two
mtime: 1482142041
begin: A long name directory with some spaces/Sub Directory Two
song_begin: short-trouser-pants-zip-closing.mp3
Time: 1
Artist: Geek & Dummy
Title: Sound effect: short trouser pants zip closing
Date: 2013
Date: 2013
mtime: 1481623577
song_end
song_begin: starting-engine-Ford-Mondeo-Mk-3-diesel.mp3
Time: 6
Artist: Geek & Dummy
Title: Sound effect: starting engine - Ford Mondeo Mk 3 diesel
Album: Geek & Dummy Sound Library
Date: 2014
Genre: soundfx
mtime: 1481623577
song_end
end: A long name directory with some spaces/Sub Directory Two
song_begin: pouring-water-into-mug-of-coffee.mp3
Time: 4
Artist: Geek & Dummy
Title: Sound effect: pouring water into mug of coffee
Date: 2013
Date: 2013
mtime: 1481623577
song_end
song_begin: Ghost-Sounds.mp3
Time: 95
Artist: Geek & Dummy
Title: Sound effect: ghostly haunted house (bells, ghostly laughs & knives sharpened)
Album: Geek & Dummy Sound Library
Date: 2014
Date: 2014
Genre: soundfx
mtime: 1481623577
song_end
end: A long name directory with some spaces
directory: Directory
mtime: 1482142041
begin: Directory
song_begin: 2-Kids-Laughing.mp3
Time: 30
Artist: Geek & Dummy
Title: Sound effect: two kids laughing
Album: Geek & Dummy Sound Library
Date: 2014
Date: 2014
Genre: soundfx
mtime: 1481623577
song_end
song_begin: ambient-noise-server-room.mp3
Time: 71
Artist: Geek & Dummy
Title: Sound effect: ambient noise - server room
Album: Geek & Dummy Sound Library
Date: 2014
Date: 2014
Genre: soundfx
mtime: 1481623577
song_end
end: Directory
directory: Directory With Spaces
mtime: 1482142041
begin: Directory With Spaces
directory: SubDirectory One
mtime: 1482142041
begin: Directory With Spaces/SubDirectory One
song_begin: central-locking-Ford-Mondeo-Mk-3.mp3
Time: 5
Artist: Geek & Dummy
Title: Sound effect: central locking - Ford Mondeo Mk 3
Album: Geek & Dummy Sound Library
Date: 2014
Date: 2014
Genre: soundfx
mtime: 1481623577
song_end
end: Directory With Spaces/SubDirectory One
song_begin: coin-spin-light.mp3
Time: 5
Artist: Geek & Dummy
Title: Sound effect: coin spin (light coin)
Date: 2013
Date: 2013
mtime: 1481623577
song_end
song_begin: finger-snap-click.mp3
Time: 0
Artist: Geek & Dummy
Title: Sound effect: finger snap/click
Album: Geek & Dummy Sound Library
Date: 2014
Date: 2014
Genre: soundfx
mtime: 1481623577
song_end
end: Directory With Spaces
directory: _My Directory
mtime: 1482142041
begin: _My Directory
song_begin: gas-fire-lighting.mp3
Time: 58
Artist: Geek & Dummy
Title: Sound effect: gas fire lighting and warming up
Album: Geek & Dummy Sound Library
Date: 2014
Date: 2014
Genre: soundfx
mtime: 1481623577
song_end
end: _My Directory
song_begin: teaspoon-stirring-mug-of-coffee.mp3
Time: 4
Artist: Geek & Dummy
Title: Sound effect: teaspoon stirring mug of coffee
Date: 2013
Date: 2013
mtime: 1481623577
song_end
song_begin: whistle-kettle-boiling.mp3
Time: 36
Artist: Geek & Dummy
Title: Sound effect: whistle kettle boiling
Date: 2013
Date: 2013
mtime: 1481623577
song_end
song_begin: wine-glass-double-chink-clink-cheers.mp3
Time: 1
Artist: Geek & Dummy
Title: Sound effect: wine glass double chink/clink/cheers
Date: 2013
Date: 2013
mtime: 1481623577
song_end

Binary file not shown.

View File

@ -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

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,18 @@
using System;
using MpcNET.Message;
namespace MpcNET.Test
{
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());
}
}
}

View File

@ -0,0 +1,33 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MpcNET.Commands;
using MpcNET.Tags;
namespace MpcNET.Test
{
public partial class LibMpcTest
{
[TestMethod]
public async Task ListAllTest()
{
var response = await Mpc.SendAsync(Command.Database.ListAll());
TestOutput.WriteLine("ListAllTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Count().Equals(7));
}
[TestMethod]
public async Task FindGenreTest()
{
var response = await Mpc.SendAsync(Command.Database.Find(MpdTags.Genre, "soundfx"));
TestOutput.WriteLine("FindGenreTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Count().Equals(7));
}
}
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,76 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MpcNET.Commands;
namespace MpcNET.Test
{
public partial class LibMpcTest
{
[TestMethod]
public async Task DisableOutputTest()
{
var responseOutputs = await Mpc.SendAsync(Command.Output.Outputs());
Assert.IsTrue(responseOutputs.Response.Body.Single(output => output.Id.Equals(0)).IsEnabled);
var response = await Mpc.SendAsync(Command.Output.DisableOutput(0));
TestOutput.WriteLine("DisableOutputTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Equals(string.Empty));
Assert.IsTrue(response.Response.State.Status.Equals("OK"));
responseOutputs = await Mpc.SendAsync(Command.Output.Outputs());
Assert.IsFalse(responseOutputs.Response.Body.Single(output => output.Id.Equals(0)).IsEnabled);
}
[TestMethod]
public async Task EnableOutputTest()
{
var responseOutputs = await Mpc.SendAsync(Command.Output.Outputs());
// By default should be disable from mpd.config
Assert.IsFalse(responseOutputs.Response.Body.Single(output => output.Id.Equals(1)).IsEnabled);
var response = await Mpc.SendAsync(Command.Output.EnableOutput(1));
TestOutput.WriteLine("EnableOutputTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Equals(string.Empty));
Assert.IsTrue(response.Response.State.Status.Equals("OK"));
responseOutputs = await Mpc.SendAsync(Command.Output.Outputs());
Assert.IsTrue(responseOutputs.Response.Body.Single(output => output.Id.Equals(1)).IsEnabled);
}
[TestMethod]
public async Task ToggleOutputTest()
{
var responseOutputs = await Mpc.SendAsync(Command.Output.Outputs());
Assert.IsTrue(responseOutputs.Response.Body.Single(output => output.Id.Equals(2)).IsEnabled);
var response = await Mpc.SendAsync(Command.Output.ToggleOutput(2));
TestOutput.WriteLine("ToggleOutputTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Equals(string.Empty));
Assert.IsTrue(response.Response.State.Status.Equals("OK"));
responseOutputs = await Mpc.SendAsync(Command.Output.Outputs());
Assert.IsFalse(responseOutputs.Response.Body.Single(output => output.Id.Equals(2)).IsEnabled);
}
[TestMethod]
public async Task LisOutputsTest()
{
var response = await Mpc.SendAsync(Command.Output.Outputs());
TestOutput.WriteLine("LisOutputsTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Count().Equals(3));
}
}
}

View File

@ -0,0 +1,174 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MpcNET.Commands;
namespace MpcNET.Test
{
public partial class LibMpcTest
{
[DataTestMethod]
[DataRow("Playlist One", 5)]
[DataRow("Playlist Two", 3)]
[DataRow("_My Playlist", 5)]
public async Task ListPlaylistTest(string playlistName, int numberOfFiles)
{
var response = await Mpc.SendAsync(Command.Playlists.Stored.GetContent(playlistName));
TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Count().Equals(numberOfFiles));
}
[DataTestMethod]
[DataRow("Playlist One", 5)]
[DataRow("Playlist Two", 3)]
[DataRow("_My Playlist", 5)]
public async Task ListPlaylistInfoTest(string playlistName, int numberOfFiles)
{
var response = await Mpc.SendAsync(Command.Playlists.Stored.GetContentWithMetadata(playlistName));
TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Count().Equals(numberOfFiles));
Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Artist)));
Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Title)));
Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Date)));
}
[TestMethod]
public async Task ListPlaylistsTest()
{
var response = await Mpc.SendAsync(Command.Playlists.Stored.GetAll());
TestOutput.WriteLine($"ListPlaylistsTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Count().Equals(3));
}
/// <summary>
/// These tests must run sequential because we have only one "Current Queue"
/// </summary>
[TestMethod]
public async Task QueueTests()
{
await LoadPlaylistTest();
await ClearPlaylistTest();
await AddDirectoryTest();
await AddFileTest();
await RemovePositionTest();
await RemoveIdTest();
}
public async Task LoadPlaylistTest()
{
await Clear_Queue();
await Check_Empty_Queue();
await Load_Playlist("Playlist One");
await Check_Queue_HasSongs(5);
}
public async Task ClearPlaylistTest()
{
await Clear_Queue();
await Check_Empty_Queue();
await Load_Playlist("Playlist One");
await Clear_Queue();
await Check_Queue_HasSongs(0);
}
public async Task AddDirectoryTest()
{
await Clear_Queue();
await Check_Empty_Queue();
await Add_Directory("Directory With Spaces");
await Check_Queue_HasSongs(3);
}
public async Task AddFileTest()
{
await Clear_Queue();
await Check_Empty_Queue();
await Add_File("teaspoon-stirring-mug-of-coffee.mp3");
await Check_Queue_HasSongs(1);
}
public async Task RemovePositionTest()
{
await Clear_Queue();
await Check_Empty_Queue();
await Add_File("teaspoon-stirring-mug-of-coffee.mp3");
await Remove_Position(0);
await Check_Queue_HasSongs(0);
}
public async Task RemoveIdTest()
{
await Clear_Queue();
await Check_Empty_Queue();
await Add_File("teaspoon-stirring-mug-of-coffee.mp3");
var id = await Get_Song_Id();
await Remove_Id(id);
await Check_Queue_HasSongs(0);
}
private async Task Check_Empty_Queue()
{
var message = await Mpc.SendAsync(Command.Playlists.Current.GetAllSongsInfo());
Assert.IsTrue(message.HasSuccessResponse());
Assert.IsFalse(message.Response.Body.Any());
}
private async Task Load_Playlist(string playlistName)
{
var message = await Mpc.SendAsync(Command.Playlists.Stored.Load(playlistName));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Clear_Queue()
{
var message = await Mpc.SendAsync(Command.Playlists.Current.Clear());
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Check_Queue_HasSongs(int nrOfSongs)
{
var message = await Mpc.SendAsync(Command.Playlists.Current.GetAllSongsInfo());
Assert.IsTrue(message.HasSuccessResponse());
Assert.IsTrue(message.Response.Body.Count() == nrOfSongs);
}
private async Task Add_Directory(string directory)
{
var message = await Mpc.SendAsync(Command.Playlists.Current.AddDirectory(directory));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Add_File(string file)
{
var message = await Mpc.SendAsync(Command.Playlists.Current.AddSong(file));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Remove_Position(int position)
{
var message = await Mpc.SendAsync(Command.Playlists.Current.RemoveSongByPosition(position));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Remove_Id(int songId)
{
var message = await Mpc.SendAsync(Command.Playlists.Current.RemoveSongById(songId));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task<int> Get_Song_Id()
{
var message = await Mpc.SendAsync(Command.Playlists.Current.GetAllSongMetadata());
return message.Response.Body.Single().Id;
}
}
}

View File

@ -0,0 +1,79 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MpcNET.Commands;
namespace MpcNET.Test
{
public partial class LibMpcTest
{
[TestMethod]
public async Task CommandsTest()
{
var response = await Mpc.SendAsync(Command.Reflection.Commands());
TestOutput.WriteLine($"CommandsTest (commands: {response.Response.Body.Count()}) Result:");
TestOutput.WriteLine(response);
// Different answer from MPD on Windows and on Linux, beacuse of Version.
// Check some of the commands.
Assert.IsTrue(response.Response.Body.Any(command => command.Equals("listall")));
Assert.IsTrue(response.Response.Body.Any(command => command.Equals("outputs")));
Assert.IsTrue(response.Response.Body.Any(command => command.Equals("pause")));
Assert.IsTrue(response.Response.Body.Any(command => command.Equals("play")));
Assert.IsTrue(response.Response.Body.Any(command => command.Equals("setvol")));
Assert.IsTrue(response.Response.Body.Any(command => command.Equals("stop")));
}
[TestMethod]
public async Task TagTypesTest()
{
var response = await Mpc.SendAsync(Command.Reflection.TagTypes());
TestOutput.WriteLine("TagTypesTest Result:");
TestOutput.WriteLine(response);
Assert.IsTrue(response.Response.Body.Count().Equals(17));
}
[TestMethod]
public async Task UrlHandlersTest()
{
var response = await Mpc.SendAsync(Command.Reflection.UrlHandlers());
TestOutput.WriteLine($"UrlHandlersTest (handlers: {response.Response.Body.Count()}) Result:");
TestOutput.WriteLine(response);
// Different answer from MPD on Windows and on Linux.
// Check some of the handlers.
Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("http://")));
Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("mms://")));
Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("gopher://")));
Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("rtp://")));
}
[TestMethod]
public async Task DecodersTest()
{
var response = await Mpc.SendAsync(Command.Reflection.Decoders());
TestOutput.WriteLine($"DecodersTest (decoders: {response.Response.Body.Count()}) Result:");
TestOutput.WriteLine(response);
// Different answer from MPD on Windows and on Linux.
// Check some of the decoders.
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("mad")));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("mp3"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/mpeg"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("flac")));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("flac"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/flac"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/x-flac"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("ffmpeg")));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("aac"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("mpeg"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/aac"))));
Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/mpeg"))));
}
}
}