Exemple #1
0
            public async Task WhileSongIsPlayingStopsCurrentSong()
            {
                using (Library library = new LibraryBuilder().WithPlaylist().Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.AddSongsToPlaylist(Helpers.SetupSongMocks(1), token);

                    var awaiter = library.PlaybackState.FirstAsync(x => x == AudioPlayerState.Finished).PublishLast();
                    awaiter.Connect();

                    await library.PlaySongAsync(0, token);

                    library.RemoveFromPlaylist(new[] { 0 }, token);

                    await awaiter.Timeout(TimeSpan.FromSeconds(5));
                }
            }
Exemple #2
0
            public async Task PreventsNextSongFromPlaying()
            {
                var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>();

                using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    int played = 0;

                    audioPlayerCallback.PlayAsync().Returns(Task.Run(() =>
                    {
                        if (played == 0)
                        {
                            library.AddAndSwitchToPlaylist("Playlist2", token);
                        }

                        played++;
                    }));

                    library.AddSongsToPlaylist(Helpers.SetupSongMocks(2), token);

                    await library.PlaySongAsync(0, token);

                    Assert.Equal(1, played);
                }
            }
Exemple #3
0
            public async Task SongPreparationCanTimeout()
            {
                await new TestScheduler().With(async sched =>
                {
                    var song = Substitute.For<Song>("C://", TimeSpan.Zero);
                    song.PrepareAsync(Arg.Any<YoutubeStreamingQuality>()).Returns(Observable.Return(Unit.Default)
                        .Delay(Library.PreparationTimeout + TimeSpan.FromSeconds(1), sched).ToTask());

                    var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>();

                    using (Library library = new LibraryBuilder().WithPlaylist().Build())
                    {
                        Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                        library.AddSongsToPlaylist(new[] { song }, token);

                        Task play = library.PlaySongAsync(0, token);

                        sched.AdvanceByMs((Library.PreparationTimeout + TimeSpan.FromSeconds(2)).TotalMilliseconds);

                        await play;
                    }

                    audioPlayerCallback.DidNotReceiveWithAnyArgs().LoadAsync(Arg.Any<Uri>());
                });
            }
Exemple #4
0
            public void BySongReferenceTest()
            {
                using (Library library = new LibraryBuilder().WithPlaylist().Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    Song[] songs = Helpers.SetupSongMocks(4);

                    library.AddSongsToPlaylist(songs, token);

                    library.RemoveFromPlaylist(new[] { songs[0], songs[2] }, token);

                    Song[] remaining = library.CurrentPlaylist.Select(entry => entry.Song).ToArray();

                    Assert.Equal(songs[1], remaining[0]);
                    Assert.Equal(songs[3], remaining[1]);
                }
            }
Exemple #5
0
            public void ThrowsAccessExceptionWithGuestTokenAndMultipleSongs()
            {
                var songs = new[]
                {
                    Substitute.For<Song>("TestPath", TimeSpan.Zero),
                    Substitute.For<Song>("TestPath", TimeSpan.Zero)
                };

                using (Library library = new LibraryBuilder().WithPlaylist().Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.LocalAccessControl.SetLocalPassword(token, "Password");
                    library.LocalAccessControl.DowngradeLocalAccess(token);

                    Assert.Throws<AccessException>(() => library.AddSongsToPlaylist(songs, token));
                }
            }
