mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 07:13:09 +01:00
user get top albums command
This commit is contained in:
parent
4c7ae32cd0
commit
cd157882eb
@ -1,5 +1,7 @@
|
|||||||
using IF.Lastfm.Core.Api.Commands.UserApi;
|
using IF.Lastfm.Core.Api;
|
||||||
|
using IF.Lastfm.Core.Api.Commands.UserApi;
|
||||||
using IF.Lastfm.Core.Api.Enums;
|
using IF.Lastfm.Core.Api.Enums;
|
||||||
|
using IF.Lastfm.Core.Api.Helpers;
|
||||||
using IF.Lastfm.Core.Objects;
|
using IF.Lastfm.Core.Objects;
|
||||||
using IF.Lastfm.Core.Tests.Resources;
|
using IF.Lastfm.Core.Tests.Resources;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
@ -7,6 +9,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Moq;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace IF.Lastfm.Core.Tests.Api.Commands
|
namespace IF.Lastfm.Core.Tests.Api.Commands
|
||||||
{
|
{
|
||||||
@ -82,4 +86,67 @@ public async Task HandleErrorResponse()
|
|||||||
Assert.IsTrue(parsed.Error == LastFmApiError.MissingParameters);
|
Assert.IsTrue(parsed.Error == LastFmApiError.MissingParameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class UserGetTopAlbumsCommandTests : CommandTestsBase
|
||||||
|
{
|
||||||
|
private const string USER = "test";
|
||||||
|
private const LastStatsTimeSpan SPAN = LastStatsTimeSpan.Month;
|
||||||
|
|
||||||
|
private GetTopAlbumsCommand _command;
|
||||||
|
private Mock<ILastAuth> _mockAuth;
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void TestInitialise()
|
||||||
|
{
|
||||||
|
_mockAuth = new Mock<ILastAuth>();
|
||||||
|
_command = new GetTopAlbumsCommand(_mockAuth.Object, USER, SPAN)
|
||||||
|
{
|
||||||
|
Page = 5,
|
||||||
|
Count = 20
|
||||||
|
};
|
||||||
|
|
||||||
|
_command.SetParameters();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CorrectParameters()
|
||||||
|
{
|
||||||
|
var expected = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{"user", USER},
|
||||||
|
{"period", SPAN.GetApiName()},
|
||||||
|
{"limit", "20"},
|
||||||
|
{"page", "5"},
|
||||||
|
{"disablecachetoken", ""}
|
||||||
|
};
|
||||||
|
|
||||||
|
_command.Parameters["disablecachetoken"] = "";
|
||||||
|
|
||||||
|
TestHelper.AssertEqual(expected, _command.Parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleErrorResponse()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void HandleResponseEmpty()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void HandleResponseSingle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void HandleResponseMultiple()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@
|
|||||||
<Compile Include="Api\MockAlbumApi.cs" />
|
<Compile Include="Api\MockAlbumApi.cs" />
|
||||||
<Compile Include="MockLastFm.cs" />
|
<Compile Include="MockLastFm.cs" />
|
||||||
<Compile Include="LastFmTests.cs" />
|
<Compile Include="LastFmTests.cs" />
|
||||||
|
<Compile Include="OrderedContractResolver.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Resources\AlbumApiResponses.Designer.cs">
|
<Compile Include="Resources\AlbumApiResponses.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
|
19
src/IF.Lastfm.Core.Tests/OrderedContractResolver.cs
Normal file
19
src/IF.Lastfm.Core.Tests/OrderedContractResolver.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
namespace IF.Lastfm.Core.Tests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// http://stackoverflow.com/a/11309106/268555
|
||||||
|
/// </summary>
|
||||||
|
public class OrderedContractResolver : DefaultContractResolver
|
||||||
|
{
|
||||||
|
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||||
|
{
|
||||||
|
return base.CreateProperties(type, memberSerialization).OrderBy(p => p.PropertyName).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +1,60 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using IF.Lastfm.Core.Api.Helpers;
|
using IF.Lastfm.Core.Api.Helpers;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace IF.Lastfm.Core.Tests
|
namespace IF.Lastfm.Core.Tests
|
||||||
{
|
{
|
||||||
public static class TestHelper
|
public static class TestHelper
|
||||||
{
|
{
|
||||||
private static readonly JsonSerializerSettings _testSerialiserSettings;
|
private static JsonSerializer GetTestSerialiser()
|
||||||
|
|
||||||
static TestHelper()
|
|
||||||
{
|
{
|
||||||
_testSerialiserSettings = new JsonSerializerSettings
|
return new JsonSerializer
|
||||||
{
|
{
|
||||||
DateFormatString = "yyyy-MM-dd HH:mm:ss.fff",
|
DateFormatString = "yyyy-MM-dd HH:mm:ss.fff",
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
|
ContractResolver = new OrderedContractResolver()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JObject WithSortedProperties(this JObject jo)
|
||||||
|
{
|
||||||
|
var result = new JObject();
|
||||||
|
foreach (var prop in jo.Properties().OrderBy(p => p.Name))
|
||||||
|
{
|
||||||
|
var nestedJo = prop.Value as JObject;
|
||||||
|
if (nestedJo != null)
|
||||||
|
{
|
||||||
|
result.Add(nestedJo.WithSortedProperties());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.Add(prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static string TestSerialise<T>(this T poco)
|
public static string TestSerialise<T>(this T poco)
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(poco, Formatting.Indented, _testSerialiserSettings);
|
var serialiser = GetTestSerialiser();
|
||||||
|
var jo = JObject.FromObject(poco, serialiser);
|
||||||
|
var ordered = jo.WithSortedProperties();
|
||||||
|
|
||||||
|
return ordered.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AssertEqual<T>(T one, T two)
|
||||||
|
{
|
||||||
|
var ones = one.TestSerialise();
|
||||||
|
var twos = two.TestSerialise();
|
||||||
|
|
||||||
|
Assert.AreEqual(ones, twos, ones.DifferencesTo(twos));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string DifferencesTo<T>(this IEnumerable<T> expected, IEnumerable<T> actual)
|
public static string DifferencesTo<T>(this IEnumerable<T> expected, IEnumerable<T> actual)
|
||||||
|
@ -22,7 +22,7 @@ public GetTopAlbumsCommand(ILastAuth auth, string username, LastStatsTimeSpan sp
|
|||||||
|
|
||||||
public override void SetParameters()
|
public override void SetParameters()
|
||||||
{
|
{
|
||||||
Parameters.Add("username", Username);
|
Parameters.Add("user", Username);
|
||||||
Parameters.Add("period", TimeSpan.GetApiName());
|
Parameters.Add("period", TimeSpan.GetApiName());
|
||||||
|
|
||||||
AddPagingParameters();
|
AddPagingParameters();
|
||||||
|
Loading…
Reference in New Issue
Block a user