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

Test project fixed. xUnit replaced with MSTest.

This commit is contained in:
glucaci 2017-04-12 10:51:59 +02:00
parent eede2e53ee
commit 408e2ded46
7 changed files with 94 additions and 77 deletions

View File

@ -1,15 +1,29 @@
using LibMpc; using LibMpc;
using Xunit; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace LibMpcTest namespace LibMpcTest
{ {
public partial class LibMpcTest : IClassFixture<MpdMock>, IClassFixture<MpcMock> [TestClass]
public partial class LibMpcTest
{ {
public LibMpcTest(MpcMock mpc) private static MpdMock _mpdMock;
[ClassInitialize]
public static void Init(TestContext context)
{ {
Mpc = mpc.Client; _mpdMock = new MpdMock();
_mpdMock.Start();
Mpc = new MpcMock().Client;
} }
internal Mpc Mpc { get; } [ClassCleanup]
public static void Cleanup()
{
_mpdMock.Dispose();
}
internal static Mpc Mpc { get; private set; }
} }
} }

View File

@ -23,8 +23,12 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" /> <PackageReference Include="MSTest.TestAdapter" Version="1.1.14" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" /> <PackageReference Include="MSTest.TestFramework" Version="1.1.14" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -7,7 +7,7 @@ namespace LibMpcTest
{ {
public class MpdMock : IDisposable public class MpdMock : IDisposable
{ {
public MpdMock() public void Start()
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{ {
@ -44,7 +44,7 @@ namespace LibMpcTest
} }
} }
public Process Process { get; } public Process Process { get; private set; }
private Server GetServer() private Server GetServer()
{ {

View File

@ -1,14 +1,14 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Xunit;
using System.Linq; using System.Linq;
using LibMpc; using LibMpc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LibMpcTest namespace LibMpcTest
{ {
public partial class LibMpcTest public partial class LibMpcTest
{ {
[Fact] [TestMethod]
public async Task ListAllTest() public async Task ListAllTest()
{ {
var response = await Mpc.SendAsync(new Commands.Database.ListAll()); var response = await Mpc.SendAsync(new Commands.Database.ListAll());
@ -16,10 +16,10 @@ namespace LibMpcTest
TestOutput.WriteLine("ListAllTest Result:"); TestOutput.WriteLine("ListAllTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(7)); Assert.IsTrue(response.Response.Body.Count().Equals(7));
} }
[Fact] [TestMethod]
public async Task FindGenreTest() public async Task FindGenreTest()
{ {
var response = await Mpc.SendAsync(new Commands.Database.Find(MpdTags.Genre, "soundfx")); var response = await Mpc.SendAsync(new Commands.Database.Find(MpdTags.Genre, "soundfx"));
@ -27,7 +27,7 @@ namespace LibMpcTest
TestOutput.WriteLine("FindGenreTest Result:"); TestOutput.WriteLine("FindGenreTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(7)); Assert.IsTrue(response.Response.Body.Count().Equals(7));
} }
} }
} }

View File

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

View File

@ -1,18 +1,17 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Xunit;
using LibMpc; using LibMpc;
using System.Linq; using System.Linq;
using Xunit.Abstractions; using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LibMpcTest namespace LibMpcTest
{ {
public partial class LibMpcTest public partial class LibMpcTest
{ {
[Theory] [DataTestMethod]
[InlineData("Playlist One", 5)] [DataRow("Playlist One", 5)]
[InlineData("Playlist Two", 3)] [DataRow("Playlist Two", 3)]
[InlineData("_My Playlist", 5)] [DataRow("_My Playlist", 5)]
public async Task ListPlaylistTest(string playlistName, int numberOfFiles) public async Task ListPlaylistTest(string playlistName, int numberOfFiles)
{ {
var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylist(playlistName)); var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylist(playlistName));
@ -20,13 +19,13 @@ namespace LibMpcTest
TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:"); TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(numberOfFiles)); Assert.IsTrue(response.Response.Body.Count().Equals(numberOfFiles));
} }
[Theory] [DataTestMethod]
[InlineData("Playlist One", 5)] [DataRow("Playlist One", 5)]
[InlineData("Playlist Two", 3)] [DataRow("Playlist Two", 3)]
[InlineData("_My Playlist", 5)] [DataRow("_My Playlist", 5)]
public async Task ListPlaylistInfoTest(string playlistName, int numberOfFiles) public async Task ListPlaylistInfoTest(string playlistName, int numberOfFiles)
{ {
var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylistInfo(playlistName)); var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylistInfo(playlistName));
@ -34,13 +33,13 @@ namespace LibMpcTest
TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:"); TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(numberOfFiles)); Assert.IsTrue(response.Response.Body.Count().Equals(numberOfFiles));
Assert.True(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Artist))); Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Artist)));
Assert.True(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Title))); Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Title)));
Assert.True(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Date))); Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Date)));
} }
[Fact] [TestMethod]
public async Task ListPlaylistsTest() public async Task ListPlaylistsTest()
{ {
var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylists()); var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylists());
@ -48,7 +47,7 @@ namespace LibMpcTest
TestOutput.WriteLine($"ListPlaylistsTest Result:"); TestOutput.WriteLine($"ListPlaylistsTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(3)); Assert.IsTrue(response.Response.Body.Count().Equals(3));
} }
} }
} }

