From 3594e508e493a1f2cb1243a02b32a5ba0e07cbe9 Mon Sep 17 00:00:00 2001 From: glucaci Date: Wed, 14 Dec 2016 10:56:00 +0100 Subject: [PATCH] Test server for linux --- .travis.yml | 3 +++ LibMpcTest/MpdServerTest.cs | 53 +++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 115d2b9..bd496ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ dist: trusty sudo: required mono: none dotnet: 1.0.0-preview2-003131 +befor_install: + - sudo apt-get update -qq + - sudo apt-get install -y mpd script: - dotnet restore - dotnet build **/project.json diff --git a/LibMpcTest/MpdServerTest.cs b/LibMpcTest/MpdServerTest.cs index 97543bb..8944776 100644 --- a/LibMpcTest/MpdServerTest.cs +++ b/LibMpcTest/MpdServerTest.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; namespace LibMpcTest { @@ -8,20 +9,17 @@ namespace LibMpcTest { public MpdServerTest() { - var serverPath = Path.Combine(AppContext.BaseDirectory, "Server"); + MpdConf.Create(Path.Combine(AppContext.BaseDirectory, "Server")); - MpdConf.Create(serverPath); - - var mpdExePath = Path.Combine(serverPath, "mpd.exe"); - var mpdConfPath = Path.Combine(serverPath, "mpd.conf"); + var server = GetServer(); Process = new Process { StartInfo = new ProcessStartInfo { - FileName = mpdExePath, - WorkingDirectory = serverPath, - Arguments = string.Join(" ", mpdConfPath, "-v"), + FileName = server.FileName, + WorkingDirectory = server.WorkingDirectory, + Arguments = server.Arguments, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, @@ -34,6 +32,21 @@ namespace LibMpcTest LogError = Process.StandardError.ReadToEnd(); } + private Server GetServer() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return Server.Linux; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return Server.Windows; + } + + throw new NotSupportedException("OS not supported"); + } + public Process Process { get; } public string LogError { get; } public string LogOutput { get; } @@ -43,5 +56,29 @@ namespace LibMpcTest Process?.Kill(); Process?.Dispose(); } + + private class Server + { + public static Server Linux = new Server( + fileName: "/usr/bin/mpd", + workingDirectory: "/usr/bin/", + arguments: string.Join(" ", Path.Combine(AppContext.BaseDirectory, "Server", "mpd.conf"), "-v")); + + public static Server Windows = new Server( + fileName: Path.Combine(AppContext.BaseDirectory, "Server", "mpd.exe"), + workingDirectory: Path.Combine(AppContext.BaseDirectory, "Server"), + arguments: string.Join(" ", Path.Combine(AppContext.BaseDirectory, "Server", "mpd.conf"), "-v")); + + private Server(string fileName, string workingDirectory, string arguments) + { + FileName = fileName; + WorkingDirectory = workingDirectory; + Arguments = arguments; + } + + public string FileName { get; } + public string WorkingDirectory { get; } + public string Arguments { get; } + } } } \ No newline at end of file