Пример #1
0
        public void Run()
        {
            var db = MockRepository.GenerateMock<IMusicContext>();
              var library = MockRepository.GenerateMock<IITunesLibrary>();
              var translator = MockRepository.GenerateMock<IAlbumTranslator>();
              var config = MockRepository.GenerateMock<IConfig>();
              var albumInfo = MockRepository.GenerateMock<ILastFmAlbumInfo>();

              var album = new Album { Artist = "Chroma Key", Genre = "Rock", Name = "You Go Now", Year = 1999 };
              var tracks = new List<Track>();
              var dbSetAlbums = new FakeDbSet<Album>();
              var fileLocation = "loc";
              var albums = new List<Album> { album };

              db.Expect(d => d.UpdateExisting(albums)).Return(0);
              db.Stub(d => d.Albums).Return(dbSetAlbums);
              config.Stub(c => c.ITunesFileLocation).Return(fileLocation);
              library.Stub(l => l.Parse(fileLocation)).Return(tracks);
              translator.Stub(t => t.Convert(tracks)).Return(albums);
              db.Expect(d => d.SaveChanges()).Return(1);

              using (new ConfigScope(config)) {
            new AlbumExport(db, library, translator, albumInfo).Run();
              }
              Assert.AreEqual(1, dbSetAlbums.Count());
              Assert.AreEqual(album, dbSetAlbums.First());
              albumInfo.AssertWasCalled(t => t.UpdateAlbums(albums));
              db.VerifyAllExpectations();
        }
Пример #2
0
        public void Update_Does_Not_Overwrite_Album_Artwork_If_It_Already_Exists()
        {
            var album = new Album {
            AlbumID = 1,
            Artist = "John Coltrane",
            Name = "Ballads",
            ArtworkLocation = "Some Url",
            AlbumArtist = "John Coltrane",
            DateAdded = DateTime.Now.AddDays(-4),
            LastPlayed = DateTime.Now.AddDays(-2),
            Genre = "Jazz",
            PlayCount = 25,
            Year = 1964
              };

              var updatedAlbum = new Album {
            AlbumID = 1,
            Artist = "John Coltrane",
            Name = "Ballads",
            ArtworkLocation = "new Url",
            AlbumArtist = "John Coltrane",
            DateAdded = DateTime.Now.AddDays(-4),
            LastPlayed = DateTime.Now.AddDays(-2),
            Genre = "Jazz",
            PlayCount = 25,
            Year = 1964
              };
              album.Update(updatedAlbum);
              Assert.AreEqual(album.ArtworkLocation, "Some Url");
        }
Пример #3
0
        public void Update_Updates_All_Fields_Except_ID_Name_And_Artist()
        {
            var album = new Album {
            AlbumID = 1,
            Artist = "John Coltrane",
            Name = "Ballads",
            ArtworkLocation = "Some Url",
            AlbumArtist = "John Coltrane",
            DateAdded = DateTime.Now.AddDays(-4),
            LastPlayed = DateTime.Now.AddDays(-2),
            Genre = "Jazz",
            PlayCount = 25,
            Year = 1964
              };

              var updatedAlbum = new Album {
            AlbumID = 77,
            Artist = "John Coltrane & McCoy Tyner",
            Name = "Ballads Remaster",
            ArtworkLocation = "new URL",
            AlbumArtist = "John Coltrane Quartet",
            DateAdded = DateTime.Now.AddDays(-3),
            LastPlayed = DateTime.Now.AddDays(-1),
            Genre = "Hard Bop",
            PlayCount = 55,
            Year = 1963
              };

              album.Update(updatedAlbum);
              Assert.AreEqual(album.ArtworkLocation, album.ArtworkLocation, "does not update artwork location if original album already had artwork");
              Assert.AreEqual(updatedAlbum.AlbumArtist, album.AlbumArtist);
              Assert.AreEqual(updatedAlbum.DateAdded, album.DateAdded);
              Assert.AreEqual(updatedAlbum.LastPlayed, album.LastPlayed);
              Assert.AreEqual(updatedAlbum.Genre, album.Genre);
              Assert.AreEqual(updatedAlbum.PlayCount, album.PlayCount);
              Assert.AreEqual(updatedAlbum.Year, album.Year);

              Assert.AreNotEqual(updatedAlbum.AlbumID, album.AlbumID);
              Assert.AreNotEqual(updatedAlbum.Artist, album.Artist);
              Assert.AreNotEqual(updatedAlbum.Name, album.Name);
        }
Пример #4
0
 public void Update(Album album)
 {
     this.AlbumArtist = album.AlbumArtist;
       this.DateAdded = album.DateAdded;
       this.Year = album.Year;
       this.PlayCount = album.PlayCount;
       this.LastPlayed = album.LastPlayed;
       this.ArtworkLocation = !string.IsNullOrEmpty(this.ArtworkLocation) ? this.ArtworkLocation : album.ArtworkLocation;
       this.Genre = album.Genre;
       //Assuming tracks will not change and will only be added on insert not update. So they aren't included here.
 }
Пример #5
0
 static Func<LastfmLibraryAlbum, bool> MatchingAlbum(Album album)
 {
     return t => ScrubAlbumData(t.Artist) == ScrubAlbumData(album.Artist) &&
      ScrubAlbumData(t.Name) == ScrubAlbumData(album.Name);
 }