View File

@ -1,14 +1,14 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Xunit;
using LibMpc; using LibMpc;
using System.Linq; using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LibMpcTest namespace LibMpcTest
{ {
public partial class LibMpcTest public partial class LibMpcTest
{ {
[Fact] [TestMethod]
public async Task CommandsTest() public async Task CommandsTest()
{ {
var response = await Mpc.SendAsync(new Commands.Reflection.Commands()); var response = await Mpc.SendAsync(new Commands.Reflection.Commands());
@ -18,15 +18,15 @@ namespace LibMpcTest
// Different answer from MPD on Windows and on Linux, beacuse of Version. // Different answer from MPD on Windows and on Linux, beacuse of Version.
// Check some of the commands. // Check some of the commands.
Assert.True(response.Response.Body.Any(command => command.Equals("listall"))); Assert.IsTrue(response.Response.Body.Any(command => command.Equals("listall")));
Assert.True(response.Response.Body.Any(command => command.Equals("outputs"))); Assert.IsTrue(response.Response.Body.Any(command => command.Equals("outputs")));
Assert.True(response.Response.Body.Any(command => command.Equals("pause"))); Assert.IsTrue(response.Response.Body.Any(command => command.Equals("pause")));
Assert.True(response.Response.Body.Any(command => command.Equals("play"))); Assert.IsTrue(response.Response.Body.Any(command => command.Equals("play")));
Assert.True(response.Response.Body.Any(command => command.Equals("setvol"))); Assert.IsTrue(response.Response.Body.Any(command => command.Equals("setvol")));
Assert.True(response.Response.Body.Any(command => command.Equals("stop"))); Assert.IsTrue(response.Response.Body.Any(command => command.Equals("stop")));
} }
[Fact] [TestMethod]
public async Task TagTypesTest() public async Task TagTypesTest()
{ {
var response = await Mpc.SendAsync(new Commands.Reflection.TagTypes()); var response = await Mpc.SendAsync(new Commands.Reflection.TagTypes());
@ -34,10 +34,10 @@ namespace LibMpcTest
TestOutput.WriteLine("TagTypesTest Result:"); TestOutput.WriteLine("TagTypesTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(17)); Assert.IsTrue(response.Response.Body.Count().Equals(17));
} }
[Fact] [TestMethod]
public async Task UrlHandlersTest() public async Task UrlHandlersTest()
{ {
var response = await Mpc.SendAsync(new Commands.Reflection.UrlHandlers()); var response = await Mpc.SendAsync(new Commands.Reflection.UrlHandlers());
@ -47,13 +47,13 @@ namespace LibMpcTest
// Different answer from MPD on Windows and on Linux. // Different answer from MPD on Windows and on Linux.
// Check some of the handlers. // Check some of the handlers.
Assert.True(response.Response.Body.Any(handler => handler.Equals("http://"))); Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("http://")));
Assert.True(response.Response.Body.Any(handler => handler.Equals("mms://"))); Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("mms://")));
Assert.True(response.Response.Body.Any(handler => handler.Equals("gopher://"))); Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("gopher://")));
Assert.True(response.Response.Body.Any(handler => handler.Equals("rtp://"))); Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("rtp://")));
} }
[Fact] [TestMethod]
public async Task DecodersTest() public async Task DecodersTest()
{ {
var response = await Mpc.SendAsync(new Commands.Reflection.Decoders()); var response = await Mpc.SendAsync(new Commands.Reflection.Decoders());
@ -63,18 +63,18 @@ namespace LibMpcTest
// Different answer from MPD on Windows and on Linux. // Different answer from MPD on Windows and on Linux.
// Check some of the decoders. // Check some of the decoders.
Assert.True(response.Response.Body.Any(decoder => decoder.Name.Equals("mad"))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("mad")));
Assert.True(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("mp3")))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("mp3"))));
Assert.True(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/mpeg")))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/mpeg"))));
Assert.True(response.Response.Body.Any(decoder => decoder.Name.Equals("flac"))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("flac")));
Assert.True(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("flac")))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("flac"))));
Assert.True(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/flac"))));
Assert.True(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/x-flac")))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/x-flac"))));
Assert.True(response.Response.Body.Any(decoder => decoder.Name.Equals("ffmpeg"))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("ffmpeg")));
Assert.True(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("aac"))));
Assert.True(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("mpeg")))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("mpeg"))));
Assert.True(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/aac"))));
Assert.True(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/mpeg")))); Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/mpeg"))));
} }
} }
} }