public void ForAdviseSet_ForExplicitAdviseSet_FillsTitleCorrectly() { // Arrange var adviseSet = new AdviseSetModel { Id = new ItemId("Advise Set Id"), Name = "Some Advise Set" }; var disc1 = new DiscModel { Id = new ItemId("1"), AdviseSetInfo = new AdviseSetInfo(adviseSet, 1), Title = "Disc 1" }; var disc2 = new DiscModel { Id = new ItemId("2"), AdviseSetInfo = new AdviseSetInfo(adviseSet, 2), Title = "Disc 2" }; var folder = new FolderModel { Name = "Some Artist" }; folder.AddDiscs(disc1, disc2); var adviseSetContent = new AdviseSetContent("AdviseSetContent Id"); adviseSetContent.AddDisc(disc1); adviseSetContent.AddDisc(disc2); // Act var target = AdvisedPlaylist.ForAdviseSet(adviseSetContent); // Assert target.Title.Should().Be("Some Advise Set"); }
public static AdviseSetContent ToAdviseSet(this DiscModel disc) { var adviseSet = new AdviseSetContent($"Disc: {disc.Id}"); adviseSet.AddDisc(disc); return(adviseSet); }
public int GetPlaybacksPassed(AdviseSetContent adviseSetContent) { if (adviseSetsPlaybacksInfo.TryGetValue(adviseSetContent.Id, out var playbacksPassed)) { return(playbacksPassed); } throw new InvalidOperationException($"The number of passed playbacks for advise set '{adviseSetContent.Id}' is unknown"); }
public double CalculateAdviseSetRank(AdviseSetContent adviseSet, PlaybacksInfo playbacksInfo) { if (adviseSet.LastPlaybackTime == null) { return(MaxRank); } var playbacksPassed = playbacksInfo.GetPlaybacksPassed(adviseSet); return(GetFactorForAverageRating(GetRating(adviseSet)) * GetFactorForPlaybackAge(playbacksPassed)); }
public static AdviseGroupContent ToAdviseGroup(this AdviseSetContent adviseSetContent) { var adviseGroup = new AdviseGroupContent(adviseSetContent.Id, isFavorite: false); foreach (var disc in adviseSetContent.Discs) { adviseGroup.AddDisc(disc); } return(adviseGroup); }
private static double GetRating(AdviseSetContent adviseSetContent) { // Below check was added just in case. // It should not happen that advise set contains both active and deleted discs. // If all discs in advise set are deleted, then the whole advise set is considered as deleted and should be filtered by the caller. if (adviseSetContent.Discs.Any(x => x.IsDeleted)) { throw new InvalidOperationException("Advise set contains both active and deleted discs"); } return(adviseSetContent.Discs .Select(x => x.GetRating()) .Average()); }
public void ForAdviseSet_IfAdviseSetContainsMultipleDiscs_OrdersPlaylistSongsCorrectly() { // Arrange var adviseSet = new AdviseSetModel { Id = new ItemId("Advise Set Id"), Name = "Some Advise Set" }; var disc1 = new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1", AdviseSetInfo = new AdviseSetInfo(adviseSet, 2), }; var song11 = new SongModel { Id = new ItemId("Song 1.1") }; var song12 = new SongModel { Id = new ItemId("Song 1.2") }; disc1.AddSongs(song11, song12); var disc2 = new DiscModel { Id = new ItemId("2"), TreeTitle = "Disc 2", AdviseSetInfo = new AdviseSetInfo(adviseSet, 1), }; var song2 = new SongModel { Id = new ItemId("Song 2.1") }; disc2.AddSongs(song2); var disc3 = new DiscModel { Id = new ItemId("3"), TreeTitle = "Disc 3", AdviseSetInfo = new AdviseSetInfo(adviseSet, 3), }; var song3 = new SongModel { Id = new ItemId("Song 3.1") }; disc3.AddSongs(song3); var adviseSetContent = new AdviseSetContent("AdviseSetContent Id"); adviseSetContent.AddDisc(disc1); adviseSetContent.AddDisc(disc2); adviseSetContent.AddDisc(disc3); // Act var target = AdvisedPlaylist.ForAdviseSet(adviseSetContent); // Assert var expectedSongs = new[] { song2, song11, song12, song3, }; target.Songs.Should().BeEquivalentTo(expectedSongs, x => x.WithStrictOrdering()); }