コード例 #1
0
        public void ForAdviseSetFromFavoriteAdviseGroup_FillsTitleCorrectly()
        {
            // Arrange

            var adviseSetContent = new DiscModel
            {
                Id    = new ItemId("1"),
                Title = "Some Disc",
            }
            .AddSongs(new SongModel {
                Id = new ItemId("12345"), Artist = new ArtistModel {
                    Name = "Another Artist"
                }
            })
            .AddToFolder(new FolderModel {
                Name = "Some Artist"
            })
            .ToAdviseSet();

            // Act

            var target = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSetContent);

            // Assert

            target.Title.Should().Be("*** Some Artist / Some Disc");
        }
コード例 #2
0
        public void ForAdviseSetFromFavoriteAdviseGroup_IfAdviseSetContainsDeletedSongs_FillsPlaylistOnlyWithActiveSongs()
        {
            // Arrange

            var deletedSong = new SongModel {
                Id = new ItemId("1"), DeleteDate = new DateTime(2017, 10, 06)
            };
            var activeSong1 = new SongModel {
                Id = new ItemId("2")
            };
            var activeSong2 = new SongModel {
                Id = new ItemId("3")
            };

            var adviseSetContent = new DiscModel
            {
                Id = new ItemId("1"),
            }
            .AddSongs(deletedSong, activeSong1, activeSong2)
            .AddToFolder(new FolderModel {
                Name = "Some Artist"
            })
            .ToAdviseSet();

            // Act

            var target = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSetContent);

            // Assert

            target.Songs.Should().BeEquivalentTo(new[] { activeSong1, activeSong2 }, x => x.WithStrictOrdering());
        }
コード例 #3
0
        public async Task Advise_IfAdvisesForFavoriteAdviseGroupsProvided_AdvisesAdviseSetFromFavoriteAdviseGroupsAtConfiguredIntervals()
        {
            // Arrange

            var settings = new AdviserSettings
            {
                PlaybacksBetweenFavoriteAdviseGroups = 10,
            };

            var favoriteAdviseGroupAdvise1 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(CreateTestAdviseSet(101));
            var favoriteAdviseGroupAdvise2 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(CreateTestAdviseSet(102));

            var rankBasedAdviserStub = new Mock <IPlaylistAdviser>();

            rankBasedAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Enumerable.Range(0, 100).Select(i => AdvisedPlaylist.ForAdviseSet(CreateTestAdviseSet(i))).ToList());

            var favoriteAdviseGroupsAdviserStub = new Mock <IPlaylistAdviser>();

            favoriteAdviseGroupsAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new[] { favoriteAdviseGroupAdvise1, favoriteAdviseGroupAdvise2 });

            var target = new CompositePlaylistAdviser(StubDiscGrouper(), rankBasedAdviserStub.Object, StubEmptyPlaylistAdviser(),
                                                      favoriteAdviseGroupsAdviserStub.Object, Mock.Of <ISessionDataService>(), Options.Create(settings));

            // Act

            var advises = (await target.Advise(Enumerable.Empty <DiscModel>(), 30, CancellationToken.None)).ToList();

            // Assert

            advises.Where(x => x.AdvisedPlaylistType == AdvisedPlaylistType.AdviseSetFromFavoriteAdviseGroup).Should().HaveCount(2);
            advises[0].Should().BeSameAs(favoriteAdviseGroupAdvise1);
            advises[10].Should().BeSameAs(favoriteAdviseGroupAdvise2);
        }
