diff --git a/LibMpcTest/LibMpcTest.cs b/LibMpcTest/LibMpcTest.cs index ce807e8..868a680 100644 --- a/LibMpcTest/LibMpcTest.cs +++ b/LibMpcTest/LibMpcTest.cs @@ -25,12 +25,10 @@ namespace LibMpcTest var connected = Task.Run(async () => await _mpc.ConnectAsync()).Result; if (connected) { - Console.Out.WriteLine(); Console.Out.WriteLine("Connected to MPD."); } else { - Console.Out.WriteLine(); Console.Out.WriteLine("Could not connect to MPD."); } } @@ -40,7 +38,7 @@ namespace LibMpcTest { var response = await _mpc.SendAsync(new Commands.Reflection.TagTypes()); - Console.Out.WriteLine(); + Console.Out.WriteLine("TagTypesTest Result:"); Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); Assert.True(response.Response.Body.Keys.Contains("tagtypes")); @@ -52,7 +50,7 @@ namespace LibMpcTest { var response = await _mpc.SendAsync(new Commands.Database.ListAll()); - Console.Out.WriteLine(); + Console.Out.WriteLine("ListAllTest Result:"); Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); // TODO: Assert diff --git a/LibMpcTest/MpdServerTest.cs b/LibMpcTest/MpdServerTest.cs index 76e3684..d3f9b2d 100644 --- a/LibMpcTest/MpdServerTest.cs +++ b/LibMpcTest/MpdServerTest.cs @@ -9,6 +9,11 @@ namespace LibMpcTest { public MpdServerTest() { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + SendCommand("/usr/bin/pkill mpd"); + } + MpdConf.Create(Path.Combine(AppContext.BaseDirectory, "Server")); var server = GetServer(); @@ -27,44 +32,19 @@ namespace LibMpcTest } }; - Console.Out.WriteLine(); Console.Out.WriteLine($"Starting Server: {Process.StartInfo.FileName} {Process.StartInfo.Arguments}"); Process.Start(); - Console.Out.WriteLine($"Output: {Process.StandardOutput.ReadToEnd()}"); Console.Out.WriteLine($"Error: {Process.StandardError.ReadToEnd()}"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - CheckIfServerIsRunning(); + SendCommand("/bin/netstat -ntpl"); } } - private void CheckIfServerIsRunning() - { - var netcat = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = "/bin/bash", - WorkingDirectory = "/bin/", - Arguments = "-c \"sudo /bin/netstat -ntpl\"", - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true, - } - }; - - netcat.Start(); - netcat.WaitForExit(); - - Console.Out.WriteLine(); - Console.Out.WriteLine("netstat -ntpl"); - Console.Out.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}"); - Console.Out.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}"); - } + public Process Process { get; } private Server GetServer() { @@ -81,9 +61,29 @@ namespace LibMpcTest throw new NotSupportedException("OS not supported"); } - public Process Process { get; } - public string LogError { get; } - public string LogOutput { get; } + 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(); + + Console.Out.WriteLine(command); + Console.Out.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}"); + Console.Out.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}"); + } public void Dispose() {