1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2024-09-16 05:30:09 +00:00
MpcNET/Sources/MpcNET.Test/Tests/PlaylistsCommandsTest.cs

176 lines
6.1 KiB
C#
Raw Normal View History

2018-05-18 13:14:20 +00:00
namespace MpcNET.Test
2017-04-12 09:21:29 +00:00
{
2018-05-18 13:14:20 +00:00
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MpcNET.Commands;
2021-10-03 15:53:58 +00:00
using MpcNET.Commands.Queue;
2018-05-18 13:14:20 +00:00
2017-04-12 09:21:29 +00:00
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)
{
2018-09-04 17:45:21 +00:00
var response = await Mpc.SendAsync(new Commands.Playlist.ListPlaylistCommand(playlistName));
2017-04-12 09:21:29 +00:00
TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:");
TestOutput.WriteLine(response);
2017-04-12 09:21:29 +00:00
2018-05-18 13:14:20 +00:00
Assert.IsTrue(response.Response.Content.Count().Equals(numberOfFiles));
2017-04-12 09:21:29 +00:00
}
[DataTestMethod]
[DataRow("Playlist One", 5)]
[DataRow("Playlist Two", 3)]
[DataRow("_My Playlist", 5)]
public async Task ListPlaylistInfoTest(string playlistName, int numberOfFiles)
{
2018-09-04 17:45:21 +00:00
var response = await Mpc.SendAsync(new Commands.Playlist.ListPlaylistInfoCommand(playlistName));
2017-04-12 09:21:29 +00:00
TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:");
TestOutput.WriteLine(response);
2017-04-12 09:21:29 +00:00
2018-05-18 13:14:20 +00:00
Assert.IsTrue(response.Response.Content.Count().Equals(numberOfFiles));
Assert.IsTrue(response.Response.Content.All(item => !string.IsNullOrEmpty(item.Artist)));
Assert.IsTrue(response.Response.Content.All(item => !string.IsNullOrEmpty(item.Title)));
Assert.IsTrue(response.Response.Content.All(item => !string.IsNullOrEmpty(item.Date)));
2017-04-12 09:21:29 +00:00
}
[TestMethod]
public async Task ListPlaylistsTest()
{
2018-09-04 17:45:21 +00:00
var response = await Mpc.SendAsync(new Commands.Playlist.ListPlaylistsCommand());
2017-04-12 09:21:29 +00:00
TestOutput.WriteLine($"ListPlaylistsTest Result:");
TestOutput.WriteLine(response);
2017-04-12 09:21:29 +00:00
2018-05-18 13:14:20 +00:00
Assert.IsTrue(response.Response.Content.Count().Equals(3));
2017-04-12 09:21:29 +00:00
}
/// <summary>
/// These tests must run sequential because we have only one "Current Queue"
/// </summary>
[TestMethod]
public async Task QueueTests()
{
2018-05-18 13:14:20 +00:00
await this.LoadPlaylistTest();
await this.ClearPlaylistTest();
await this.AddDirectoryTest();
await this.AddFileTest();
await this.RemovePositionTest();
await this.RemoveIdTest();
}
public async Task LoadPlaylistTest()
{
2018-05-18 13:14:20 +00:00
await this.Clear_Queue();
await this.Check_Empty_Queue();
await this.Load_Playlist("Playlist One");
await this.Check_Queue_HasSongs(5);
}
public async Task ClearPlaylistTest()
{
2018-05-18 13:14:20 +00:00
await this.Clear_Queue();
await this.Check_Empty_Queue();
await this.Load_Playlist("Playlist One");
await this.Clear_Queue();
await this.Check_Queue_HasSongs(0);
}
public async Task AddDirectoryTest()
{
2018-05-18 13:14:20 +00:00
await this.Clear_Queue();
await this.Check_Empty_Queue();
await this.Add_Directory("Directory With Spaces");
await this.Check_Queue_HasSongs(3);
}
public async Task AddFileTest()
{
2018-05-18 13:14:20 +00:00
await this.Clear_Queue();
await this.Check_Empty_Queue();
await this.Add_File("teaspoon-stirring-mug-of-coffee.mp3");
await this.Check_Queue_HasSongs(1);
}
public async Task RemovePositionTest()
{
2018-05-18 13:14:20 +00:00
await this.Clear_Queue();
await this.Check_Empty_Queue();
await this.Add_File("teaspoon-stirring-mug-of-coffee.mp3");
await this.Remove_Position(0);
await this.Check_Queue_HasSongs(0);
}
public async Task RemoveIdTest()
{
2018-05-18 13:14:20 +00:00
await this.Clear_Queue();
await this.Check_Empty_Queue();
await this.Add_File("teaspoon-stirring-mug-of-coffee.mp3");
var id = await this.Get_Song_Id();
await this.Remove_Id(id);
await this.Check_Queue_HasSongs(0);
}
private async Task Check_Empty_Queue()
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new PlaylistCommand());
Assert.IsTrue(message.HasSuccessResponse());
2018-05-18 13:14:20 +00:00
Assert.IsFalse(message.Response.Content.Any());
}
private async Task Load_Playlist(string playlistName)
{
2018-09-04 17:45:21 +00:00
var message = await Mpc.SendAsync(new Commands.Playlist.LoadCommand(playlistName));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Clear_Queue()
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new ClearCommand());
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Check_Queue_HasSongs(int nrOfSongs)
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new PlaylistCommand());
Assert.IsTrue(message.HasSuccessResponse());
2018-05-18 13:14:20 +00:00
Assert.IsTrue(message.Response.Content.Count() == nrOfSongs);
}
private async Task Add_Directory(string directory)
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new AddCommand(directory));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Add_File(string file)
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new AddIdCommand(file));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Remove_Position(int position)
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new DeleteCommand(position));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task Remove_Id(int songId)
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new DeleteIdCommand(songId));
Assert.IsTrue(message.HasSuccessResponse());
}
private async Task<int> Get_Song_Id()
{
2021-10-03 15:53:58 +00:00
var message = await Mpc.SendAsync(new PlaylistInfoCommand());
2018-05-18 13:14:20 +00:00
return message.Response.Content.Single().Id;
}
2017-04-12 09:21:29 +00:00
}
}