1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-01-14 22:18:43 +00:00

Output commands completed + test

This commit is contained in:
glucaci 2016-12-20 11:03:28 +01:00
parent 9885ffa87b
commit e2ebbe7e14
8 changed files with 71 additions and 31 deletions

View File

@ -52,7 +52,26 @@ namespace LibMpc
} }
} }
// TODO: toggleoutput // Turns an output on or off, depending on the current state. /// <summary>
/// Turns an output on or off, depending on the current state.
/// </summary>
public class ToggleOutput : IMpcCommand<string>
{
private readonly int _outputId;
public ToggleOutput(int outputId)
{
_outputId = outputId;
}
public string Value => string.Join(" ", "toggleoutput", _outputId);
public string FormatResponse(IList<KeyValuePair<string, string>> response)
{
// Response should be empty.
return string.Join(", ", response);
}
}
/// <summary> /// <summary>
/// Shows information about all outputs. /// Shows information about all outputs.

View File

@ -1,5 +1,4 @@
using LibMpc; using LibMpc;
using System.Diagnostics;
using Xunit; using Xunit;
namespace LibMpcTest namespace LibMpcTest
@ -13,12 +12,4 @@ namespace LibMpcTest
internal Mpc Mpc { get; } internal Mpc Mpc { get; }
} }
internal class TestUtils
{
internal static void WriteLine(string value)
{
Debug.WriteLine(value);
}
}
} }

View File

@ -12,7 +12,7 @@ namespace LibMpcTest
Client = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600)); Client = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600));
var connected = Task.Run(async () => await Client.ConnectAsync()).Result; var connected = Task.Run(async () => await Client.ConnectAsync()).Result;
TestUtils.WriteLine($"Connected to MPD : {connected}"); TestOutput.WriteLine($"Connected to MPD : {connected}");
} }
public Mpc Client { get; } public Mpc Client { get; }
@ -20,7 +20,7 @@ namespace LibMpcTest
public void Dispose() public void Dispose()
{ {
Client?.DisconnectAsync().GetAwaiter().GetResult(); Client?.DisconnectAsync().GetAwaiter().GetResult();
TestUtils.WriteLine($"Disconnected from MPD."); TestOutput.WriteLine($"Disconnected from MPD.");
} }
} }
} }

View File

@ -32,11 +32,11 @@ namespace LibMpcTest
} }
}; };
TestUtils.WriteLine($"Starting Server: {Process.StartInfo.FileName} {Process.StartInfo.Arguments}"); TestOutput.WriteLine($"Starting Server: {Process.StartInfo.FileName} {Process.StartInfo.Arguments}");
Process.Start(); Process.Start();
TestUtils.WriteLine($"Output: {Process.StandardOutput.ReadToEnd()}"); TestOutput.WriteLine($"Output: {Process.StandardOutput.ReadToEnd()}");
TestUtils.WriteLine($"Error: {Process.StandardError.ReadToEnd()}"); TestOutput.WriteLine($"Error: {Process.StandardError.ReadToEnd()}");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{ {
@ -80,16 +80,16 @@ namespace LibMpcTest
netcat.Start(); netcat.Start();
netcat.WaitForExit(); netcat.WaitForExit();
TestUtils.WriteLine(command); TestOutput.WriteLine(command);
TestUtils.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}"); TestOutput.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}");
TestUtils.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}"); TestOutput.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}");
} }
public void Dispose() public void Dispose()
{ {
Process?.Kill(); Process?.Kill();
Process?.Dispose(); Process?.Dispose();
TestUtils.WriteLine("Server Stopped."); TestOutput.WriteLine("Server Stopped.");
} }
private class Server private class Server

12
LibMpcTest/TestOutput.cs Normal file
View File

@ -0,0 +1,12 @@
using System;
namespace LibMpcTest
{
internal class TestOutput
{
internal static void WriteLine(string value)
{
Console.Out.WriteLine(value);
}
}
}

