GetTrackShoutsCommandTests

This commit is contained in:
Rikki Tooley 2013-09-09 19:55:27 +01:00
parent 85d8edad3b
commit fc42d1b34c
7 changed files with 191 additions and 1 deletions

View 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;
}
}
}

View File

@ -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);
}
}
}

View File

@ -92,6 +92,8 @@
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="Api\Commands\CommandTestsBase.cs" />
<Compile Include="Api\Commands\TrackApi\GetTrackShoutsCommandTests.cs" />
<Compile Include="Objects\AlbumTests.cs" />
<Compile Include="Api\MockAlbumApi.cs" />
<Compile Include="MockLastFm.cs" />
@ -108,6 +110,7 @@
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Resources\AlbumGetInfo.json" />
<None Include="Resources\TrackGetShoutsSingle.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IF.Lastfm.Core\IF.Lastfm.Core.csproj">
@ -121,6 +124,9 @@
<LastGenOutput>TestData.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\TrackGetShouts.json" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>

View 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"
}
}
}

View 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"
}
}
}

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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
// the code is regenerated.
@ -69,5 +69,25 @@ internal static byte[] AlbumGetInfo {
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));
}
}
}
}

View File

@ -121,4 +121,10 @@
<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>
</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>