public void AlbumArtLoaderCachesNewArtTest() { var container = new Athena.IoC.Container(); var model = new AmpacheModel(); container.Register<AmpacheModel>().To(model); var defaultStream = new MemoryStream(); var persistor = Substitute.For<IPersister<AlbumArt>>(); container.Register<IPersister<AlbumArt>>().To(persistor); persistor.IsPersisted(Arg.Any<IEntity>()).Returns(false); var art = new AlbumArt(); persistor.IsPersisted(Arg.Is(art)).Returns(false); int timesCalled = 0; persistor.When(x => x.Persist(Arg.Any<AlbumArt>())).Do( x => { ++timesCalled; }); art.ArtStream = new MemoryStream(new byte[8]); persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(new [] {art}); var prefs = new UserConfiguration(); prefs.CacheArt = true; model.Configuration = prefs; var target = new AlbumArtLoader(container, defaultStream); var sng = new AmpacheSong(); sng.ArtUrl = "test"; model.PlayingSong = sng; System.Threading.Thread.Sleep(100); Assert.That(model.AlbumArtStream, Is.SameAs(art.ArtStream)); Assert.That(timesCalled, Is.EqualTo(1)); }
public void AmpachePlayerNextNotShufflingPlayingRollsToStartTest() { var model = new AmpacheModel(); var mock = new PlayerHandle(model); mock.SetPauseState(false); var first = new AmpacheSong(); var second = new AmpacheSong(); model.Playlist = new List<AmpacheSong>{ first, second }; model.PlayingSong = second; model.IsPlaying = true; model.PercentPlayed = 90; model.PercentDownloaded = 100; model.NextRequested = true; System.Threading.Thread.Sleep(100); Assert.That(model.PlayPauseRequested, Is.False); Assert.That(model.PercentPlayed, Is.EqualTo(0)); Assert.That(model.PercentDownloaded, Is.EqualTo(0)); Assert.That(mock.PauseCalls, Is.EqualTo(0)); Assert.That(mock.UnpauseCalls, Is.EqualTo(0)); Assert.That(mock.PlaySongCalls, Is.EqualTo(1)); Assert.That(mock.StopCalls, Is.EqualTo(0)); Assert.That(mock.SeekToCalls, Is.EqualTo(0)); Assert.That(mock.GetPauseState(), Is.False); Assert.That(model.IsPlaying, Is.True); Assert.That(model.PlayingSong, Is.SameAs(first)); Assert.That(mock.LastStartedSong, Is.SameAs(first)); }
public void SongPersisterIsNotPersistedTest() { var conn = new SQLiteConnection("Data Source=:memory:"); using(var target = new SongPersister(conn)) using(var cmd = conn.CreateCommand()) { var song = new AmpacheSong(); song.Id = 555; Assert.That(target.IsPersisted(song), Is.False); } }
public void SongPersisterIsPersistedTest() { var conn = new SQLiteConnection("Data Source=:memory:"); using(var target = new SongPersister(conn)) using(var cmd = conn.CreateCommand()) { var song = new AmpacheSong(); song.Id = 555; cmd.CommandText = string.Format("INSERT INTO SongCache (SongId) VALUES ({0});", song.Id); cmd.ExecuteNonQuery(); Assert.That(target.IsPersisted(song), Is.True); } }
public void SongHandshakeRemapperUrlMissingUserTest() { var sng = new AmpacheSong(); sng.Url = URL_MISSING_USER; sng.Id = 630; sng.AlbumId = 50; sng.ArtUrl = ART_URL; var handshake = new MockHandshake(); handshake.SetPassphrase("test"); handshake.SetServer("http://server.com"); sng.MapToHandshake(handshake); Assert.That(sng.Url, Is.EqualTo(URL_MISSING_USER.Replace("SESSION", handshake.Passphrase).Replace("SONGID", sng.Id.ToString()))); Assert.That(sng.ArtUrl, Is.EqualTo(ART_URL.Replace("ID", sng.ArtId.ToString()).Replace("AUTH", handshake.Passphrase))); }
protected abstract void PlaySong(AmpacheSong song);
public void AmpachePlayerNextShufflingTest() { var model = new AmpacheModel(); var mock = new PlayerHandle(model); mock.SetPauseState(false); var first = new AmpacheSong(); var second = new AmpacheSong(); model.Playlist = new List<AmpacheSong>{ first, second }; model.PlayingSong = first; model.IsPlaying = true; model.Shuffling = true; model.NextRequested = true; System.Threading.Thread.Sleep(100); Assert.That(model.PlayPauseRequested, Is.False); Assert.That(mock.PauseCalls, Is.EqualTo(0)); Assert.That(mock.UnpauseCalls, Is.EqualTo(0)); Assert.That(mock.PlaySongCalls, Is.EqualTo(1)); Assert.That(mock.StopCalls, Is.EqualTo(0)); Assert.That(mock.SeekToCalls, Is.EqualTo(0)); Assert.That(mock.GetPauseState(), Is.False); Assert.That(model.IsPlaying, Is.True); // TODO: find a way to test randomized shuffeling }
public void AlbumArtLoaderUsesLoadedArtAfterLoadingTest() { var container = new Athena.IoC.Container(); var model = new AmpacheModel(); container.Register<AmpacheModel>().To(model); var defaultStream = new MemoryStream(); var persistor = Substitute.For<IPersister<AlbumArt>>(); container.Register<IPersister<AlbumArt>>().To(persistor); persistor.IsPersisted(Arg.Any<IEntity>()).Returns(false); var art = new AlbumArt(); art.ArtStream = new MemoryStream(); persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(new [] {art}); var prefs = new UserConfiguration(); prefs.CacheArt = false; model.Configuration = prefs; var target = new AlbumArtLoader(container, defaultStream); var sng = new AmpacheSong(); sng.ArtUrl = "test"; model.PlayingSong = sng; System.Threading.Thread.Sleep(100); Assert.That(model.AlbumArtStream, Is.SameAs(art.ArtStream)); }
public void AlbumArtLoaderUsesDefaultArtWhenNoArtAvailableTest() { var container = new Athena.IoC.Container(); var model = new AmpacheModel(); container.Register<AmpacheModel>().To(model); var defaultStream = new MemoryStream(); var target = new AlbumArtLoader(container, defaultStream); var sng = new AmpacheSong(); sng.ArtUrl = string.Empty; model.PlayingSong = sng; System.Threading.Thread.Sleep(100); Assert.That(model.AlbumArtStream, Is.SameAs(defaultStream)); }
public void AlbumArtLoaderUsesDefaultArtWhenLoadingArtTest() { var container = new Athena.IoC.Container(); var model = new AmpacheModel(); container.Register<AmpacheModel>().To(model); var defaultStream = new MemoryStream(); var persistor = Substitute.For<IPersister<AlbumArt>>(); persistor.IsPersisted(Arg.Any<IEntity>()).Returns(false); int timesCalled = 0; persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(x => { ++timesCalled; Assert.That(model.AlbumArtStream, Is.SameAs(defaultStream)); return Enumerable.Empty<AlbumArt>();}); container.Register<IPersister<AlbumArt>>().To(persistor); var target = new AlbumArtLoader(container, defaultStream); var sng = new AmpacheSong(); sng.ArtUrl = "test"; model.PlayingSong = sng; System.Threading.Thread.Sleep(100); Assert.That(timesCalled, Is.EqualTo(1)); }
public void BackgroundListensForPlaylistChangesTest() { var container = new Athena.IoC.Container(); var persister = Substitute.For<IPersister<AmpacheSong>>(); var sng = new AmpacheSong(); container.Register<IPersister<AmpacheSong>>().To(persister); var usrp = Substitute.For<IPersister<UserConfiguration>>(); container.Register<IPersister<UserConfiguration>>().To(usrp); bool persisted = false; persister.When(p => p.Persist(sng)).Do(p => persisted = true); string path = "myartpath"; var target = new BackgroundHandle(null, path, new AmpacheModel(), container); target.Start(new MemoryStream()); System.Threading.Thread.Sleep(100); var sngs = new List<AmpacheSong>(); sngs.Add(sng); target.Model.Playlist = sngs; Assert.That(persisted, Is.True); }
public void AmpachePlayerPreviousAfterSomePlayTest() { var model = new AmpacheModel(); var mock = new PlayerHandle(model); mock.SetPauseState(false); var first = new AmpacheSong(); var second = new AmpacheSong(); model.Playlist = new List<AmpacheSong>{ first, second }; model.PlayingSong = second; mock.SetPlayerPositionMilliSecond(10000); model.IsPlaying = true; model.PreviousRequested = true; System.Threading.Thread.Sleep(100); Assert.That(model.PlayPauseRequested, Is.False); Assert.That(mock.PauseCalls, Is.EqualTo(0)); Assert.That(mock.UnpauseCalls, Is.EqualTo(0)); Assert.That(mock.PlaySongCalls, Is.EqualTo(1)); Assert.That(mock.StopCalls, Is.EqualTo(0)); Assert.That(mock.SeekToCalls, Is.EqualTo(0)); Assert.That(mock.GetPauseState(), Is.False); Assert.That(model.IsPlaying, Is.True); Assert.That(model.PlayingSong, Is.SameAs(second)); Assert.That(mock.LastStartedSong, Is.SameAs(second)); }
protected override void PlaySong(AmpacheSong song) { LastStartedSong = song; ++PlaySongCalls; }
protected override void PlaySong(AmpacheSong song) { base.PlaySong(song); throw new Exception(); }
public void AmpachePlayerStopWhilePlayTest() { var model = new AmpacheModel(); var mock = new PlayerHandle(model); mock.SetPauseState(false); var first = new AmpacheSong(); var second = new AmpacheSong(); model.Playlist = new List<AmpacheSong>{ first, second }; model.PlayingSong = second; model.IsPlaying = true; model.StopRequested = true; System.Threading.Thread.Sleep(100); Assert.That(model.PlayPauseRequested, Is.False); Assert.That(mock.PauseCalls, Is.EqualTo(0)); Assert.That(mock.UnpauseCalls, Is.EqualTo(0)); Assert.That(mock.PlaySongCalls, Is.EqualTo(0)); Assert.That(mock.StopCalls, Is.EqualTo(1)); Assert.That(mock.SeekToCalls, Is.EqualTo(0)); Assert.That(mock.GetPauseState(), Is.False); Assert.That(model.IsPlaying, Is.False); Assert.That(model.PlayingSong, Is.Null); }
public void AmpachePlayerSettingPlayerPositionMilliSecondUpdatesPercentPlayedOnModelTest() { var model = new AmpacheModel(); var mock = new PlayerHandle(model); var song = new AmpacheSong(); song.TrackLength = TimeSpan.FromSeconds(60); model.PlayingSong = song; mock.SetPlayerPositionMilliSecond(15000); Assert.That(model.PercentPlayed, Is.EqualTo(25)); }
public void AmpachePlayerSeekingTest() { var model = new AmpacheModel(); var mock = new PlayerHandle(model); mock.SetPauseState(false); var first = new AmpacheSong(); var second = new AmpacheSong(); second.TrackLength = TimeSpan.FromMinutes(1); model.Playlist = new List<AmpacheSong>{ first, second }; model.PlayingSong = second; model.IsPlaying = true; model.Configuration = new UserConfiguration(); model.Configuration.AllowSeeking = true; model.RequestedSeekToPercentage = 50; System.Threading.Thread.Sleep(100); Assert.That(model.PlayPauseRequested, Is.False); Assert.That(mock.PauseCalls, Is.EqualTo(0)); Assert.That(mock.UnpauseCalls, Is.EqualTo(0)); Assert.That(mock.PlaySongCalls, Is.EqualTo(0)); Assert.That(mock.StopCalls, Is.EqualTo(0)); Assert.That(mock.SeekToCalls, Is.EqualTo(1)); Assert.That(mock.GetPauseState(), Is.False); Assert.That(model.IsPlaying, Is.True); Assert.That(model.PlayingSong, Is.SameAs(second)); }
public void SongPersisterSelectAllTest() { var conn = new SQLiteConnection("Data Source=:memory:"); using(var target = new SongPersister(conn)) using(var cmd = conn.CreateCommand()) { var song = new AmpacheSong(); song.Id = 555; song.AlbumId = 88; song.AlbumName = "album name"; song.ArtistId =45; song.ArtistName = "artist"; song.ArtUrl = "url"; song.Name = "name"; song.PerciseRating = 2456; song.Rating = 24; song.Tags = new List<Tag>(); song.TrackLength = TimeSpan.FromSeconds(2442); song.TrackNumber = 5; song.Url = "sasasdf"; Assert.That(target.IsPersisted(song), Is.False); target.Persist(song); cmd.CommandText = string.Format("select COUNT(*) from SongCache where SongId = {0};", song.Id); Assert.That(cmd.ExecuteScalar(), Is.EqualTo(1)); var actual = target.SelectAll().ToList(); Assert.That(actual, Is.Not.Null); Assert.That(actual.Count, Is.EqualTo(1)); var first = actual.First(); Assert.That(first.Id, Is.EqualTo(song.Id)); Assert.That(first.ArtistId, Is.EqualTo(song.ArtistId)); Assert.That(first.AlbumId, Is.EqualTo(song.AlbumId)); Assert.That(first.Name, Is.EqualTo(song.Name)); Assert.That(first.AlbumName, Is.EqualTo(song.AlbumName)); Assert.That(first.ArtistName, Is.EqualTo(song.ArtistName)); Assert.That(first.TrackNumber, Is.EqualTo(song.TrackNumber)); Assert.That(first.ArtUrl, Is.EqualTo(song.ArtUrl)); Assert.That(first.TrackLength, Is.EqualTo(song.TrackLength)); Assert.That(first.Url, Is.EqualTo(song.Url)); Assert.That(first.Rating, Is.EqualTo(song.Rating)); Assert.That(first.PerciseRating, Is.EqualTo(song.PerciseRating)); } }
private View HydrateSong(AmpacheSong song, View v) { if(song != null){ v.FindViewById<TextView>(Android.Resource.Id.Text1).Text = song.Name; } return v; }
public void AmpachePlayerPlayPauseStartsPlaybackAtFirstSongTest() { var model = new AmpacheModel(); var mock = new PlayerHandle(model); mock.SetPauseState(false); var first = new AmpacheSong(); var second = new AmpacheSong(); model.Playlist = new List<AmpacheSong>{ first, second }; model.PlayPauseRequested = true; System.Threading.Thread.Sleep(100); Assert.That(model.PlayPauseRequested, Is.False); Assert.That(mock.PauseCalls, Is.EqualTo(0)); Assert.That(mock.UnpauseCalls, Is.EqualTo(0)); Assert.That(mock.PlaySongCalls, Is.EqualTo(1)); Assert.That(mock.StopCalls, Is.EqualTo(0)); Assert.That(mock.SeekToCalls, Is.EqualTo(0)); Assert.That(mock.GetPauseState(), Is.False); Assert.That(model.IsPlaying, Is.True); Assert.That(model.PlayingSong, Is.SameAs(first)); Assert.That(mock.LastStartedSong, Is.SameAs(first)); }
public void SongPersisterPersistTest() { var conn = new SQLiteConnection("Data Source=:memory:"); using(var target = new SongPersister(conn)) using(var cmd = conn.CreateCommand()) { var song = new AmpacheSong(); song.Id = 555; song.AlbumId = 88; song.AlbumName = "album name"; song.ArtistId =45; song.ArtistName = "artist"; song.ArtUrl = "url"; song.Name = "name"; song.PerciseRating = 2456; song.Rating = 24; song.Tags = new List<Tag>(); song.TrackLength = TimeSpan.FromSeconds(2442); song.TrackNumber = 5; song.Url = "sasasdf"; Assert.That(target.IsPersisted(song), Is.False); target.Persist(song); cmd.CommandText = string.Format("select * from SongCache where SongId = {0};", song.Id); var reader = cmd.ExecuteReader(); Assert.That(reader.Read(), Is.True); Assert.That(reader["SongId"], Is.EqualTo(song.Id)); Assert.That(reader["ArtistId"], Is.EqualTo(song.ArtistId)); Assert.That(reader["AlbumId"], Is.EqualTo(song.AlbumId)); Assert.That(reader["SongName"], Is.EqualTo(song.Name)); Assert.That(reader["AlbumName"], Is.EqualTo(song.AlbumName)); Assert.That(reader["ArtistName"], Is.EqualTo(song.ArtistName)); Assert.That(reader["TrackNumber"], Is.EqualTo(song.TrackNumber)); Assert.That(reader["ArtUrl"], Is.EqualTo(song.ArtUrl)); Assert.That(reader["TrackLengthSeconds"], Is.EqualTo(song.TrackLength.TotalSeconds)); Assert.That(reader["SongUrl"], Is.EqualTo(song.Url)); Assert.That(reader["Rating"], Is.EqualTo(song.Rating)); Assert.That(reader["PerciseRating"], Is.EqualTo(song.PerciseRating)); // NOTE: tags are not persisted! } }
public void SongHandshakeRemapperNullHandshakeTest() { var sng = new AmpacheSong(); sng.MapToHandshake(null); Assert.Fail(); }