예제 #1
0
        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.");
        }
        public void Test()
        {
            var song1 = "song1";
            var song2 = "song2";
            var song3 = "song3";
            var song4 = "song4";

            _songs = new MusicInfo[] {
                    new MusicInfo() { FullPath = song1 },
                    new MusicInfo() { FullPath = song2 },
                    new MusicInfo() { FullPath = song3 },
                    new MusicInfo() { FullPath = song4 }
                };

            var library = new MemoryLibraryRepository();
            library.ClearLibrary();
            library.AddMusicToLibrary(_songs);

            var loopingWatcher = new RandomSongPlaylistWatcher(2);
            _playlist = new Playlist(loopingWatcher);
            _dummyAudio = new DummyAudioInteractor();

            var player = new Player(_playlist, _dummyAudio, library);

            loopingWatcher.AttachToPlaylist(_playlist, library);

            player.MaxPlayCount = 3;
            player.Play();
        }
예제 #3
0
        public void MemoryLibraryShouldBeSingleton()
        {
            var music = new MusicInfo()
            {
                Album = "Test Album",
                Artist = "Test Artist",
                FullPath = "Test Path",
                Title = "Test Title"
            };

            var repository = new MemoryLibraryRepository();
            repository.ClearLibrary();

            repository.AddMusicToLibrary(new MusicInfo[] { music });

            List<MusicInfo> result = repository.GetAllMusic();

            Assert.IsNotNull(result, "The result must not be null.");
            Assert.AreEqual(1, result.Count, "There must only be one song.");

            var repository2 = new MemoryLibraryRepository();

            music.FullPath += 2;

            repository2.AddMusicToLibrary(new MusicInfo[] { music });
            result = repository2.GetAllMusic();

            Assert.AreEqual(2, result.Count, "There must two songs.");
        }
예제 #4
0
        public void AddMusicToLibrary()
        {
            var music = new MusicInfo()
            {
                Album = "Test Album",
                Artist = "Test Artist",
                FullPath = "Test Path",
                Title = "Test Title"
            };

            var pubnubStub = MockRepository.GenerateStub<IRealTimeMessaging>();
            pubnubStub.Stub(X => X.SendSongsAdded(null));

            var repository = new MemoryLibraryRepository(pubnubStub);
            repository.ClearLibrary();

            repository.AddMusicToLibrary(new MusicInfo[] {music});

            List<MusicInfo> result = repository.GetAllMusic();

            Assert.IsNotNull(result, "The result must not be null.");
            Assert.AreEqual(1, result.Count, "There must only be one song.");
            Assert.AreEqual(music.Album, result[0].Album, "The result must be for the correct album.");
            Assert.AreEqual(music.Artist, result[0].Artist, "The artist must be correct.");
            Assert.AreEqual(music.Title, result[0].Title, "The title must be correct.");
            Assert.AreEqual(music.FullPath, result[0].FullPath, "The full path must be correct.");

            pubnubStub.AssertWasCalled(X => X.SendSongsAdded(null), Y => Y.IgnoreArguments());
        }
예제 #5
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.");
        }