コード例 #1
0
ファイル: PlayerTests.cs プロジェクト: awlawl/Maestro
        public void PlayerCanBeGivenANewPlaylist()
        {
            var library    = new MemoryLibraryRepository();
            var playlist   = new Playlist();
            var dummyAudio = new DummyAudioInteractor();
            var player     = new Player(playlist, dummyAudio, null);

            var song = "song1";

            library.ClearLibrary();
            library.AddMusicToLibrary(new MusicInfo[] { new MusicInfo()
                                                        {
                                                            FullPath = song
                                                        } });

            playlist.AddRange(library.GetAllMusic());

            player.Play();

            Assert.AreEqual(song, playlist.CurrentSong.FullPath, "The last song played must be the only one in the library.");

            var song2 = "song 2";

            library.ClearLibrary();
            library.AddMusicToLibrary(new MusicInfo[] { new MusicInfo()
                                                        {
                                                            FullPath = song2
                                                        } });

            playlist.AddRange(library.GetAllMusic());

            player.PlayCount = 0;
            player.Play();

            Assert.AreEqual(song, playlist.PreviousSong.FullPath, "The previous played must be new song in the library.");
            Assert.AreEqual(song2, playlist.CurrentSong.FullPath, "The current played must be new song in the library.");
        }
コード例 #2
0
        public void ShouldSendMessageWhenSongIsPlayed()
        {
            var library = new MemoryLibraryRepository();

            library.ClearLibrary();

            var song = new MusicInfo()
            {
                Album    = "Test album",
                FullPath = "Test song",
                Artist   = "Test artist",
                Title    = "Test title"
            };

            library.AddMusicToLibrary(
                new MusicInfo[] {
                song
            });

            var pubnubStub = MockRepository.GenerateStub <IRealTimeMessaging>();

            pubnubStub.Stub(X => X.SendNowPlaying(null)).IgnoreArguments();

            var messagingWatcher = new MessagingPlaylistWatcher();

            messagingWatcher.AssignMessaging(pubnubStub);
            var loopingWatcher = new LoopingPlaylistWatcher();
            var playlist       = new Playlist(new IPlaylistWatcher[] { loopingWatcher, messagingWatcher });
            var dummyAudio     = new DummyAudioInteractor();

            var player = new Player(playlist, dummyAudio, library);

            loopingWatcher.AttachToPlaylist(playlist, library);
            messagingWatcher.AttachToPlaylist(playlist, library);

            playlist.AddRange(library.GetAllMusic());

            player.MaxPlayCount = 1;
            player.Play();

            var args = pubnubStub.GetArgumentsForCallsMadeOn(X => X.SendNowPlaying(null), Y => Y.IgnoreArguments());

            Assert.AreEqual(1, args.Count, "There must be one message.");

            var nowPlayingSong = (MusicInfo)args[0][0];

            Assert.AreEqual(song.Album, nowPlayingSong.Album, "The album must be correct.");
            Assert.AreEqual(song.Title, nowPlayingSong.Title, "The title must be correct.");
        }
コード例 #3
0
        public void Loop()
        {
            var song1 = "song1";
            var song2 = "song2";

            var library = new MemoryLibraryRepository();

            library.ClearLibrary();
            library.AddMusicToLibrary(
                new MusicInfo[] {
                new MusicInfo()
                {
                    FullPath = song1
                },
                new MusicInfo()
                {
                    FullPath = song2
                }
            });

            var loopingWatcher = new LoopingPlaylistWatcher();
            var playlist       = new Playlist(loopingWatcher);
            var dummyAudio     = new DummyAudioInteractor();

            var player = new Player(playlist, dummyAudio, library);

            loopingWatcher.AttachToPlaylist(playlist, library);

            playlist.AddRange(library.GetAllMusic());

            player.MaxPlayCount = 3;
            player.Play();

            Assert.AreEqual(3, dummyAudio.PlayHistory.Count, "There must be three songs in the history.");
            Assert.AreEqual(song1, dummyAudio.PlayHistory[0], "The first song must play first.");
            Assert.AreEqual(song2, dummyAudio.PlayHistory[1], "The second song must play second.");
            Assert.AreEqual(song1, dummyAudio.PlayHistory[2], "The first song must play third.");

            Assert.AreEqual(2, playlist.RemainingSongs, "After playing three songs there must still be 2 songs in the playlist.");
        }