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."); }
private void StartPlayer() { try { var playlistManager = GetPlaylistManager(); var messagingWatcher = new MessagingPlaylistWatcher(); var playlist = new Playlist(new IPlaylistWatcher[] { playlistManager, messagingWatcher }); var dummyAudio = new NAudioInteractor(); var library = new MongoLibraryRepository(null); _folderWatcher = new ImportFolderWatcher(library); if (ConfigurationManager.AppSettings["ResetLibraryForTesting"] == "true") { InsertTestSongs(library); } var player = new Player(playlist, dummyAudio, library); _pubnub = new PubnubMessaging(player, true); messagingWatcher.AssignMessaging(_pubnub); messagingWatcher.AttachToPlaylist(playlist, library); playlistManager.AttachToPlaylist(playlist, library); _pubnub.StartListening(); library.Messaging = _pubnub; _folderWatcher.Start(); if (ConfigurationManager.AppSettings["AutoStartPlaying"] == "true") { player.Play(); } _pubnub.SendNowPlaying(playlist[0]); } catch (Exception exc) { Log.Debug(exc.ToString()); } }