public void AlbumArtLoaderIgnoresCachingPersistedItemTest()
        {
            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(true);
            var art = new AlbumArt();
            persistor.IsPersisted(Arg.Is(art)).Returns(true);
            int timesCalled = 0;
            persistor.When(x => x.Persist(Arg.Any<AlbumArt>())).Do( x => { ++timesCalled; });
            art.ArtStream = new MemoryStream();
            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(0));
        }
 public AlbumArtLoader(Athena.IoC.Container container, MemoryStream defaultStream)
 {
     _container = container;
     _defaultStream = defaultStream;
     _model = container.Resolve<AmpacheModel>();
     _model.PropertyChanged += Handle_modelPropertyChanged;
     LoadAlbumImage();
 }
 public void BackgroundListensForModelDispositionTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, null, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     target.Model.Dispose();
     Assert.That(target.FinalizedCalled, Is.True);
 }
 public void BackgroundListensForPlayingChangesAndCancelsShutOffTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     target.Model.IsPlaying = true;
     Assert.That(target.StopShutOffCallCount, Is.EqualTo(1));
 }
 public void BackgroundListensForConfigChangesTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     bool persisted = false;
     var config = new UserConfiguration();
     persister.When(x => x.Persist(config)).Do(p => persisted = true);
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     target.Model.Configuration = config;
     Assert.That(persisted, Is.True);
 }
        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 AlbumArtLoaderUsesDefaultWhenInitializedTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            Assert.That(model.AlbumArtStream, Is.Not.SameAs(defaultStream));
            var target = new AlbumArtLoader(container, defaultStream);
            Assert.That(model.AlbumArtStream, Is.SameAs(defaultStream));
        }
        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 override void OnCreate()
 {
     base.OnCreate ();
     Console.SetOut(new AndroidLogTextWriter());
     DataAccess.Configurator.ArtLocalDirectory = CacheDir.AbsolutePath;
     _container = new Athena.IoC.Container();
     _model = new AmpacheModel();
     _container.Register<AmpacheModel>().To(_model);
     DataAccess.Configurator.Configure(_container);
     var am = (AlarmManager)ApplicationContext.GetSystemService(Context.AlarmService);
     var ping = new Intent(PingReceiver.INTENT);
     _pingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, ping, PendingIntentFlags.UpdateCurrent);
     am.SetRepeating(AlarmType.RtcWakeup, Java.Lang.JavaSystem.CurrentTimeMillis() + (long)TimeSpan.FromMinutes(5).TotalMilliseconds, (long)TimeSpan.FromMinutes(5).TotalMilliseconds, _pingIntent);
     var stm = Resources.OpenRawResource(Resource.Drawable.ct_default_artwork);
     var stream = new System.IO.MemoryStream();
     stm.CopyTo(stream);
     stream.Position = 0;
     Start(stream);
     _player = new AndroidPlayer(_model, ApplicationContext);
     _notifications = new AmpacheNotifications(this.ApplicationContext, _model);
     var telSvc = this.ApplicationContext.GetSystemService(Context.TelephonyService) as Android.Telephony.TelephonyManager;
     if(telSvc != null) {
         telSvc.Listen(new AmpachePhoneStateListener(_model), Android.Telephony.PhoneStateListenerFlags.CallState);
     }
 }
 public void BackgroundStartPopulatesModelPlaylistWhenUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var config = new UserConfiguration();
     config.ServerUrl = "test";
     config.User = "******";
     config.Password = "******";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     persister.SelectBy(Arg.Any<int>()).Returns(config);
     container.Register<IPersister<UserConfiguration>>().To(persister);
     var factory = Substitute.For<AmpacheSelectionFactory>();
     factory.AuthenticateToServer(config).Returns(x => (Authenticate)null);
     container.Register<IPersister<UserConfiguration>>();
     var target = new BackgroundHandle(config, path, factory, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     var exp = target.Model.Playlist;
     Assert.That(exp, Is.Not.Null);
 }
 public void BackgroundStartPopulatesModelFactoryWhenUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var config = new UserConfiguration();
     config.ServerUrl = "test";
     config.User = "******";
     config.Password = "******";
     var persister = Substitute.For<IPersister<AmpacheSong>>();
     container.Register<IPersister<AmpacheSong>>().To(persister);
     var configpersist = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(configpersist);
     configpersist.SelectBy(Arg.Any<int>()).Returns(config);
     var sngs = new List<AmpacheSong>();
     sngs.Add(new AmpacheSong(){Url = "http://test"});
     sngs.Add(new AmpacheSong(){Url = "http://test"});
     persister.SelectAll().Returns(sngs);
     var factory = Substitute.For<AmpacheSelectionFactory>();
     factory.AuthenticateToServer(config).Returns(x => (Authenticate)null);
     var mockHs = new MockHandShake();
     mockHs.Setup("test", "test");
     factory.Handshake.Returns(mockHs);
     var target = new BackgroundHandle(config, path, factory, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     var exp = target.Model.Factory;
     Assert.That(exp, Is.Not.Null);
     var userMessage = target.Model.UserMessage;
     Assert.That(userMessage, Is.Not.Null);
     Assert.That(userMessage, Is.EqualTo(BackgroundHandle.SUCCESS_MESSAGE));
     Assert.That(target.Model.Playlist, Is.EquivalentTo(sngs));
 }
 public void BackgroundStartPopulatesModelFactoryWhenNoUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     var exp = target.Model.Factory;
     Assert.That(exp, Is.Not.Null);
 }
 public void BackgroundStartInitializesModelConfigurationTest()
 {
     var container = new Athena.IoC.Container();
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, null, new AmpacheModel(), container);
     var initial = target.Model;
     target.Start(new MemoryStream());
     var after = target.Model.Configuration;
     Assert.That(after, Is.Not.Null);
 }
 public void BackgroundStartBeginsAutoShutOffTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     Assert.That(target.AutoShutOffCallCount, 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 AmpacheSelectionFactory(Athena.IoC.Container container)
 {
     _container = container;
 }
 public Binder(Athena.IoC.Container container)
 {
     Container = container;
 }