public void SimpleStart() { string filename = "song1"; var music = new MusicInfo() { FullPath = filename}; var dummyPlaylistWatcher = new DummyPlaylistWatcher(); var playlist = new Playlist(dummyPlaylistWatcher); playlist.Enqueue(music); Assert.AreEqual(1, playlist.Count, "There must be one song in the playlist."); MusicInfo song = playlist.CurrentSong; playlist.CurrentSongIsStarting(); Assert.AreEqual(filename, song.FullPath, "The next song must be the one that was enqueued."); Assert.AreEqual(1, dummyPlaylistWatcher.PlayHistory.Count, "Only one song must have been played."); Assert.AreEqual(filename, dummyPlaylistWatcher.PlayHistory[0], "The song that played was "); }
public void AddMusicToLibrary(MusicInfo[] song) { _library.AddRange(song); if (_messaging != null) _messaging.SendSongsAdded(song); }
public void AddOrUpdateMusicInLibrary(MusicInfo song) { Log.Debug("Adding song to library: " + song.FullPath); var collection = MongoHelper.Current.GetCollection<MongoMusicInfo>("musicinfo"); //find any existing var existing = collection.FindAll() .Where(X => X.FullPath == song.FullPath) .ToArray(); //insert it again collection.Insert(song); if (existing.Length>0) { //delete the original ones foreach (var previousVersion in existing) { Log.Debug("This song was already in the library, deleting the old one: " + previousVersion.IdValue); collection.Remove(Query.EQ("_id", previousVersion.Id)); } } if (Messaging != null) Messaging.SendSongsAdded(new MusicInfo[] { song }); }
public void PlaylistsCanGoBack() { string filename1 = "song1"; string filename2 = "song1"; var music1 = new MusicInfo() { FullPath = filename1 }; var music2 = new MusicInfo() { FullPath = filename2 }; var dummyPlaylistWatcher = new DummyPlaylistWatcher(); var playlist = new Playlist(dummyPlaylistWatcher); playlist.Enqueue(music1); playlist.Enqueue(music2); Assert.AreEqual(2, playlist.Count, "There must be two songs in the playlist."); MusicInfo song = playlist.CurrentSong; Assert.AreEqual(filename1, song.FullPath, "The first item in the playlist must be correct."); playlist.MoveToNextSong(); MusicInfo nextSong = playlist.CurrentSong; Assert.AreEqual(filename2, nextSong.FullPath, "The second item in the playlist must be correct."); playlist.MoveBackOneSong(); Assert.AreEqual(filename1, playlist.CurrentSong.FullPath, "Going back one song should go back to the first one."); }
public void AddOrUpdateMusicInLibrary(MusicInfo song) { _library.Add(song); if (_messaging != null) _messaging.SendSongsAdded(new MusicInfo[] {song}); }
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()); }
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."); }
public void AddMusicToLibrary(MusicInfo[] songs) { if (songs.Length == 0) return; var collection = MongoHelper.Current.GetCollection<MusicInfo>("musicinfo"); collection.InsertBatch(songs); if (Messaging != null) Messaging.SendSongsAdded(songs); }
public void PlayerShouldBePausableAndResumeable() { var playlist = new Playlist(new DummyPlaylistWatcher()); var dummyAudio = new DummyAudioInteractor(); var player = new Player(playlist, dummyAudio, null); var song = "song1"; var music = new MusicInfo() { FullPath = song }; playlist.Enqueue(music); player.Play(); player.Pause(); player.Resume(); Assert.IsTrue(dummyAudio.WasPaused, "The audio must have been paused."); Assert.IsTrue(dummyAudio.WasResumed, "The audio must have been resumed."); }
public MusicInfo GetInfoForFile(string fullPath) { var result = new MusicInfo(); TagLib.File file = TagLib.File.Create(fullPath); result.Artist = (file.Tag.FirstAlbumArtist ?? file.Tag.FirstPerformer) ?? ""; result.Album = file.Tag.Album ?? ""; result.Title = file.Tag.Title ?? ""; result.FullPath = fullPath; result.TrackNumber = file.Tag.Track; if (string.IsNullOrEmpty(result.Title)) { result.Title = Path.GetFileNameWithoutExtension(fullPath); } result.SavedPlaylists = new string[0]; return result; }
public MusicInfo GetInfoForFile(string fullPath) { var result = new MusicInfo(); TagLib.File file = TagLib.File.Create(fullPath); result.Artist = (file.Tag.FirstAlbumArtist ?? file.Tag.FirstPerformer) ?? ""; result.Album = file.Tag.Album ?? ""; result.Title = file.Tag.Title ?? ""; result.FullPath = fullPath; result.TrackNumber = file.Tag.Track; if (string.IsNullOrEmpty(result.Title)) { result.Title = Path.GetFileNameWithoutExtension(fullPath); } result.SavedPlaylists = new string[0]; return(result); }
public void SongEnding(MusicInfo song) { if (_playlist.RemainingSongs > PLAYLIST_SIZE) return; //TODO: Don't get the whole library for each song change var allMusic = _library.GetAllMusic().Shuffle(_random).ToArray(); for (var i = 0; i < allMusic.Length; i++) { if (!_playlist .AsQueryable() .Reverse() .Take(allMusic.Length/2) .Any(X => X.FullPath == allMusic[i].FullPath)) { _playlist.Add(allMusic[i]); break; } } }
public void PlayerCanGoBack() { var playlist = new Playlist(new DummyPlaylistWatcher()); var dummyAudio = new DummyAudioInteractor(); var player = new Player(playlist, dummyAudio, null); var song1 = new MusicInfo() { FullPath = "song1" }; var song2 = new MusicInfo() { FullPath = "song2" }; playlist.Enqueue(song1); playlist.Enqueue(song2); player.MaxPlayCount = 2; player.Play(); Assert.AreEqual(1, playlist.CurrentPosition, "The song must have moved one song ahead."); player.Back(); Assert.AreEqual(0, playlist.CurrentPosition, "The song must have moved one song back."); }
public void SongEnding(MusicInfo song) { if (_playlist.RemainingSongs > PLAYLIST_SIZE) { return; } //TODO: Don't get the whole library for each song change var allMusic = _library.GetAllMusic().Shuffle(_random).ToArray(); for (var i = 0; i < allMusic.Length; i++) { if (!_playlist .AsQueryable() .Reverse() .Take(allMusic.Length / 2) .Any(X => X.FullPath == allMusic[i].FullPath)) { _playlist.Add(allMusic[i]); break; } } }
public void SongStarting(MusicInfo song) { }
public void SongEnding(MusicInfo song) { _playlist.Enqueue(song); }
public void OneMp3file() { var fakeFiles = new string[] { "one.mp3" }; var fakeMusicInfo = new MusicInfo() { Album = "onealbum", Artist = "oneartist" }; var fakeMusicInfoReader = new FakeMusicInfoReader(fakeMusicInfo); var importFolderInteractor = new FakeFolderInteractor(fakeFiles); var library = new MemoryLibraryRepository(); library.ClearLibrary(); var importFolderWatcher = new ImportFolderWatcher(importFolderInteractor, fakeMusicInfoReader, library, null); importFolderWatcher.ProcessFiles(); var expectedLibraryPath = @"c:\temp\" + fakeMusicInfo.Artist + "\\" + fakeMusicInfo.Album + "\\" + fakeFiles[0]; Assert.AreEqual(1, importFolderInteractor.MovedFiles.Count(), "There must one moved file"); Assert.AreEqual(fakeFiles[0], importFolderInteractor.MovedFiles[0].SourceFile, "The file to move must be correct."); Assert.AreEqual(expectedLibraryPath, importFolderInteractor.MovedFiles[0].DestinationFile, "The file must be moved to the correct folder."); var libraryFiles = library.GetAllMusic(); Assert.AreEqual(1, libraryFiles.Count(), "There must be one file in the library."); Assert.AreEqual(fakeMusicInfo.Artist, libraryFiles[0].Artist, "The artist added to the library must be correct."); Assert.AreEqual(expectedLibraryPath, libraryFiles[0].FullPath, "The full path of the file in the library must be correct."); }
public void PlayerShouldBeStoppable() { var playlist = new Playlist(new DummyPlaylistWatcher()); var dummyAudio = new DummyAudioInteractor(); var player = new Player(playlist, dummyAudio, null); var song = "song1"; var music = new MusicInfo() { FullPath = song }; playlist.Enqueue(music); player.Play(); player.Stop(); Assert.IsTrue(dummyAudio.WasStopped, "It should stop."); }
public void OneMp3file_NoInfo() { var fakeFiles = new string[] { "one.mp3" }; var fakeMusicInfo = new MusicInfo() { Album = "", Artist = "" }; var fakeMusicInfoReader = new FakeMusicInfoReader(fakeMusicInfo); var importFolderInteractor = new FakeFolderInteractor(fakeFiles); var importFolderWatcher = new ImportFolderWatcher(importFolderInteractor, fakeMusicInfoReader, new MemoryLibraryRepository(), null); importFolderWatcher.ProcessFiles(); var expectedLibraryPath = @"c:\temp\Unknown Artist\Unknown Album\" + fakeFiles[0]; Assert.AreEqual(1, importFolderInteractor.MovedFiles.Count(), "There must one moved file"); Assert.AreEqual(fakeFiles[0], importFolderInteractor.MovedFiles[0].SourceFile, "The file to move must be correct."); Assert.AreEqual(expectedLibraryPath, importFolderInteractor.MovedFiles[0].DestinationFile, "The file must be moved to the correct folder."); }
public void SongStarting(MusicInfo song) { _messaging.SendNowPlaying(song); }
public void ResumingWhileNotPausedDoesNothing() { var playlist = new Playlist(new DummyPlaylistWatcher()); var dummyAudio = new DummyAudioInteractor(); var player = new Player(playlist, dummyAudio, null); var song = "song1"; var music = new MusicInfo() { FullPath = song }; playlist.Enqueue(music); player.Play(); player.Resume(); Assert.IsFalse(dummyAudio.WasResumed, "It should not resume if it wasn't paused."); }
public void PlayerShouldStopIfThePlaylistRunsOut() { var playlist = new Playlist(new DummyPlaylistWatcher()); var dummyAudio = new DummyAudioInteractor(); var player = new Player(playlist, dummyAudio, null); var song = "song1"; var music = new MusicInfo() { FullPath = song }; playlist.Enqueue(music); player.Play(); Assert.AreEqual(1, dummyAudio.PlayHistory.Count, "There must be one song that was played."); Assert.AreEqual(song, dummyAudio.PlayHistory[0], "The song that was played must be the right one."); }
public void PlayerShouldPlayTheNextSongWhenTheSongFinishes() { var playlist = new Playlist(new DummyPlaylistWatcher()); var dummyAudio = new DummyAudioInteractor(); var player = new Player(playlist, dummyAudio, null); var song1 = "song1"; var song2 = "song2"; var music1 = new MusicInfo() { FullPath = song1 }; var music2 = new MusicInfo() { FullPath = song2 }; playlist.Enqueue(music1); playlist.Enqueue(music2); player.Play(); Assert.AreEqual(2, dummyAudio.PlayHistory.Count, "There must be two songs that were played."); Assert.AreEqual(song1, dummyAudio.PlayHistory[0], "The first song that was played must be the right one."); Assert.AreEqual(song2, dummyAudio.PlayHistory[1], "The second song that was played must be the right one."); }
public void TranscodesOtherFormats() { var fakeFiles = new string[] { "test.m4a" }; var fakeMusicInfo = new MusicInfo() { Album = "Test", Artist = "Test2" }; var transcodedFile = "test.mp3"; var fakeMusicInfoReader = new FakeMusicInfoReader(fakeMusicInfo); var importFolderInteractor = new FakeFolderInteractor(fakeFiles); var fakeTranscoder = new FakeTranscoder(); var library = new MemoryLibraryRepository(); library.ClearLibrary(); var importFolderWatcher = new ImportFolderWatcher(importFolderInteractor, fakeMusicInfoReader, library, fakeTranscoder); importFolderWatcher.ProcessFiles(); var expectedLibraryPath = @"c:\temp\" + fakeMusicInfo.Artist + "\\" + fakeMusicInfo.Album + "\\" + transcodedFile; Assert.AreEqual(1, importFolderInteractor.MovedFiles.Count(), "There must one moved file"); Assert.AreEqual(transcodedFile, importFolderInteractor.MovedFiles[0].SourceFile, "The file to move must be correct."); Assert.AreEqual(expectedLibraryPath, importFolderInteractor.MovedFiles[0].DestinationFile, "The file must be moved to the correct folder."); Assert.IsTrue(importFolderInteractor.DeletedFiles.Contains(fakeFiles[0]), "The original file must be deleted."); Assert.IsTrue(importFolderInteractor.DeletedFiles.Contains(expectedLibraryPath), "The library path must be deleted."); Assert.AreEqual(2, importFolderInteractor.DeletedFiles.Count(), "There must be 2 attempted file deletes."); }
public void SendSongsAdded(MusicInfo[] song) { PubnubMessage message; if (song.Length == 1) { message = new PubnubMessage() { action = PubnubMessage.ACTION_ADDED_SONG_TO_LIBRARY, data = new { howMany = 1, firstSong = song[0] } }; } else { message = new PubnubMessage() { action = PubnubMessage.ACTION_ADDED_SONG_TO_LIBRARY, data = new { howMany = song.Length, firstSong = song[0] } }; } SendMessage(message); }
public void SongEnding(MusicInfo song) { }
public FakeMusicInfoReader(MusicInfo musicInfo) { _musicInfo = musicInfo; }
public void SongStarting(MusicInfo filename) { PlayHistory.Add(filename.FullPath); }
public void SendNowPlaying(MusicInfo song) { SendMessage(new PubnubMessage() { action = PubnubMessage.ACTION_NOWPLAYING, data = song }); }