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 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 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));
     }
 }