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 AlbumArtRepositoryPersistNewArtTest()
 {
     var stream = new MemoryStream();
     stream.WriteByte(0x38);
     var art = new AlbumArt{ AlbumId = 1, ArtStream = stream };
     var target = new AlbumArtRepository("art");
     target.Persist(art);
     Assert.That(File.Exists(Path.Combine("art", "1")));
     using(var nfs = File.Open(Path.Combine("art", 1.ToString()), FileMode.Open))
     {
         Assert.That(nfs.Length, Is.EqualTo(1));
     }
 }
        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));
        }