Exemplo n.º 1
0
        public async Task ListPlaylistInfoTest(string playlistName, int numberOfFiles)
        {
            var response = await Mpc.SendAsync(Commands.Playlists.Stored.GetContentWithMetadata(playlistName));

            TestOutput.WriteLine($"ListPlaylistTest (playlistName: {playlistName}) Result:");
            TestOutput.WriteLine(response);

            Assert.IsTrue(response.Response.Body.Count().Equals(numberOfFiles));
            Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Artist)));
            Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Title)));
            Assert.IsTrue(response.Response.Body.All(item => !string.IsNullOrEmpty(item.Date)));
        }
Exemplo n.º 2
0
        public async Task UrlHandlersTest()
        {
            var response = await Mpc.SendAsync(new Commands.Reflection.UrlHandlers());

            TestOutput.WriteLine($"UrlHandlersTest (handlers: {response.Response.Body.Count()}) Result:");
            TestOutput.WriteLine(response);

            // Different answer from MPD on Windows and on Linux.
            // Check some of the handlers.
            Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("http://")));
            Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("mms://")));
            Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("gopher://")));
            Assert.IsTrue(response.Response.Body.Any(handler => handler.Equals("rtp://")));
        }
Exemplo n.º 3
0
        public async Task CommandsTest()
        {
            var response = await Mpc.SendAsync(new Commands.Reflection.Commands());

            TestOutput.WriteLine($"CommandsTest (commands: {response.Response.Body.Count()}) Result:");
            TestOutput.WriteLine(response);

            // Different answer from MPD on Windows and on Linux, beacuse of Version.
            // Check some of the commands.
            Assert.IsTrue(response.Response.Body.Any(command => command.Equals("listall")));
            Assert.IsTrue(response.Response.Body.Any(command => command.Equals("outputs")));
            Assert.IsTrue(response.Response.Body.Any(command => command.Equals("pause")));
            Assert.IsTrue(response.Response.Body.Any(command => command.Equals("play")));
            Assert.IsTrue(response.Response.Body.Any(command => command.Equals("setvol")));
            Assert.IsTrue(response.Response.Body.Any(command => command.Equals("stop")));
        }
Exemplo n.º 4
0
        public async Task DisableOutputTest()
        {
            var responseOutputs = await Mpc.SendAsync(new Commands.Output.OutputsCommand());

            Assert.IsTrue(responseOutputs.Response.Content.Single(output => output.Id.Equals(0)).IsEnabled);

            var response = await Mpc.SendAsync(new Commands.Output.DisableOutputCommand(0));

            TestOutput.WriteLine("DisableOutputTest Result:");
            TestOutput.WriteLine(response);

            Assert.IsTrue(response.Response.Content.Equals(string.Empty));
            Assert.IsTrue(response.Response.Result.Status.Equals("OK"));

            responseOutputs = await Mpc.SendAsync(new Commands.Output.OutputsCommand());

            Assert.IsFalse(responseOutputs.Response.Content.Single(output => output.Id.Equals(0)).IsEnabled);
        }
Exemplo n.º 5
0
        public async Task ToggleOutputTest()
        {
            var responseOutputs = await Mpc.SendAsync(new Commands.Output.Outputs());

            Assert.IsTrue(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(response);

            Assert.IsTrue(response.Response.Body.Equals(string.Empty));
            Assert.IsTrue(response.Response.State.Status.Equals("OK"));

            responseOutputs = await Mpc.SendAsync(new Commands.Output.Outputs());

            Assert.IsFalse(responseOutputs.Response.Body.Single(output => output.Id.Equals(2)).IsEnabled);
        }
Exemplo n.º 6
0
        public async Task EnableOutputTest()
        {
            var responseOutputs = await Mpc.SendAsync(new Commands.Output.OutputsCommand());

            // By default should be disable from mpd.config
            Assert.IsFalse(responseOutputs.Response.Content.Single(output => output.Id.Equals(1)).IsEnabled);

            var response = await Mpc.SendAsync(new Commands.Output.EnableOutputCommand(1));

            TestOutput.WriteLine("EnableOutputTest Result:");
            TestOutput.WriteLine(response);

            Assert.IsTrue(response.Response.Content.Equals(string.Empty));
            Assert.IsTrue(response.Response.Result.Status.Equals("OK"));

            responseOutputs = await Mpc.SendAsync(new Commands.Output.OutputsCommand());

            Assert.IsTrue(responseOutputs.Response.Content.Single(output => output.Id.Equals(1)).IsEnabled);
        }
Exemplo n.º 7
0
        public async Task DecodersTest()
        {
            var response = await Mpc.SendAsync(new Commands.Reflection.Decoders());

            TestOutput.WriteLine($"DecodersTest (decoders: {response.Response.Body.Count()}) Result:");
            TestOutput.WriteLine(response);

            // Different answer from MPD on Windows and on Linux.
            // Check some of the decoders.
            Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("mad")));
            Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("mp3"))));
            Assert.IsTrue(response.Response.Body.Any(decoder => decoder.MediaTypes.Any(mediaType => mediaType.Equals("audio/mpeg"))));
            Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("flac")));
            Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Suffixes.Any(suffix => suffix.Equals("flac"))));
            Assert.IsTrue(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/x-flac"))));
            Assert.IsTrue(response.Response.Body.Any(decoder => decoder.Name.Equals("ffmpeg")));
            Assert.IsTrue(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("mpeg"))));
            Assert.IsTrue(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/mpeg"))));
        }
Exemplo n.º 8
0
        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();

            TestOutput.WriteLine(command);
            TestOutput.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}");
            TestOutput.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}");
        }
Exemplo n.º 9
0
        public void Start()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                SendCommand("/usr/bin/pkill mpd");
            }

            MpdConf.Create(Path.Combine(AppContext.BaseDirectory, "Server"));

            var server = GetServer();

            Process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = server.FileName,
                    WorkingDirectory       = server.WorkingDirectory,
                    Arguments              = server.Arguments,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                }
            };

            TestOutput.WriteLine($"Starting Server: {Process.StartInfo.FileName} {Process.StartInfo.Arguments}");

            Process.Start();
            TestOutput.WriteLine($"Output: {Process.StandardOutput.ReadToEnd()}");
            TestOutput.WriteLine($"Error: {Process.StandardError.ReadToEnd()}");

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                SendCommand("/bin/netstat -ntpl");
            }
        }
Exemplo n.º 10
0
        private static async Task SendCommand <T>(IMpcCommand <T> command)
        {
            var response = await Mpc.SendAsync(command);

            TestOutput.WriteLine(response);
        }
Exemplo n.º 11
0
        private static async Task SendCommand(string command)
        {
            var response = await Mpc.SendAsync(new PassthroughCommand(command));

            TestOutput.WriteLine(response);
        }
Exemplo n.º 12
0
 public void Dispose()
 {
     Process?.Kill();
     Process?.Dispose();
     TestOutput.WriteLine("Server Stopped.");
 }
Exemplo n.º 13
0
 public void Dispose()
 {
     this.Client?.DisconnectAsync().GetAwaiter().GetResult();
     TestOutput.WriteLine($"Disconnected from MPD.");
 }