1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-07-01 08:47:36 +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,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"))));
}
}
}