public void UniqueNameDoesValidate() { using (Library library = new LibraryBuilder().Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddPlaylist("Existing", accessToken); library.AddPlaylist("New", accessToken); var fixture = new PlaylistViewModel(library.Playlists.Single(x => x.Name == "New"), library, accessToken, new CoreSettings()); fixture.EditName = true; fixture.Name = "Unique"; Assert.Null(fixture["Name"]); } }
public void UpdateNowCommandCanExecuteSmokeTest() { var fileSystem = new MockFileSystem(); fileSystem.Directory.CreateDirectory("C://Test"); Library library = new LibraryBuilder().WithFileSystem(fileSystem).Build(); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); var vm = new SettingsViewModel(library, new ViewSettings(), new CoreSettings(), Substitute.For<IWindowManager>(), token, new MobileApiInfo(Observable.Return(new List<MobileClient>()), Observable.Return(false))); var coll = vm.UpdateLibraryCommand.CanExecuteObservable.CreateCollection(); library.ChangeSongSourcePath("C://Test", token); var expected = new[] { false, true }; Assert.Equal(expected, coll); }
public async Task CanPlayAWholeBunchOfSongs() { var song = new LocalSong("C://", TimeSpan.Zero); using (Library library = new LibraryBuilder().WithPlaylist().Build()) { var awaiter = library.PlaybackState.Where(x => x == AudioPlayerState.Playing) .Select((x, i) => i + 1) .FirstAsync(x => x == 10) .PublishLast(); awaiter.Connect(); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); await library.PlayInstantlyAsync(Enumerable.Repeat(song, 10).ToList(), token); await awaiter.Timeout(TimeSpan.FromSeconds(5)); } }
public async Task NullUriThrowsArgumentNullException() { const string youtubePath = "http://youtube.com?v=yadda"; var song = new YoutubeSong(youtubePath, TimeSpan.FromMinutes(1)); var songFinder = Substitute.For<IYoutubeSongFinder>(); songFinder.ResolveYoutubeSongFromUrl(Arg.Any<Uri>()).Returns(Task.FromResult(song)); using (var library = new LibraryBuilder().WithPlaylist().Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); var playlist = library.Playlists.First(); library.SwitchToPlaylist(playlist, accessToken); var fixture = new DirectYoutubeViewModel(library, accessToken, songFinder); await Helpers.ThrowsAsync<ArgumentNullException>(() => fixture.AddDirectYoutubeUrlToPlaylist(null, null)); } }
public async Task NullYoutubeSongFinderResultDoesNothing() { var songFinder = Substitute.For<IYoutubeSongFinder>(); songFinder.ResolveYoutubeSongFromUrl(Arg.Any<Uri>()).Returns(Task.FromResult<YoutubeSong>(null)); using (var library = new LibraryBuilder().WithPlaylist().Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); var playlist = library.Playlists.First(); library.SwitchToPlaylist(playlist, accessToken); var fixture = new DirectYoutubeViewModel(library, accessToken, songFinder); await fixture.AddDirectYoutubeUrlToPlaylist(new Uri("http://youtube.com?v=yadda"), null); Assert.Equal(0, playlist.Count()); } }
public async Task SmokeTest() { const string youtubePath = "http://youtube.com?v=yadda"; var song = new YoutubeSong(youtubePath, TimeSpan.FromMinutes(1)); var songFinder = Substitute.For<IYoutubeSongFinder>(); songFinder.ResolveYoutubeSongFromUrl(Arg.Any<Uri>()).Returns(Task.FromResult(song)); using (var library = new LibraryBuilder().WithPlaylist().Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); var playlist = library.Playlists.First(); library.SwitchToPlaylist(playlist, accessToken); var fixture = new DirectYoutubeViewModel(library, accessToken, songFinder); await fixture.AddDirectYoutubeUrlToPlaylist(new Uri(youtubePath), null); Assert.Equal(1, playlist.Count()); } }
public async Task IsTrueForUpdatedLibrary() { var song = new LocalSong("C://Song.mp3", TimeSpan.Zero); var songFinder = Substitute.For<ILocalSongFinder>(); songFinder.GetSongsAsync().Returns(Observable.Return(Tuple.Create(song, (byte[])null))); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { "C://Song.mp3", new MockFileData("Bla") } }); using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithSongFinder(songFinder).Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); // NB: System.IO.Abstractions only likes backslashes library.ChangeSongSourcePath("C:\\", accessToken); var vm = new LocalViewModel(library, new ViewSettings(), new CoreSettings(), accessToken); await library.AwaitInitializationAndUpdate(); Assert.False(vm.ShowAddSongsHelperMessage); } }
public void PartyModeTriggersTimeoutMessage() { using (var library = new LibraryBuilder().WithPlaylist().Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); library.LocalAccessControl.SetLocalPassword(accessToken, "password"); library.LocalAccessControl.DowngradeLocalAccess(accessToken); var fixture = Substitute.For<SongSourceViewModel<ISongViewModelBase>>(library, accessToken); var timeoutTriggers = fixture.TimeoutWarning.CreateCollection(); var songVm = Substitute.For<ISongViewModelBase>(); var song = Helpers.SetupSongMock(); songVm.Model.Returns(song); fixture.SelectedSongs = new[] { songVm }; fixture.AddToPlaylistCommand.Execute(null); fixture.AddToPlaylistCommand.Execute(null); Assert.Equal(1, timeoutTriggers.Count); } }
public async Task UpdateRemovesArtworkOnlyWithoutReferenceToSong() { var existingSong = new LocalSong("C://Existing.mp3", TimeSpan.Zero, "artwork-abcdefg"); var missingSong = new LocalSong("C://Missing.mp3", TimeSpan.Zero, "artwork-abcdefg"); await BlobCache.LocalMachine.Insert("artwork-abcdefg", new byte[] { 0, 1 }); var libraryReader = Substitute.For<ILibraryReader>(); libraryReader.LibraryExists.Returns(true); libraryReader.ReadSongSourcePath().Returns("C://"); libraryReader.ReadPlaylists().Returns(new List<Playlist>()); libraryReader.ReadSongs().Returns(new[] { existingSong, missingSong }); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { existingSong.OriginalPath, new MockFileData("DontCare") } }); using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).Build()) { await library.AwaitInitializationAndUpdate(); Assert.NotNull(BlobCache.LocalMachine.GetAllKeys().FirstOrDefault(x => x == "artwork-abcdefg")); } }
public void ThrowsAccessExceptionIfPartyModeAndLockPlaylistSwitchingIsTrue() { var settings = new CoreSettings { LockPlaylist = true }; using (Library library = new LibraryBuilder().WithPlaylist("Playlist 1").WithSettings(settings).Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddPlaylist("Playlist 2", token); library.LocalAccessControl.SetLocalPassword(token, "Password"); library.LocalAccessControl.DowngradeLocalAccess(token); Assert.Throws<AccessException>(() => library.SwitchToPlaylist(library.GetPlaylistByName("Playlist 2"), token)); } }
public async Task ExternalTagChangesArePropagated() { var song = new LocalSong("C://Song.mp3", TimeSpan.Zero) { Title = "A" }; var updatedSong = new LocalSong("C://Song.mp3", TimeSpan.Zero) { Title = "B" }; var libraryReader = Substitute.For<ILibraryReader>(); libraryReader.LibraryExists.Returns(true); libraryReader.ReadSongSourcePath().Returns("C://"); libraryReader.ReadPlaylists().Returns(new List<Playlist>()); libraryReader.ReadSongs().Returns(new[] { song }); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { song.OriginalPath, new MockFileData("DontCare") } }); var songFinder = Substitute.For<ILocalSongFinder>(); songFinder.GetSongsAsync().Returns(Observable.Return(Tuple.Create(updatedSong, (byte[])null))); using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).WithSongFinder(songFinder).Build()) { await library.AwaitInitializationAndUpdate(); Assert.Equal("B", library.Songs[0].Title); } }
public async Task PreventsNextSongFromPlaying() { var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); int played = 0; audioPlayerCallback.PlayAsync().Returns(Task.Run(() => { if (played == 0) { library.AddAndSwitchToPlaylist("Playlist2", token); } played++; })); library.AddSongsToPlaylist(Helpers.SetupSongMocks(2), token); await library.PlaySongAsync(0, token); Assert.Equal(1, played); } }
public async Task SetsCurrentSongIndexIfChangingToOtherPlaylistAndPlayingFirstSong() { var settings = new CoreSettings { EnablePlaylistTimeout = false }; using (Library library = new LibraryBuilder().WithPlaylist().WithSettings(settings).Build()) { var coll = library.CurrentPlaylistChanged.StartWith(library.CurrentPlaylist) .Select(x => x.WhenAnyValue(y => y.CurrentSongIndex)).Switch().CreateCollection(); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongToPlaylist(Helpers.SetupSongMock()); await library.PlaySongAsync(0, token); library.AddPlaylist("Playlist 2", token); library.SwitchToPlaylist(library.Playlists.Last(), token); library.AddSongToPlaylist(Helpers.SetupSongMock()); await library.PlaySongAsync(0, token); Assert.Equal(new int?[] { null, 0, null, null, 0, null }, coll); } }
public async Task SmokeTest() { var fileSystem = new MockFileSystem(); fileSystem.Directory.CreateDirectory("C://Test"); using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).Build()) { library.ChangeSongSourcePath("C://Test", library.LocalAccessControl.RegisterLocalAccessToken()); Assert.Equal("C://Test", await library.SongSourcePath.FirstAsync()); } }
public async Task JumpsOverCorruptedSong() { using (var handle = new CountdownEvent(2)) { var audioPlayer = Substitute.For<IMediaPlayerCallback>(); audioPlayer.PlayAsync().Returns(_ => Task.Run(() => { switch (handle.CurrentCount) { case 2: handle.Signal(); throw new SongLoadException(); case 1: handle.Signal(); break; } })); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayer).Build()) { Song[] songs = Helpers.SetupSongMocks(2); await library.PlayInstantlyAsync(songs, library.LocalAccessControl.RegisterLocalAccessToken()); if (!handle.Wait(5000)) { Assert.False(true, "Timeout"); } } } }
public async Task SmokeTest() { var fileSystem = new MockFileSystem(); fileSystem.Directory.CreateDirectory("C://Test"); using (var library = new LibraryBuilder().WithFileSystem(fileSystem).Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.ChangeSongSourcePath("C://Test", token); var isUpdating = library.IsUpdating.CreateCollection(); var last = library.IsUpdating.Where(x => !x).ElementAt(1).PublishLast(); last.Connect(); library.Initialize(); await last.Timeout(TimeSpan.FromSeconds(5)); Assert.Equal(new[] { false, true, false }, isUpdating); } }
public void PlaylistTimeoutThrowsInvalidOperationException() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); library.LocalAccessControl.SetLocalPassword(accessToken, "password"); library.LocalAccessControl.DowngradeLocalAccess(accessToken); Song song = Helpers.SetupSongMock(); library.AddSongToPlaylist(song); Assert.Throws<InvalidOperationException>(() => library.AddSongToPlaylist(song)); } }
public async Task SetsSongIsCorruptedToTrueIfFailing() { Func<Library, Task> test = async library => { Song song = Helpers.SetupSongMock(); library.AddSongToPlaylist(song); await library.PlaySongAsync(0, library.LocalAccessControl.RegisterLocalAccessToken()); Assert.True(song.IsCorrupted); }; var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); audioPlayerCallback.LoadAsync(Arg.Any<Uri>()).Returns(Observable.Throw<Unit>(new SongLoadException()).ToTask()); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { await test(library); } audioPlayerCallback.PlayAsync().Returns(Observable.Throw<Unit>(new PlaybackException()).ToTask()); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { await test(library); } }
public async Task SongPreparationCanTimeout() { await new TestScheduler().With(async sched => { var song = Substitute.For<Song>("C://", TimeSpan.Zero); song.PrepareAsync(Arg.Any<YoutubeStreamingQuality>()).Returns(Observable.Return(Unit.Default) .Delay(Library.PreparationTimeout + TimeSpan.FromSeconds(1), sched).ToTask()); var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongsToPlaylist(new[] { song }, token); Task play = library.PlaySongAsync(0, token); sched.AdvanceByMs((Library.PreparationTimeout + TimeSpan.FromSeconds(2)).TotalMilliseconds); await play; } audioPlayerCallback.DidNotReceiveWithAnyArgs().LoadAsync(Arg.Any<Uri>()); }); }
public async Task PlaysNextSongAutomatically() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongsToPlaylist(Helpers.SetupSongMocks(2), token); var conn = library.PlaybackState.Where(x => x == AudioPlayerState.Playing) .Take(2) .PublishLast(); conn.Connect(); await library.PlaySongAsync(0, token); await conn.Timeout(TimeSpan.FromSeconds(5)); } }
public async Task ThrowsInvalidOperationExceptionIfPlaylistIsEmpty() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { await Helpers.ThrowsAsync<InvalidOperationException>(async () => await library.PlayPreviousSongAsync(library.LocalAccessControl.RegisterLocalAccessToken())); } }
public async Task SmokeTest() { var audioPlayer = Substitute.For<IMediaPlayerCallback>(); using (Library library = new LibraryBuilder().WithAudioPlayer(audioPlayer).Build()) { Song song = Helpers.SetupSongMock(); await library.PlayInstantlyAsync(new[] { song }, library.LocalAccessControl.RegisterLocalAccessToken()); } audioPlayer.Received(1).PlayAsync(); }
public async Task UpdateRemovesArtworkWhenSongIsMissing() { var missingSong = new LocalSong("C://Missing.mp3", TimeSpan.Zero, "artwork-abcdefg"); await BlobCache.LocalMachine.Insert("artwork-abcdefg", new byte[] { 0, 1 }); var libraryReader = Substitute.For<ILibraryReader>(); libraryReader.LibraryExists.Returns(true); libraryReader.ReadSongSourcePath().Returns("C://"); libraryReader.ReadPlaylists().Returns(new List<Playlist>()); libraryReader.ReadSongs().Returns(new[] { missingSong }); var fileSystem = new MockFileSystem(); fileSystem.Directory.CreateDirectory("C://"); using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).Build()) { await library.AwaitInitializationAndUpdate(); Assert.Null(BlobCache.LocalMachine.GetAllKeys().FirstOrDefault(x => x == "artwork-abcdefg")); } }
public async Task WhileSongIsPlayingStopsCurrentSong() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongsToPlaylist(Helpers.SetupSongMocks(1), token); var awaiter = library.PlaybackState.FirstAsync(x => x == AudioPlayerState.Finished).PublishLast(); awaiter.Connect(); await library.PlaySongAsync(0, token); library.RemoveFromPlaylist(new[] { 0 }, token); await awaiter.Timeout(TimeSpan.FromSeconds(5)); } }
public async Task TriggersUpdate() { var fileSystem = new MockFileSystem(); fileSystem.Directory.CreateDirectory("C://Test"); using (var library = new LibraryBuilder().WithFileSystem(fileSystem).Build()) { library.Initialize(); var updated = library.IsUpdating.FirstAsync(x => x).PublishLast(); updated.Connect(); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.ChangeSongSourcePath("C://Test", token); await updated.Timeout(TimeSpan.FromSeconds(5)); } }
public async Task DoesNotSaveTemporaryPlaylist() { var libraryWriter = Substitute.For<ILibraryWriter>(); using (Library library = new LibraryBuilder().WithWriter(libraryWriter).Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddAndSwitchToPlaylist("Playlist", token); await library.PlayInstantlyAsync(Helpers.SetupSongMocks(1), token); library.Save(); } libraryWriter.Received(1).Write(Arg.Any<IEnumerable<LocalSong>>(), Arg.Is<IEnumerable<Playlist>>(x => x.Count() == 1), Arg.Any<string>()); }
public void ThrowsAccessExceptionIfAccessModeIsPartyAndLockPlaylistRemovalIsTrue() { var songMock = Substitute.For<Song>("TestPath", TimeSpan.Zero); var settings = new CoreSettings { LockPlaylist = true }; using (Library library = new LibraryBuilder().WithPlaylist().WithSettings(settings).Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.LocalAccessControl.SetLocalPassword(token, "Password"); library.LocalAccessControl.DowngradeLocalAccess(token); library.AddSongToPlaylist(songMock); Assert.Throws<AccessException>(() => library.RemoveFromPlaylist(new[] { 0 }, token)); } }
public async Task CallsAudioPlayerPause() { var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { Song song = Helpers.SetupSongMock(); library.AddSongToPlaylist(song); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); await library.PlaySongAsync(0, token); await library.PauseSongAsync(token); } audioPlayerCallback.Received(1).PauseAsync(); }
public void BySongReferenceTest() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); Song[] songs = Helpers.SetupSongMocks(4); library.AddSongsToPlaylist(songs, token); library.RemoveFromPlaylist(new[] { songs[0], songs[2] }, token); Song[] remaining = library.CurrentPlaylist.Select(entry => entry.Song).ToArray(); Assert.Equal(songs[1], remaining[0]); Assert.Equal(songs[3], remaining[1]); } }
public void DisabledTimeoutSmokeTest() { var settings = new CoreSettings { EnablePlaylistTimeout = false }; using (Library library = new LibraryBuilder().WithPlaylist().WithSettings(settings).Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); library.LocalAccessControl.SetLocalPassword(accessToken, "password"); library.LocalAccessControl.DowngradeLocalAccess(accessToken); Song song = Helpers.SetupSongMock(); library.AddSongToPlaylist(song); library.AddSongToPlaylist(song); Assert.Equal(2, library.CurrentPlaylist.Count()); } }