コード例 #4
0
        public async Task Advise_MixesDifferentAdviseTypesCorrectly()
        {
            // Arrange

            var highlyRatedSongsAdvise1 = AdvisedPlaylist.ForHighlyRatedSongs(Enumerable.Empty <SongModel>());
            var highlyRatedSongsAdvise2 = AdvisedPlaylist.ForHighlyRatedSongs(Enumerable.Empty <SongModel>());

            var favoriteAdviseGroupAdvise1 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(CreateTestAdviseSet(101));
            var favoriteAdviseGroupAdvise2 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(CreateTestAdviseSet(102));

            var rankedBasedAdvises = Enumerable.Range(1, 10).Select(i => AdvisedPlaylist.ForAdviseSet(CreateTestAdviseSet(i))).ToList();

            var rankBasedAdviserStub = new Mock <IPlaylistAdviser>();

            rankBasedAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>())).ReturnsAsync(rankedBasedAdvises);

            var highlyRatedSongsAdviserStub = new Mock <IPlaylistAdviser>();

            highlyRatedSongsAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new[] { highlyRatedSongsAdvise1, highlyRatedSongsAdvise2 });

            var favoriteAdviseGroupsAdviserStub = new Mock <IPlaylistAdviser>();

            favoriteAdviseGroupsAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new[] { favoriteAdviseGroupAdvise1, favoriteAdviseGroupAdvise2 });

            var settings = new AdviserSettings
            {
                PlaybacksBetweenFavoriteAdviseGroups = 5,
                HighlyRatedSongsAdviser = new HighlyRatedSongsAdviserSettings
                {
                    PlaybacksBetweenHighlyRatedSongs = 10,
                },
            };

            var target = new CompositePlaylistAdviser(StubDiscGrouper(), rankBasedAdviserStub.Object, highlyRatedSongsAdviserStub.Object,
                                                      favoriteAdviseGroupsAdviserStub.Object, Mock.Of <ISessionDataService>(), Options.Create(settings));

            // Act

            var advises = (await target.Advise(Enumerable.Empty <DiscModel>(), 30, CancellationToken.None)).ToList();

            // Assert

            var expectedAdvises = new[]
            {
                highlyRatedSongsAdvise1,
                favoriteAdviseGroupAdvise1,
                rankedBasedAdvises[0], rankedBasedAdvises[1], rankedBasedAdvises[2], rankedBasedAdvises[3],
                favoriteAdviseGroupAdvise2,
                rankedBasedAdvises[4], rankedBasedAdvises[5], rankedBasedAdvises[6],
                highlyRatedSongsAdvise2,
                rankedBasedAdvises[7], rankedBasedAdvises[8], rankedBasedAdvises[9],
            };

            advises.Should().BeEquivalentTo(expectedAdvises);
        }
コード例 #5
0
        public async Task Advise_IfAllAdviseSetsAreActive_AdvisesSetsInCorrectOrder()
        {
            // Arrange

            // Last playback time for each advise group:
            //
            //     adviseGroup1: 3, 2
            //     adviseGroup2: null
            //     adviseGroup3: null, 1
            //
            // Expected order (order within advise group is provided by inner adviser and is not changed):
            //
            //     adviseSet21, adviseSet11, adviseSet31
            var adviseSet11 = CreateTestAdviseSet("11", new[] { CreateTestSong(1, new DateTime(2018, 08, 17)) });
            var adviseSet12 = CreateTestAdviseSet("12", new[] { CreateTestSong(2, new DateTime(2018, 08, 18)) });
            var adviseSet21 = CreateTestAdviseSet("21", new[] { CreateTestSong(3) });
            var adviseSet31 = CreateTestAdviseSet("31", new[] { CreateTestSong(4) });
            var adviseSet32 = CreateTestAdviseSet("32", new[] { CreateTestSong(5, new DateTime(2018, 08, 19)) });

            var adviseGroups = new[]
            {
                CreateAdviseGroup("1", isFavorite: true, adviseSet11, adviseSet12),
                CreateAdviseGroup("2", isFavorite: true, adviseSet21),
                CreateAdviseGroup("3", isFavorite: true, adviseSet31, adviseSet32),
            };

            var playbacksInfo = new PlaybacksInfo(adviseGroups);

            var rankBasedAdviserStub = new Mock <IPlaylistAdviser>();

            rankBasedAdviserStub.Setup(x => x.Advise(adviseGroups, playbacksInfo, It.IsAny <CancellationToken>())).ReturnsAsync(CreatedAdvisedPlaylists(adviseGroups));

            var mocker = new AutoMocker();

            mocker.Use(rankBasedAdviserStub);

            var target = mocker.CreateInstance <FavoriteAdviseGroupsAdviser>();

            // Act

            var advisedPlaylists = await target.Advise(adviseGroups, playbacksInfo, CancellationToken.None);

            // Assert

            var expectedPlaylists = new[]
            {
                AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSet21),
                AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSet11),
                AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSet31),
            };

            advisedPlaylists.Should().BeEquivalentTo(expectedPlaylists, x => x.WithStrictOrdering());
        }