View File

@ -13,8 +13,8 @@ namespace LibMpcTest
{ {
var response = await Mpc.SendAsync(new Commands.Database.ListAll()); var response = await Mpc.SendAsync(new Commands.Database.ListAll());
TestUtils.WriteLine("ListAllTest Result:"); TestOutput.WriteLine("ListAllTest Result:");
TestUtils.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(7)); Assert.True(response.Response.Body.Count().Equals(7));
} }
@ -24,8 +24,8 @@ namespace LibMpcTest
{ {
var response = await Mpc.SendAsync(new Commands.Database.Find(MpdTags.Genre, "soundfx")); var response = await Mpc.SendAsync(new Commands.Database.Find(MpdTags.Genre, "soundfx"));
TestUtils.WriteLine("FindGenreTest Result:"); TestOutput.WriteLine("FindGenreTest Result:");
TestUtils.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(6)); Assert.True(response.Response.Body.Count().Equals(6));
} }

View File

@ -16,8 +16,8 @@ namespace LibMpcTest
var response = await Mpc.SendAsync(new Commands.Output.DisableOutput(2)); var response = await Mpc.SendAsync(new Commands.Output.DisableOutput(2));
TestUtils.WriteLine("DisableOutputTest Result:"); TestOutput.WriteLine("DisableOutputTest Result:");
TestUtils.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Equals(string.Empty)); Assert.True(response.Response.Body.Equals(string.Empty));
Assert.True(response.Response.State.Status.Equals("OK")); Assert.True(response.Response.State.Status.Equals("OK"));
@ -35,8 +35,8 @@ namespace LibMpcTest
var response = await Mpc.SendAsync(new Commands.Output.EnableOutput(1)); var response = await Mpc.SendAsync(new Commands.Output.EnableOutput(1));
TestUtils.WriteLine("EnableOutputTest Result:"); TestOutput.WriteLine("EnableOutputTest Result:");
TestUtils.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Equals(string.Empty)); Assert.True(response.Response.Body.Equals(string.Empty));
Assert.True(response.Response.State.Status.Equals("OK")); Assert.True(response.Response.State.Status.Equals("OK"));
@ -45,13 +45,31 @@ namespace LibMpcTest
Assert.True(responseOutputs.Response.Body.Single(output => output.Id.Equals(1)).IsEnabled); Assert.True(responseOutputs.Response.Body.Single(output => output.Id.Equals(1)).IsEnabled);
} }
[Fact]
public async Task ToggleOutputTest()
{
var responseOutputs = await Mpc.SendAsync(new Commands.Output.Outputs());
Assert.True(responseOutputs.Response.Body.Single(output => output.Id.Equals(2)).IsEnabled);
var response = await Mpc.SendAsync(new Commands.Output.ToggleOutput(2));
TestOutput.WriteLine("ToggleOutputTest Result:");
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Equals(string.Empty));
Assert.True(response.Response.State.Status.Equals("OK"));
responseOutputs = await Mpc.SendAsync(new Commands.Output.Outputs());
Assert.False(responseOutputs.Response.Body.Single(output => output.Id.Equals(2)).IsEnabled);
}
[Fact] [Fact]
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());
TestUtils.WriteLine("LisOutputsTest Result:"); TestOutput.WriteLine("LisOutputsTest Result:");
TestUtils.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(3)); Assert.True(response.Response.Body.Count().Equals(3));
} }

View File

@ -13,8 +13,8 @@ namespace LibMpcTest
{ {
var response = await Mpc.SendAsync(new Commands.Reflection.TagTypes()); var response = await Mpc.SendAsync(new Commands.Reflection.TagTypes());
TestUtils.WriteLine("TagTypesTest Result:"); TestOutput.WriteLine("TagTypesTest Result:");
TestUtils.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Count().Equals(17)); Assert.True(response.Response.Body.Count().Equals(17));
} }