From 2880ce2e46805faed8b3eba20e19a9e01c54db67 Mon Sep 17 00:00:00 2001 From: glucaci Date: Tue, 13 Dec 2016 12:55:24 +0100 Subject: [PATCH] Trigger travis to run tests. Sample test implemented. --- .travis.yml | 2 +- LibMpc/Message/MpdMessage.cs | 44 +++++++++++++++--------------- LibMpc/Message/MpdResponse.cs | 50 +++++++++++++++++------------------ LibMpcTest/LibMpcTest.cs | 15 +++++++++-- 4 files changed, 62 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index a38a3d6..b20fa5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ sudo: required mono: none dotnet: 1.0.0-preview2-003131 script: - - dotnet restore && dotnet build **/project.json + - dotnet restore && dotnet build **/project.json && dotnet test LibMpcTest\project.json notifications: email:false diff --git a/LibMpc/Message/MpdMessage.cs b/LibMpc/Message/MpdMessage.cs index 3341d67..186136e 100644 --- a/LibMpc/Message/MpdMessage.cs +++ b/LibMpc/Message/MpdMessage.cs @@ -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 Response { get; } } + [DebuggerDisplay("Request: {Request.Command.Value} | Response Status: {Response.State.Status}")] public class MpdMessage : IMpdMessage { private readonly Regex _linePattern = new Regex("^(?[A-Za-z_]*):[ ]{0,1}(?.*)$"); @@ -20,7 +22,7 @@ namespace LibMpc { Request = new MpdRequest(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 Request { get; } public IMpdResponse Response { get; } - private IList> GetValuesFromResponse() - { - var result = new List>(); - - 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> GetValuesFromResponse() + { + var result = new List>(); + + 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(mpdKey, mpdValue)); - } - } - } - } - - return result; + } + } + } + } + + return result; } public override string ToString() diff --git a/LibMpc/Message/MpdResponse.cs b/LibMpc/Message/MpdResponse.cs index 9631d44..0ad720d 100644 --- a/LibMpc/Message/MpdResponse.cs +++ b/LibMpc/Message/MpdResponse.cs @@ -1,26 +1,26 @@ -using System; -using System.Collections.Generic; - -namespace LibMpc -{ - public interface IMpdResponse - { - IMpdResponseState State { get; } - IDictionary Body { get; } - } - - public class MpdResponse : IMpdResponse - { - public MpdResponse(string endLine, IDictionary body, bool connected) - { - State = new MpdResponseState(endLine, connected); - Body = body; - } - - public IMpdResponseState State { get; } - public IDictionary Body { get; } - } - +using System; +using System.Collections.Generic; + +namespace LibMpc +{ + public interface IMpdResponse + { + IMpdResponseState State { get; } + IDictionary Body { get; } + } + + public class MpdResponse : IMpdResponse + { + public MpdResponse(string endLine, IDictionary body, bool connected) + { + State = new MpdResponseState(endLine, connected); + Body = body; + } + + public IMpdResponseState State { get; } + public IDictionary Body { get; } + } + public static class CheckNotNullExtension { public static void CheckNotNull(this object toBeChecked) @@ -30,5 +30,5 @@ namespace LibMpc throw new ArgumentNullException(nameof(toBeChecked)); } } - } -} + } +} diff --git a/LibMpcTest/LibMpcTest.cs b/LibMpcTest/LibMpcTest.cs index 1859213..cfd3775 100644 --- a/LibMpcTest/LibMpcTest.cs +++ b/LibMpcTest/LibMpcTest.cs @@ -1,9 +1,9 @@ using LibMpc; using System; -using System.IO; +using System.Linq; using System.Net; -using System.Reflection; using System.Threading.Tasks; +using Newtonsoft.Json; using Xunit; 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() { _mpc?.DisconnectAsync().GetAwaiter().GetResult();