mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-07-02 00:57:38 +00:00
Trigger travis to run tests. Sample test implemented.
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
@ -11,6 +12,7 @@ namespace LibMpc
|
||||
IMpdResponse<T> Response { get; }
|
||||
}
|
||||
|
||||
[DebuggerDisplay("Request: {Request.Command.Value} | Response Status: {Response.State.Status}")]
|
||||
public class MpdMessage<T> : IMpdMessage<T>
|
||||
{
|
||||
private readonly Regex _linePattern = new Regex("^(?<key>[A-Za-z_]*):[ ]{0,1}(?<value>.*)$");
|
||||
@ -20,7 +22,7 @@ namespace LibMpc
|
||||
{
|
||||
Request = new MpdRequest<T>(command);
|
||||
|
||||
var endLine = response.Skip(response.Count - 1).Single();
|
||||
var endLine = response.Skip(response.Count - 1).Single();
|
||||
_rawResponse = response.Take(response.Count - 1).ToList();
|
||||
|
||||
var values = Request.Command.FormatResponse(GetValuesFromResponse());
|
||||
@ -30,28 +32,28 @@ namespace LibMpc
|
||||
public IMpdRequest<T> Request { get; }
|
||||
public IMpdResponse<T> Response { get; }
|
||||
|
||||
private IList<KeyValuePair<string, string>> GetValuesFromResponse()
|
||||
{
|
||||
var result = new List<KeyValuePair<string, string>>();
|
||||
|
||||
foreach (var line in _rawResponse)
|
||||
{
|
||||
var match = _linePattern.Match(line);
|
||||
if (match.Success)
|
||||
{
|
||||
var mpdKey = match.Result("${key}");
|
||||
if (!string.IsNullOrEmpty(mpdKey))
|
||||
{
|
||||
var mpdValue = match.Result("${value}");
|
||||
if (!string.IsNullOrEmpty(mpdValue))
|
||||
private IList<KeyValuePair<string, string>> GetValuesFromResponse()
|
||||
{
|
||||
var result = new List<KeyValuePair<string, string>>();
|
||||
|
||||
foreach (var line in _rawResponse)
|
||||
{
|
||||
var match = _linePattern.Match(line);
|
||||
if (match.Success)
|
||||
{
|
||||
var mpdKey = match.Result("${key}");
|
||||
if (!string.IsNullOrEmpty(mpdKey))
|
||||
{
|
||||
var mpdValue = match.Result("${value}");
|
||||
if (!string.IsNullOrEmpty(mpdValue))
|
||||
{
|
||||
result.Add(new KeyValuePair<string, string>(mpdKey, mpdValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
Reference in New Issue
Block a user