mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Trigger travis to run tests. Sample test implemented.
This commit is contained in:
parent
d45aff33ee
commit
2880ce2e46
@ -4,6 +4,6 @@ sudo: required
|
|||||||
mono: none
|
mono: none
|
||||||
dotnet: 1.0.0-preview2-003131
|
dotnet: 1.0.0-preview2-003131
|
||||||
script:
|
script:
|
||||||
- dotnet restore && dotnet build **/project.json
|
- dotnet restore && dotnet build **/project.json && dotnet test LibMpcTest\project.json
|
||||||
notifications:
|
notifications:
|
||||||
email:false
|
email:false
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -11,6 +12,7 @@ namespace LibMpc
|
|||||||
IMpdResponse<T> Response { get; }
|
IMpdResponse<T> Response { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DebuggerDisplay("Request: {Request.Command.Value} | Response Status: {Response.State.Status}")]
|
||||||
public class MpdMessage<T> : IMpdMessage<T>
|
public class MpdMessage<T> : IMpdMessage<T>
|
||||||
{
|
{
|
||||||
private readonly Regex _linePattern = new Regex("^(?<key>[A-Za-z_]*):[ ]{0,1}(?<value>.*)$");
|
private readonly Regex _linePattern = new Regex("^(?<key>[A-Za-z_]*):[ ]{0,1}(?<value>.*)$");
|
||||||
@ -20,7 +22,7 @@ namespace LibMpc
|
|||||||
{
|
{
|
||||||
Request = new MpdRequest<T>(command);
|
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();
|
_rawResponse = response.Take(response.Count - 1).ToList();
|
||||||
|
|
||||||
var values = Request.Command.FormatResponse(GetValuesFromResponse());
|
var values = Request.Command.FormatResponse(GetValuesFromResponse());
|
||||||
@ -30,28 +32,28 @@ namespace LibMpc
|
|||||||
public IMpdRequest<T> Request { get; }
|
public IMpdRequest<T> Request { get; }
|
||||||
public IMpdResponse<T> Response { get; }
|
public IMpdResponse<T> Response { get; }
|
||||||
|
|
||||||
private IList<KeyValuePair<string, string>> GetValuesFromResponse()
|
private IList<KeyValuePair<string, string>> GetValuesFromResponse()
|
||||||
{
|
{
|
||||||
var result = new List<KeyValuePair<string, string>>();
|
var result = new List<KeyValuePair<string, string>>();
|
||||||
|
|
||||||
foreach (var line in _rawResponse)
|
foreach (var line in _rawResponse)
|
||||||
{
|
{
|
||||||
var match = _linePattern.Match(line);
|
var match = _linePattern.Match(line);
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
{
|
{
|
||||||
var mpdKey = match.Result("${key}");
|
var mpdKey = match.Result("${key}");
|
||||||
if (!string.IsNullOrEmpty(mpdKey))
|
if (!string.IsNullOrEmpty(mpdKey))
|
||||||
{
|
{
|
||||||
var mpdValue = match.Result("${value}");
|
var mpdValue = match.Result("${value}");
|
||||||
if (!string.IsNullOrEmpty(mpdValue))
|
if (!string.IsNullOrEmpty(mpdValue))
|
||||||
{
|
{
|
||||||
result.Add(new KeyValuePair<string, string>(mpdKey, mpdValue));
|
result.Add(new KeyValuePair<string, string>(mpdKey, mpdValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace LibMpc
|
namespace LibMpc
|
||||||
{
|
{
|
||||||
public interface IMpdResponse<T>
|
public interface IMpdResponse<T>
|
||||||
{
|
{
|
||||||
IMpdResponseState State { get; }
|
IMpdResponseState State { get; }
|
||||||
IDictionary<string, T> Body { get; }
|
IDictionary<string, T> Body { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MpdResponse<T> : IMpdResponse<T>
|
public class MpdResponse<T> : IMpdResponse<T>
|
||||||
{
|
{
|
||||||
public MpdResponse(string endLine, IDictionary<string, T> body, bool connected)
|
public MpdResponse(string endLine, IDictionary<string, T> body, bool connected)
|
||||||
{
|
{
|
||||||
State = new MpdResponseState(endLine, connected);
|
State = new MpdResponseState(endLine, connected);
|
||||||
Body = body;
|
Body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMpdResponseState State { get; }
|
public IMpdResponseState State { get; }
|
||||||
public IDictionary<string, T> Body { get; }
|
public IDictionary<string, T> Body { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CheckNotNullExtension
|
public static class CheckNotNullExtension
|
||||||
{
|
{
|
||||||
public static void CheckNotNull(this object toBeChecked)
|
public static void CheckNotNull(this object toBeChecked)
|
||||||
@ -30,5 +30,5 @@ namespace LibMpc
|
|||||||
throw new ArgumentNullException(nameof(toBeChecked));
|
throw new ArgumentNullException(nameof(toBeChecked));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using LibMpc;
|
using LibMpc;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
@ -30,6 +30,17 @@ namespace LibMpcTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ListAllTest()
|
||||||
|
{
|
||||||
|
var response = await _mpc.SendAsync(new Commands.Reflection.TagTypes());
|
||||||
|
|
||||||
|
_output.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
||||||
|
|
||||||
|
Assert.True(response.Response.Body.Keys.Contains("tagtypes"));
|
||||||
|
Assert.True(response.Response.Body.Values.Any());
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_mpc?.DisconnectAsync().GetAwaiter().GetResult();
|
_mpc?.DisconnectAsync().GetAwaiter().GetResult();
|
||||||
|
Loading…
Reference in New Issue
Block a user