Beispiel #1
0
 public static AlbumInfo FromRepositoryObject(LastfmAlbumInfo repoObject)
 {
     return(new AlbumInfo {
         Name = repoObject.Name,
         Artist = repoObject.Artist,
         ReleaseDate = repoObject.ReleaseDate,
         WikiSummary = repoObject.WikiSummary,
     });
 }
        public void FindAlbumInfo_Gets_Data_From_Cache()
        {
            var          cache             = MockRepository.GenerateStub <ILastfmCache>();
            var          expectedAlbumInfo = new LastfmAlbumInfo();
            const string artist            = "Bobby Hutcherson";
            const string album             = "Spiral";

            var repository = new LastfmRepository(null, cache);

            cache.Stub(c => c.Get(LastfmCache.AlbumInfoCacheKey + ":" + artist + album)).Return(expectedAlbumInfo);

            var albumInfo = repository.FindAlbumInfo(artist, album);

            Assert.That(albumInfo, Is.SameAs(expectedAlbumInfo));
        }
        public void GetAlbumInfo_Returns_Info_From_Repository()
        {
            var artist          = CreateArtistName();
            var album           = CreateAlbumName();
            var lastfmAlbumInfo = new LastfmAlbumInfo {
                Artist = artist,
                Name   = album
            };

            repository.Stub(r => r.FindAlbumInfo(artist, album)).Return(lastfmAlbumInfo);

            var result = subject.GetAlbumInfo(artist, album) as OkNegotiatedContentResult <AlbumInfo>;

            Assert.That(result.Content.Name, Is.EqualTo(lastfmAlbumInfo.Name));
        }
        public void FindAlbumInfo_Adds_Result_To_Cache_And_Returns_It()
        {
            var service = MockRepository.GenerateStub <ILastfmService>();
            var cache   = MockRepository.GenerateMock <ILastfmCache>();
            var config  = MockRepository.GenerateStub <IConfig>();

            var expectedAlbumInfo = new LastfmAlbumInfo();
            var artist            = "Bobby Hutcherson";
            var album             = "Spiral";

            service.Stub(s => s.FindAlbumInfo(artist, album)).Return(expectedAlbumInfo);
            cache.Stub(c => c.Get(LastfmCache.AlbumInfoCacheKey + ":" + artist + album)).Return(null);
            cache.Expect(c => c.Insert(LastfmCache.AlbumInfoCacheKey + ":" + artist + album, expectedAlbumInfo));

            using (new ConfigScope(config)) {
                var repository = new LastfmRepository(service, cache);
                var albumInfo  = repository.FindAlbumInfo(artist, album);

                cache.VerifyAllExpectations();
                Assert.That(albumInfo, Is.SameAs(expectedAlbumInfo));
            }
        }