コード例 #6
0
        public async Task Advise_SkipsDuplicatedAdviseSetsBetweenAdvisers()
        {
            // Arrange

            var settings = new AdviserSettings
            {
                PlaybacksBetweenFavoriteAdviseGroups = 10,
            };

            var adviseSet1 = CreateTestAdviseSet(101);
            var adviseSet2 = CreateTestAdviseSet(102);

            var favoriteAdviseGroupAdvise1 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSet1);
            var favoriteAdviseGroupAdvise2 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSet2);

            var rankedBasedAdvises = Enumerable.Range(0, 10).Select(i => AdvisedPlaylist.ForAdviseSet(CreateTestAdviseSet(i)))
                                     .Concat(new[] { AdvisedPlaylist.ForAdviseSet(adviseSet1) })
                                     .Concat(Enumerable.Range(10, 20).Select(i => AdvisedPlaylist.ForAdviseSet(CreateTestAdviseSet(i))))
                                     .Concat(new[] { AdvisedPlaylist.ForAdviseSet(adviseSet2) })
                                     .ToList();

            var rankBasedAdviserStub = new Mock <IPlaylistAdviser>();

            rankBasedAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>())).ReturnsAsync(rankedBasedAdvises);

            var favoriteAdviseGroupsAdviserStub = new Mock <IPlaylistAdviser>();

            favoriteAdviseGroupsAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new[] { favoriteAdviseGroupAdvise1, favoriteAdviseGroupAdvise2 });

            var target = new CompositePlaylistAdviser(StubDiscGrouper(), rankBasedAdviserStub.Object, StubEmptyPlaylistAdviser(),
                                                      favoriteAdviseGroupsAdviserStub.Object, Mock.Of <ISessionDataService>(), Options.Create(settings));

            // Act

            var advises = (await target.Advise(Enumerable.Empty <DiscModel>(), 30, CancellationToken.None)).ToList();

            // Assert

            advises.Should().ContainSingle(a => a.AdviseSet == adviseSet1);
            advises.Should().ContainSingle(a => a.AdviseSet == adviseSet2);
        }
コード例 #7
0
        public void ForAdviseSetFromFavoriteAdviseGroup_FillsAdviseSetCorrectly()
        {
            // Arrange

            var adviseSetContent = new DiscModel {
                Id = new ItemId("1")
            }
            .AddToFolder(new FolderModel {
                Name = "Some Artist"
            })
            .ToAdviseSet();

            // Act

            var target = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSetContent);

            // Assert

            target.AdviseSet.Should().BeSameAs(adviseSetContent);
        }
コード例 #8
0
        public void RegisterPlayback_IfPlaybackAdviseIsForAdviseSetFromFavoriteAdviseGroup_SetsPlaybacksSinceFavoriteAdviseGroupToZero()
        {
            // Arrange

            var disc = new DiscModel {
                Id = new ItemId("1")
            }
            .AddToFolder(new FolderModel());

            var target = new PlaylistAdviserMemo(playbacksSinceHighlyRatedSongsPlaylist: 3, playbacksSinceFavoriteAdviseGroup: 5);

            // Act

            var newMemo = target.RegisterPlayback(AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(disc.ToAdviseSet()));

            // Assert

            var expectedMemo = new PlaylistAdviserMemo(playbacksSinceHighlyRatedSongsPlaylist: 4, playbacksSinceFavoriteAdviseGroup: 0);

            newMemo.Should().BeEquivalentTo(expectedMemo);
        }
