1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-07-01 08:47:36 +00:00

Trigger travis to run tests. Sample test implemented.

This commit is contained in:
glucaci
2016-12-13 12:55:24 +01:00
parent d45aff33ee
commit 2880ce2e46
4 changed files with 62 additions and 49 deletions

View File

@ -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()

View File

@ -1,26 +1,26 @@
using System;
using System.Collections.Generic;
namespace LibMpc
{
public interface IMpdResponse<T>
{
IMpdResponseState State { get; }
IDictionary<string, T> Body { get; }
}
public class MpdResponse<T> : IMpdResponse<T>
{
public MpdResponse(string endLine, IDictionary<string, T> body, bool connected)
{
State = new MpdResponseState(endLine, connected);
Body = body;
}
public IMpdResponseState State { get; }
public IDictionary<string, T> Body { get; }
}
using System;
using System.Collections.Generic;
namespace LibMpc
{
public interface IMpdResponse<T>
{
IMpdResponseState State { get; }
IDictionary<string, T> Body { get; }
}
public class MpdResponse<T> : IMpdResponse<T>
{
public MpdResponse(string endLine, IDictionary<string, T> body, bool connected)
{
State = new MpdResponseState(endLine, connected);
Body = body;
}
public IMpdResponseState State { get; }
public IDictionary<string, T> Body { get; }
}
public static class CheckNotNullExtension
{
public static void CheckNotNull(this object toBeChecked)
@ -30,5 +30,5 @@ namespace LibMpc
throw new ArgumentNullException(nameof(toBeChecked));
}
}
}
}
}
}