Exemple #6
0
            public async Task PlaysNextSongAutomatically()
            {
                using (Library library = new LibraryBuilder().WithPlaylist().Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.AddSongsToPlaylist(Helpers.SetupSongMocks(2), token);

                    var conn = library.PlaybackState.Where(x => x == AudioPlayerState.Playing)
                        .Take(2)
                        .PublishLast();
                    conn.Connect();

                    await library.PlaySongAsync(0, token);

                    await conn.Timeout(TimeSpan.FromSeconds(5));
                }
            }
            public async Task SetsSongIsCorruptedToTrueIfPlayIsFailing()
            {
                var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>();
                audioPlayerCallback.PlayAsync().Returns(Observable.Throw<Unit>(new PlaybackException()).ToTask());

                using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build())
                {
                    Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken();

                    Song song = Helpers.SetupSongMock();

                    library.AddSongsToPlaylist(new[] { song }, accessToken);

                    await library.PlaySongAsync(0, accessToken);

                    Assert.True(song.IsCorrupted);
                }
            }
            public void ThrowsAccessExceptionIfAccessModeIsPartyAndLockPlaylistRemovalIsTrue()
            {
                var songMock = Substitute.For<Song>("TestPath", TimeSpan.Zero);

                var settings = new CoreSettings
                {
                    LockPlaylist = true
                };

                using (Library library = new LibraryBuilder().WithPlaylist().WithSettings(settings).Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.AddSongsToPlaylist(new[] { songMock }, token);

                    library.LocalAccessControl.SetLocalPassword(token, "Password");
                    library.LocalAccessControl.DowngradeLocalAccess(token);

                    Assert.Throws<AccessException>(() => library.RemoveFromPlaylist(new[] { 0 }, token));
                }
            }
            public async Task ResetsSongIsCorruptedIfPlayingIsWorking()
            {
                var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>();
                audioPlayerCallback.LoadAsync(Arg.Any<Uri>()).Returns(Observable.Throw<Unit>(new SongLoadException()).ToTask());

                using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build())
                {
                    Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken();

                    Song song = Helpers.SetupSongMock();

                    library.AddSongsToPlaylist(new[] { song }, accessToken);

                    await library.PlaySongAsync(0, accessToken);

                    audioPlayerCallback.LoadAsync(Arg.Any<Uri>()).Returns(_ => Task.Delay(0));

                    await library.PlaySongAsync(0, accessToken);

                    Assert.False(song.IsCorrupted);
                }
            }
            public async Task CallsAudioPlayerPause()
            {
                var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>();

                using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    Song song = Helpers.SetupSongMock();

                    library.AddSongsToPlaylist(new[] { song }, token);

                    await library.PlaySongAsync(0, token);

                    await library.PauseSongAsync(token);
                }

                audioPlayerCallback.Received(1).PauseAsync();
            }
            public void ThrowsInvalidOperationExceptionIfGuestSystemIsDisabled()
            {
                var settings = new CoreSettings
                {
                    EnableGuestSystem = false
                };

                using (var library = new LibraryBuilder().WithPlaylist().WithSettings(settings).Build())
                {
                    Guid accessToken = library.RemoteAccessControl.RegisterRemoteAccessToken(Guid.NewGuid());

                    library.Initialize();
                    library.AddSongsToPlaylist(new[] { Helpers.SetupSongMock() }, accessToken);

                    Assert.Throws<InvalidOperationException>(() => library.VoteForPlaylistEntry(0, accessToken));
                }
            }
            public void IgnoresAccessPermission()
            {
                var settings = new CoreSettings
                {
                    EnableGuestSystem = true,
                    LockRemoteControl = true,
                    RemoteControlPassword = "******",
                    MaxVoteCount = 2,
                };

                using (var library = new LibraryBuilder().WithPlaylist().WithSettings(settings).Build())
                {
                    Guid localToken = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.AddSongsToPlaylist(new[] { Helpers.SetupSongMock() }, localToken);
                    library.AddSongsToPlaylist(new[] { Helpers.SetupSongMock() }, localToken);

                    Guid remoteToken = library.RemoteAccessControl.RegisterRemoteAccessToken(Guid.NewGuid());

                    // Guests can vote
                    library.VoteForPlaylistEntry(0, remoteToken);

                    library.RemoteAccessControl.UpgradeRemoteAccess(remoteToken, "Password");

                    // Admins can vote
                    library.VoteForPlaylistEntry(1, remoteToken);
                }
            }
            public async Task SetsCurrentSongIndexIfChangingToOtherPlaylistAndPlayingFirstSong()
            {
                using (Library library = new LibraryBuilder().WithPlaylist().Build())
                {
                    var coll = library.WhenAnyValue(x => x.CurrentPlaylist.CurrentSongIndex).CreateCollection();

                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.AddSongsToPlaylist(new[] { Helpers.SetupSongMock() }, token);

                    await library.PlaySongAsync(0, token);

                    library.AddPlaylist("Playlist 2", token);
                    library.SwitchToPlaylist(library.Playlists.Last(), token);
                    library.AddSongsToPlaylist(new[] { Helpers.SetupSongMock() }, token);

                    await library.PlaySongAsync(0, token);

                    Assert.Equal(new int?[] { null, 0, null, null, 0, null }, coll);
                }
            }