Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional username parameter to Artist.GetInfoAsync. #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 129 additions & 2 deletions src/IF.Lastfm.Core.Tests/Api/Commands/Artist/GetInfoCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public async Task HandleSuccessResponse()
Stats = new LastStats
{
Listeners = 513447,
Plays = 0
Plays = 0,
UserPlayCount = null
}
};

Expand All @@ -125,7 +126,116 @@ public async Task HandleSuccessResponse()

Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson));
}


[Test]
public async Task HandleSuccessResponseForUser()
{
_command = new GetInfoCommand(MAuth.Object)
{
ArtistName = "Frightened Rabbit",
UserName = "test-user"
};

var expectedArtist = new LastArtist()
{
Name = "Frightened Rabbit",
Mbid = "dc21d171-7204-4759-9fd0-77d031aeb40c",
Url = new Uri("http://www.last.fm/music/Frightened+Rabbit"),
MainImage = new LastImageSet("http://userserve-ak.last.fm/serve/34/50340089.jpg",
"http://userserve-ak.last.fm/serve/64/50340089.jpg",
"http://userserve-ak.last.fm/serve/126/50340089.jpg",
"http://userserve-ak.last.fm/serve/252/50340089.jpg",
"http://userserve-ak.last.fm/serve/_/50340089/Frightened+Rabbit+frabbit.jpg"),
// todo streamable
OnTour = false,
Similar = new List<LastArtist>
{
new LastArtist
{
Name = "Admiral Fallow",
Url = new Uri("http://www.last.fm/music/Admiral+Fallow"),
MainImage = new LastImageSet("http://userserve-ak.last.fm/serve/34/48454975.jpg",
"http://userserve-ak.last.fm/serve/64/48454975.jpg",
"http://userserve-ak.last.fm/serve/126/48454975.jpg",
"http://userserve-ak.last.fm/serve/252/48454975.jpg",
"http://userserve-ak.last.fm/serve/500/48454975/Admiral+Fallow+l_1185fb2755064ccfbab2871ecec8.jpg")
},
new LastArtist
{
Name = "The Twilight Sad",
Url = new Uri("http://www.last.fm/music/The+Twilight+Sad"),
MainImage = new LastImageSet("http://userserve-ak.last.fm/serve/34/18201771.jpg",
"http://userserve-ak.last.fm/serve/64/18201771.jpg",
"http://userserve-ak.last.fm/serve/126/18201771.jpg",
"http://userserve-ak.last.fm/serve/252/18201771.jpg",
"http://userserve-ak.last.fm/serve/500/18201771/The+Twilight+Sad+hi+how+are+you.jpg"),
},
new LastArtist
{
Name = "Owl John",
Url = new Uri("http://www.last.fm/music/Owl+John"),
MainImage = new LastImageSet("http://userserve-ak.last.fm/serve/34/101981791.png",
"http://userserve-ak.last.fm/serve/64/101981791.png",
"http://userserve-ak.last.fm/serve/126/101981791.png",
"http://userserve-ak.last.fm/serve/252/101981791.png",
"http://userserve-ak.last.fm/serve/500/101981791/Owl+John+owl.png"),
},
new LastArtist
{
Name = "We Were Promised Jetpacks",
Url = new Uri("http://www.last.fm/music/We+Were+Promised+Jetpacks"),
MainImage = new LastImageSet("http://userserve-ak.last.fm/serve/34/53527397.jpg",
"http://userserve-ak.last.fm/serve/64/53527397.jpg",
"http://userserve-ak.last.fm/serve/126/53527397.jpg",
"http://userserve-ak.last.fm/serve/252/53527397.jpg",
"http://userserve-ak.last.fm/serve/_/53527397/We+Were+Promised+Jetpacks+wwpj.jpg"),
},
new LastArtist
{
Name = "Meursault",
Url = new Uri("http://www.last.fm/music/Meursault"),
MainImage = new LastImageSet("http://userserve-ak.last.fm/serve/34/41921789.jpg",
"http://userserve-ak.last.fm/serve/64/41921789.jpg",
"http://userserve-ak.last.fm/serve/126/41921789.jpg",
"http://userserve-ak.last.fm/serve/252/41921789.jpg",
"http://userserve-ak.last.fm/serve/_/41921789/Meursault+lovely+fuckwits.jpg"),
}
},
Tags = new List<LastTag>
{
new LastTag("indie", "http://www.last.fm/tag/indie"),
new LastTag("scottish", "http://www.last.fm/tag/scottish"),
new LastTag("indie rock", "http://www.last.fm/tag/indie%20rock"),
new LastTag("folk", "http://www.last.fm/tag/folk"),
new LastTag("folk rock", "http://www.last.fm/tag/folk%20rock"),
},
Bio = new LastWiki
{
Content = "Frightened Rabbit are an <a href=\"http://www.last.fm/tag/indie%20rock\" class=\"bbcode_tag\" rel=\"tag\">indie rock</a> band which formed in 2003 in Glasgow, Scotland. The band currently consists of Scott Hutchison (vocals, guitar), Billy Kennedy (guitar, keyboards), Grant Hutchison (drums, vocals), Andy Monaghan (guitar, keyboards) and Gordon Skene (guitar, keyboards). The band has released four albums: &quot;Sing the Greys&quot; (2006), &quot;The Midnight Organ Fight&quot; (2008), &quot;The Winter of Mixed Drinks&quot; (2010) and &quot;Pedestrian Verse&quot; (2013). \n\n <a href=\"http://www.last.fm/music/Frightened+Rabbit\">Read more about Frightened Rabbit on Last.fm</a>.\n \n \nUser-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.",
Summary = "Frightened Rabbit are an <a href=\"http://www.last.fm/tag/indie%20rock\" class=\"bbcode_tag\" rel=\"tag\">indie rock</a> band which formed in 2003 in Glasgow, Scotland. The band currently consists of Scott Hutchison (vocals, guitar), Billy Kennedy (guitar, keyboards), Grant Hutchison (drums, vocals), Andy Monaghan (guitar, keyboards) and Gordon Skene (guitar, keyboards). The band has released four albums: &quot;Sing the Greys&quot; (2006), &quot;The Midnight Organ Fight&quot; (2008), &quot;The Winter of Mixed Drinks&quot; (2010) and &quot;Pedestrian Verse&quot; (2013). \n\n <a href=\"http://www.last.fm/music/Frightened+Rabbit\">Read more about Frightened Rabbit on Last.fm</a>.",
Published = new DateTimeOffset(2013, 2, 6, 0, 4, 40, TimeSpan.Zero),
YearFormed = 2003
},
Stats = new LastStats
{
Listeners = 513447,
Plays = 0,
UserPlayCount = 59452
}
};

var file = GetFileContents("ArtistApi.ArtistGetInfoForUserSuccess.json");
var response = CreateResponseMessage(file);
var parsed = await _command.HandleResponse(response);

Assert.IsTrue(parsed.Success);

var expectedJson = expectedArtist.TestSerialise();
var actualJson = parsed.Content.TestSerialise();

Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson));
}

[Test]
public void ArtistGetInfo_SetLangParam_Success()
{
Expand All @@ -143,6 +253,23 @@ public void ArtistGetInfo_SetLangParam_Success()
Assert.AreEqual("fr", langValue);
}

[Test]
public void ArtistGetInfo_SetUserNameParam_Success()
{
string expectedUserName = "test-user";

GetInfoCommand getInfoCommand = new GetInfoCommand(MAuth.Object)
{
ArtistName = "Frightened Rabbit",
UserName = expectedUserName
};

getInfoCommand.SetParameters();
string userNameValue;
Assert.IsTrue(getInfoCommand.Parameters.TryGetValue("username", out userNameValue));
Assert.AreEqual(expectedUserName, userNameValue);
}

[Test]
public async Task HandleErrorResponse()
{
Expand Down
4 changes: 4 additions & 0 deletions src/IF.Lastfm.Core.Tests/IF.Lastfm.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<EmbeddedResource Include="Resources\TrackApi\*.txt" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\ArtistApi\ArtistGetInfoForUserSuccess.json" />
</ItemGroup>

<!--
<ItemGroup>
<Reference Include="Moq, Version=4.2.1502.911, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
Expand Down
Loading