mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 07:13:09 +01:00
GetTrackShoutsCommandTests
This commit is contained in:
parent
85d8edad3b
commit
fc42d1b34c
35
IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs
Normal file
35
IF.Lastfm.Core.Tests/Api/Commands/CommandTestsBase.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using IF.Lastfm.Core.Api;
|
||||||
|
using Moq;
|
||||||
|
|
||||||
|
namespace IF.Lastfm.Core.Tests.Api.Commands
|
||||||
|
{
|
||||||
|
public abstract class CommandTestsBase
|
||||||
|
{
|
||||||
|
public Mock<IAuth> MAuth { get; private set; }
|
||||||
|
|
||||||
|
protected CommandTestsBase()
|
||||||
|
{
|
||||||
|
MAuth = new Mock<IAuth>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void Constructor();
|
||||||
|
public abstract Task HandleSuccessResponse();
|
||||||
|
|
||||||
|
protected HttpResponseMessage CreateResponseMessage(string message)
|
||||||
|
{
|
||||||
|
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
Content = new StringContent(message, Encoding.UTF8)
|
||||||
|
};
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using IF.Lastfm.Core.Api.Commands.TrackApi;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace IF.Lastfm.Core.Tests.Api.Commands.TrackApi
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class GetTrackShoutsCommandTests : CommandTestsBase
|
||||||
|
{
|
||||||
|
private GetTrackShoutsCommand _command;
|
||||||
|
|
||||||
|
public GetTrackShoutsCommandTests()
|
||||||
|
{
|
||||||
|
_command = new GetTrackShoutsCommand(MAuth.Object, "Genesis", "Grimes")
|
||||||
|
{
|
||||||
|
Autocorrect = true,
|
||||||
|
Page = 5,
|
||||||
|
Count = 7
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public override void Constructor()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(_command.TrackName, "Genesis");
|
||||||
|
Assert.AreEqual(_command.ArtistName, "Grimes");
|
||||||
|
Assert.AreEqual(_command.Method, "track.getShouts");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async override Task HandleSuccessResponse()
|
||||||
|
{
|
||||||
|
var response = CreateResponseMessage(Encoding.UTF8.GetString(TestData.TrackGetShouts));
|
||||||
|
|
||||||
|
var parsed = await _command.HandleResponse(response);
|
||||||
|
|
||||||
|
Assert.IsTrue(parsed.Page == 5);
|
||||||
|
Assert.IsTrue(parsed.Content.Count() == 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The shouts API uses a different schema when there's only one shout in the page
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[TestMethod]
|
||||||
|
public async Task HandleResponseSingle()
|
||||||
|
{
|
||||||
|
var response = CreateResponseMessage(Encoding.UTF8.GetString(TestData.TrackGetShoutsSingle));
|
||||||
|
|
||||||
|
var parsed = await _command.HandleResponse(response);
|
||||||
|
|
||||||
|
Assert.IsTrue(parsed.Content.Count() == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -92,6 +92,8 @@
|
|||||||
<Otherwise />
|
<Otherwise />
|
||||||
</Choose>
|
</Choose>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Api\Commands\CommandTestsBase.cs" />
|
||||||
|
<Compile Include="Api\Commands\TrackApi\GetTrackShoutsCommandTests.cs" />
|
||||||
<Compile Include="Objects\AlbumTests.cs" />
|
<Compile Include="Objects\AlbumTests.cs" />
|
||||||
<Compile Include="Api\MockAlbumApi.cs" />
|
<Compile Include="Api\MockAlbumApi.cs" />
|
||||||
<Compile Include="MockLastFm.cs" />
|
<Compile Include="MockLastFm.cs" />
|
||||||
@ -108,6 +110,7 @@
|
|||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="Resources\AlbumGetInfo.json" />
|
<None Include="Resources\AlbumGetInfo.json" />
|
||||||
|
<None Include="Resources\TrackGetShoutsSingle.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\IF.Lastfm.Core\IF.Lastfm.Core.csproj">
|
<ProjectReference Include="..\IF.Lastfm.Core\IF.Lastfm.Core.csproj">
|
||||||
@ -121,6 +124,9 @@
|
|||||||
<LastGenOutput>TestData.Designer.cs</LastGenOutput>
|
<LastGenOutput>TestData.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="Resources\TrackGetShouts.json" />
|
||||||
|
</ItemGroup>
|
||||||
<Choose>
|
<Choose>
|
||||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
49
IF.Lastfm.Core.Tests/Resources/TrackGetShouts.json
Normal file
49
IF.Lastfm.Core.Tests/Resources/TrackGetShouts.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"shouts": {
|
||||||
|
"shout": [
|
||||||
|
{
|
||||||
|
"body": "Timeless!",
|
||||||
|
"author": "lukasz_pulawski",
|
||||||
|
"date": "Thu, 29 Aug 2013 21:21:06"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"body": "i have a weird feeling listening this song. kinda nostalgic, happy and sad at the same time [3]",
|
||||||
|
"author": "Einarr123",
|
||||||
|
"date": "Thu, 29 Aug 2013 02:00:33"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"body": "LEGEND",
|
||||||
|
"author": "hlopez90",
|
||||||
|
"date": "Fri, 23 Aug 2013 23:15:37"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"body": "This song gets stucked in you head for ages",
|
||||||
|
"author": "Go_diego",
|
||||||
|
"date": "Fri, 23 Aug 2013 19:02:17"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"body": "Personal soundtrack",
|
||||||
|
"author": "guialoud",
|
||||||
|
"date": "Mon, 19 Aug 2013 00:24:32"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"body": "Pop Anthem",
|
||||||
|
"author": "HazieI",
|
||||||
|
"date": "Sun, 28 Jul 2013 07:27:34"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"body": "i have a weird feeling listening this song. kinda nostalgic, happy and sad at the same time [2]",
|
||||||
|
"author": "HazieI",
|
||||||
|
"date": "Sun, 28 Jul 2013 07:18:05"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@attr": {
|
||||||
|
"artist": "Grimes",
|
||||||
|
"track": "Genesis",
|
||||||
|
"page": "5",
|
||||||
|
"perPage": "7",
|
||||||
|
"totalPages": "15",
|
||||||
|
"total": "105"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
IF.Lastfm.Core.Tests/Resources/TrackGetShoutsSingle.json
Normal file
17
IF.Lastfm.Core.Tests/Resources/TrackGetShoutsSingle.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"shouts": {
|
||||||
|
"shout": {
|
||||||
|
"body": "i have a weird feeling listening this song. kinda nostalgic, happy and sad at the same time [2]",
|
||||||
|
"author": "HazieI",
|
||||||
|
"date": "Sun, 28 Jul 2013 07:18:05"
|
||||||
|
},
|
||||||
|
"@attr": {
|
||||||
|
"artist": "Grimes",
|
||||||
|
"track": "Genesis",
|
||||||
|
"page": "7",
|
||||||
|
"perPage": "10",
|
||||||
|
"totalPages": "7",
|
||||||
|
"total": "61"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
IF.Lastfm.Core.Tests/TestData.Designer.cs
generated
22
IF.Lastfm.Core.Tests/TestData.Designer.cs
generated
@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.18033
|
// Runtime Version:4.0.30319.32559
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
@ -69,5 +69,25 @@ internal static byte[] AlbumGetInfo {
|
|||||||
return ((byte[])(obj));
|
return ((byte[])(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] TrackGetShouts {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("TrackGetShouts", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] TrackGetShoutsSingle {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("TrackGetShoutsSingle", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,4 +121,10 @@
|
|||||||
<data name="AlbumGetInfo" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="AlbumGetInfo" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>resources\albumgetinfo.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>resources\albumgetinfo.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TrackGetShouts" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>resources\trackgetshouts.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
|
<data name="TrackGetShoutsSingle" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>resources\trackgetshoutssingle.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue
Block a user