Skip to content

Commit

Permalink
Test were fixed
Browse files Browse the repository at this point in the history
 * TrackUpdateNowPlayingCommand: some values were emptyed
 * GetWeeklyAlbumChartAsync  and GetWeeklyArtistChartAsync were done without parameter "to"
 * UserGetWeeklyTrackChartTests was commented, since it's bad test now and should be done another way (see my comment in the file)
  • Loading branch information
tolbxela committed Mar 31, 2020
1 parent 9dd2ef9 commit 68e07a7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using IF.Lastfm.Core.Api;
using IF.Lastfm.Core.Objects;
using NUnit.Framework;
using System;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using IF.Lastfm.Core.Api.Enums;
using IF.Lastfm.Core.Helpers;
using IF.Lastfm.Core.Objects;
using IF.Lastfm.Core.Scrobblers;
using NUnit.Framework;

namespace IF.Lastfm.Core.Tests.Integration.Commands
{
Expand All @@ -36,18 +34,17 @@ public async Task ScrobblesSingle()
var response = await Lastfm.Scrobbler.ScrobbleAsync(testScrobble);

Assert.IsTrue(response.Success);

var expectedTrack = new LastTrack
{
Name = TRACK_NAME,
ArtistName = ARTIST_NAME,
AlbumName = ALBUM_NAME
AlbumName = ALBUM_NAME,
};
var expectedJson = expectedTrack.TestSerialise();

var tracks = await Lastfm.User.GetRecentScrobbles(Lastfm.Auth.UserSession.Username, null, null, false, 1, 1);
var scrobbledTrack = tracks.Single(x => !x.IsNowPlaying.GetValueOrDefault(false));

TestHelper.AssertSerialiseEqual(trackPlayed, scrobbledTrack.TimePlayed);

scrobbledTrack.TimePlayed = null;
Expand All @@ -57,6 +54,9 @@ public async Task ScrobblesSingle()
scrobbledTrack.ArtistMbid = null;
scrobbledTrack.Images = null;
scrobbledTrack.Url = null;
scrobbledTrack.ArtistImages = null;
scrobbledTrack.ArtistUrl = null;
scrobbledTrack.IsLoved = null;

var actualJson = scrobbledTrack.TestSerialise();

Expand All @@ -75,7 +75,7 @@ public async Task ScrobblesMultiple()
MaxBatchSize = 2
};
var response = await scrobbler.ScrobbleAsync(scrobbles);

Assert.AreEqual(2, countingHandler.Count);
Assert.AreEqual(LastResponseStatus.Successful, response.Status);
Assert.IsTrue(response.Success);
Expand All @@ -100,4 +100,4 @@ private IList<Scrobble> GenerateScrobbles(int amount)
}).ToList();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using IF.Lastfm.Core.Api;
using IF.Lastfm.Core.Objects;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;
using IF.Lastfm.Core.Objects;
using NUnit.Framework;

namespace IF.Lastfm.Core.Tests.Integration.Commands
{

public class TrackUpdateNowPlayingCommandTests : CommandIntegrationTestsBase
{
private const string ARTIST_NAME = "Crystal Castles";
Expand Down Expand Up @@ -47,6 +45,9 @@ public async Task UpdatesNowPlaying()
actual.ArtistMbid = null;
actual.Images = null;
actual.Url = null;
actual.ArtistImages = null;
actual.ArtistUrl = null;
actual.IsLoved = null;

var expectedJson = expectedTrack.TestSerialise();
var actualJson = actual.TestSerialise();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

Expand All @@ -15,13 +12,13 @@ public async Task GetAlbumChart_Success()
//call GetWeeklyChartList to get available weeks
var weekList = await Lastfm.User.GetWeeklyChartListAsync(INTEGRATION_TEST_USER);
var from = weekList.Content.Last().From;
var to = weekList.Content.Last().To;
//var to = weekList.Content.Last().To;
//use the from and to params to call GetWeeklyArtistChart for the last week
var response = await Lastfm.User.GetWeeklyAlbumChartAsync(INTEGRATION_TEST_USER, from, to);
var response = await Lastfm.User.GetWeeklyAlbumChartAsync(INTEGRATION_TEST_USER, from);
var artistChart = response.Content;

Assert.IsTrue(response.Success);

//Values will vary from week to week so just checking that we got some values back
Assert.IsNotEmpty(artistChart);
Assert.IsNotEmpty(artistChart.First().Name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

Expand All @@ -15,13 +12,13 @@ public async Task GetChartList_Success()
//call GetWeeklyChartList to get available weeks
var weekList = await Lastfm.User.GetWeeklyChartListAsync(INTEGRATION_TEST_USER);
var from = weekList.Content.Last().From;
var to = weekList.Content.Last().To;
//var to = weekList.Content.Last().To;
//use the from and to params to call GetWeeklyArtistChart for the last week
var response = await Lastfm.User.GetWeeklyArtistChartAsync(INTEGRATION_TEST_USER, from, to);
var response = await Lastfm.User.GetWeeklyArtistChartAsync(INTEGRATION_TEST_USER, from);
var artistChart = response.Content;

Assert.IsTrue(response.Success);

//Values will vary from week to week so just checking that we got some values back
Assert.IsNotEmpty(artistChart);
Assert.IsNotEmpty(artistChart.First().Name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace IF.Lastfm.Core.Tests.Integration.Commands
{
/*
* Sorry, but this is a bad test!
* It is based on expectation, that there is some activity in the Last.fm users profile and will fail when there were no scrobles for last three weeks.
* The tests should not expect any data input outside!
public class UserGetWeeklyTrackChartTests : CommandIntegrationTestsBase
{

[Test]
[Test]
public async Task GetTrackChart_Success()
{
//call GetWeeklyChartList to get available weeks
Expand All @@ -26,16 +23,17 @@ public async Task GetTrackChart_Success()
//get weekly chart for the week before
var responsePrev = await Lastfm.User.GetWeeklyTrackChartAsync(INTEGRATION_TEST_USER, fromPrevWeek, toPrevWeek);
var trackChartPrev = responsePrev.Content;
Assert.IsTrue(response.Success, "User.GetWeeklyChartListAsync - response.Success was not true");
//Values will vary from week to week so just checking that we got some values back
Assert.IsNotEmpty(trackChart, "User.GetWeeklyChartListAsync - response.Content was empty");
Assert.IsNotEmpty(trackChart.First().Name);
Assert.IsNotEmpty(trackChart.First().ArtistName);
//check that the two different weekly charts are not the same
Assert.IsFalse(trackChart.First().Name == trackChartPrev.First().Name);
}
}
*/
}

0 comments on commit 68e07a7

Please sign in to comment.