コード例 #9
0
        public async Task Advise_IfPlaylistAdviserMemoIsLoaded_UsesPreviousPlaybacksSinceFavoriteAdviseGroup()
        {
            // Arrange

            var settings = new AdviserSettings
            {
                PlaybacksBetweenFavoriteAdviseGroups = 10,
            };

            var favoriteAdviseGroupAdvise1 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(CreateTestAdviseSet(101));
            var favoriteAdviseGroupAdvise2 = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(CreateTestAdviseSet(102));

            var rankBasedAdviserStub = new Mock <IPlaylistAdviser>();

            rankBasedAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Enumerable.Range(0, 100).Select(i => AdvisedPlaylist.ForAdviseSet(CreateTestAdviseSet(i))).ToList());

            var favoriteAdviseGroupsAdviserStub = new Mock <IPlaylistAdviser>();

            favoriteAdviseGroupsAdviserStub.Setup(x => x.Advise(It.IsAny <IEnumerable <AdviseGroupContent> >(), It.IsAny <PlaybacksInfo>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new[] { favoriteAdviseGroupAdvise1, favoriteAdviseGroupAdvise2 });

            var sessionDataServiceStub = new Mock <ISessionDataService>();

            sessionDataServiceStub.Setup(x => x.GetData <PlaylistAdviserMemo>("PlaylistAdviserData", CancellationToken.None))
            .ReturnsAsync(new PlaylistAdviserMemo(playbacksSinceHighlyRatedSongsPlaylist: 0, playbacksSinceFavoriteAdviseGroup: 2));

            var target = new CompositePlaylistAdviser(StubDiscGrouper(), rankBasedAdviserStub.Object, StubEmptyPlaylistAdviser(),
                                                      favoriteAdviseGroupsAdviserStub.Object, sessionDataServiceStub.Object, Options.Create(settings));

            // Act

            var advises = (await target.Advise(Enumerable.Empty <DiscModel>(), 30, CancellationToken.None)).ToList();

            // Assert

            advises.Where(x => x.AdvisedPlaylistType == AdvisedPlaylistType.AdviseSetFromFavoriteAdviseGroup).Should().HaveCount(2);
            advises[7].Should().BeSameAs(favoriteAdviseGroupAdvise1);
            advises[17].Should().BeSameAs(favoriteAdviseGroupAdvise2);
        }
コード例 #10
0
        public async Task Advise_AdvisesOnlySetsFromFavoriteAdviseGroups()
        {
            // Arrange

            var adviseSetFromFavoriteAdviseGroup    = CreateTestAdviseSet("1", new[] { CreateTestSong(1) });
            var adviseSetFromNonFavoriteAdviseGroup = CreateTestAdviseSet("2", new[] { CreateTestSong(2) });

            var adviseGroups = new[]
            {
                CreateAdviseGroup("1", isFavorite: false, adviseSetFromNonFavoriteAdviseGroup),
                CreateAdviseGroup("2", isFavorite: true, adviseSetFromFavoriteAdviseGroup),
            };

            var playbacksInfo = new PlaybacksInfo(adviseGroups);

            var rankBasedAdviserStub = new Mock <IPlaylistAdviser>();

            rankBasedAdviserStub.Setup(x => x.Advise(adviseGroups, playbacksInfo, It.IsAny <CancellationToken>()))
            .ReturnsAsync(CreatedAdvisedPlaylists(adviseGroups));

            var mocker = new AutoMocker();

            mocker.Use(rankBasedAdviserStub);

            var target = mocker.CreateInstance <FavoriteAdviseGroupsAdviser>();

            // Act

            var advisedPlaylists = await target.Advise(adviseGroups, playbacksInfo, CancellationToken.None);

            // Assert

            var expectedPlaylists = new[]
            {
                AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSetFromFavoriteAdviseGroup),
            };

            advisedPlaylists.Should().BeEquivalentTo(expectedPlaylists, x => x.WithStrictOrdering());
        }