public void RaiseCurrentSongFinishedAtIntantiate()
        {
            PlayerEventCatcher catcher = new PlayerEventCatcher();

            new PlayException();

            Assert.IsTrue(catcher.SongFinishedInvoked);
        }
        public void DoNothingIfThereIsTheEndOfPlayListOnNextSongDemand()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            mockPlayList.Setup(pl => pl.IsFinished).Returns(true);

            ViewModel.NextSongCommand.Execute(null);

            Assert.IsFalse(eventCatcher.PlaySongInvoked);
        }
        public void DoNothingIfParameterIsNull()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            SongListViewModel viewModel = new SongListViewModel();

            viewModel.AddSongsToPlayListCommand.Execute(null);

            Assert.IsFalse(eventCatcher.AddToPlayListInvoked);
        }
        public void ClearPlayListAndRaiseStopEvent()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            ViewModel.PlayerState = State.Play;

            ViewModel.ClearPlayListCommand.Execute(null);

            Assert.IsTrue(eventCatcher.StopSongInvoked);
            Assert.AreEqual(State.Stop, ViewModel.PlayerState);
            mockPlayList.Verify(pl => pl.Clear(), Times.Once());
        }
        public void RaiseAddToPlayListEvent()
        {
            Song expectedSong = Create.Song();
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            SongListViewModel viewModel = new SongListViewModel();

            viewModel.AddOneSongToPlayListCommand.Execute(expectedSong);

            Assert.IsTrue(eventCatcher.AddToPlayListInvoked);
            Assert.AreEqual(1, eventCatcher.AddToPlayListSong.Count);
            CollectionAssert.Contains(eventCatcher.AddToPlayListSong, expectedSong);
        }
        public void ClearPlayerIfThereIsTheEndOfPlayListOnSongFinished()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            ViewModel.PlayerState = State.Play;
            mockPlayList.Setup(pl => pl.IsFinished).Returns(true);

            PlayerObserver.NotifyCurrentSongFinished();

            Assert.IsFalse(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(State.Stop, ViewModel.PlayerState);
            Assert.IsTrue(eventCatcher.StopSongInvoked);
            mockPlayList.Verify(pl => pl.ResetAllSongs(), Times.Once());
        }
        public void DoNothingOnPauseCommandIfPlayerIsNotPlaying()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();

            ViewModel.PlayerState = State.Pause;
            ViewModel.PauseSongCommand.Execute(null);

            Assert.IsFalse(eventCatcher.PauseSongInvoked);
            Assert.AreEqual(State.Pause, ViewModel.PlayerState);

            ViewModel.PlayerState = State.Stop;
            ViewModel.PauseSongCommand.Execute(null);

            Assert.IsFalse(eventCatcher.PauseSongInvoked);
            Assert.AreEqual(State.Stop, ViewModel.PlayerState);
        }
        public void RaiseAddToPlayListEventWithSeveralSong()
        {
            Song expectedSong1 = Create.Song();
            Song expectedSong2 = Create.Song();
            ObservableCollection<Song> expectedSongs = new ObservableCollection<Song>(){expectedSong1, expectedSong2};

            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            SongListViewModel viewModel = new SongListViewModel();

            viewModel.AddSongsToPlayListCommand.Execute(expectedSongs);

            Assert.IsTrue(eventCatcher.AddToPlayListInvoked);
            Assert.AreEqual(2, eventCatcher.AddToPlayListSong.Count);
            CollectionAssert.Contains(eventCatcher.AddToPlayListSong, expectedSong1);
            CollectionAssert.Contains(eventCatcher.AddToPlayListSong, expectedSong1);
        }
        public void DoNotPlayIfPlayListIsEmpty()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            mockPlayList.Setup(pl => pl.IsEmpty).Returns(true);

            ViewModel.PlaySongCommand.Execute(null);

            Assert.IsFalse(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(State.Stop, ViewModel.PlayerState);
        }
        public void IfPlayListIsTheBeginningAndRepeatIsActivatedPlayTheLastSong()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            SongToPlay song = new SongToPlay();
            ViewModel.PlayerState = State.Play;
            ViewModel.Repeat = true;
            mockPlayList.Setup(pl => pl.PlayingTheFirst).Returns(true);
            mockPlayList.Setup(pl => pl.GetLast()).Returns(song);

            ViewModel.PreviousSongCommand.Execute(null);

            mockPlayList.Verify(pl => pl.ResetAllSongs(), Times.Once());
            mockPlayList.Verify(pl => pl.GetLast(), Times.Once());
            Assert.IsTrue(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(song.Song, eventCatcher.SongToPlay);
            Assert.AreEqual(State.Play, ViewModel.PlayerState);
        }
        public void PlayASong()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            SongToPlay song = new SongToPlay {Song = Create.Song()};

            ViewModel.PlaySongCommand.Execute(song);

            Assert.IsTrue(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(song.Song, eventCatcher.SongToPlay);
            Assert.AreEqual(State.Play, ViewModel.PlayerState);
        }
        public void RaiseNewSongFinishedEventWhenASongIsFinishedAndCleanAllValue()
        {
            PlayerEventCatcher catcher = new PlayerEventCatcher();
            PlayerViewModel viewModel = new PlayerViewModel
                                            {
                                                CurrentSong = Create.Song(),
                                                ElapsedTime = "0",
                                                PurcentagePlayed = 0,
                                                TotalTime = "0"
                                            };

            MockMusicPlayer.Raise(mp => mp.SongFinished += null);

            Assert.IsTrue(catcher.SongFinishedInvoked);
            Assert.IsNull(viewModel.ElapsedTime);
            Assert.IsNull(viewModel.TotalTime);
            Assert.IsNull(viewModel.CurrentSong);
            Assert.AreEqual(0, viewModel.PurcentagePlayed);
        }
        public void PlayNextSongOfPlayList()
        {
            SongToPlay song = new SongToPlay {Song = Create.Song()};
            mockPlayList.Setup(pl => pl.GetNextSong()).Returns(song);
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();

            ViewModel.NextSongCommand.Execute(null);

            mockPlayList.Verify(pl => pl.GetNextSong(), Times.Once());
            Assert.IsTrue(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(song.Song, eventCatcher.SongToPlay);
        }
        public void PlayNextSongWhenTheCurrentIsFinished()
        {
            SongToPlay song = new SongToPlay {Song = Create.Song()};
            mockPlayList.Setup(pl => pl.GetNextSong()).Returns(song);
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();

            PlayerObserver.NotifyCurrentSongFinished();

            mockPlayList.Verify(pl => pl.GetNextSong(), Times.Once());
            Assert.IsTrue(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(song.Song, eventCatcher.SongToPlay);
        }
        public void IfPlayListIsFinishedAndRepeatIsActivatedPlayTheFirstSong()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            SongToPlay song = new SongToPlay();
            ViewModel.PlayerState = State.Play;
            ViewModel.Repeat = true;
            mockPlayList.Setup(pl => pl.IsFinished).Returns(true);
            mockPlayList.Setup(pl => pl.GetFirst()).Returns(song);

            PlayerObserver.NotifyCurrentSongFinished();

            mockPlayList.Verify(pl => pl.ResetAllSongs(), Times.Once());
            mockPlayList.Verify(pl => pl.GetFirst(), Times.Once());
            Assert.IsTrue(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(song.Song, eventCatcher.SongToPlay);
            Assert.AreEqual(State.Play, ViewModel.PlayerState);
        }
        public void RaiseResumeDemandEvent()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            ViewModel.PlayerState = State.Pause;

            ViewModel.ResumeSongCommand.Execute(null);

            Assert.IsTrue(eventCatcher.ResumeSongInvoked);
            Assert.AreEqual(State.Play, ViewModel.PlayerState);
        }
        public void PlayTheFirstSongOfPlayListIfParameterIsNull()
        {
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();
            SongToPlay song = new SongToPlay {Song = Create.Song()};
            mockPlayList.Setup(pl => pl.GetFirst()).Returns(song);

            ViewModel.PlaySongCommand.Execute(null);

            Assert.IsTrue(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(song.Song, eventCatcher.SongToPlay);
            Assert.AreEqual(State.Play, ViewModel.PlayerState);
        }
        public void PlayPreviousSong()
        {
            SongToPlay song1 = new SongToPlay {Song = Create.Song()};
            mockPlayList.Setup(pl => pl.GetPreviousSong()).Returns(song1);
            PlayerEventCatcher eventCatcher = new PlayerEventCatcher();

            ViewModel.PreviousSongCommand.Execute(null);

            mockPlayList.Verify();
            Assert.IsTrue(eventCatcher.PlaySongInvoked);
            Assert.AreEqual(song1.Song, eventCatcher.SongToPlay);
        }