Example #1
0
            public async Task ThrowsArgumentNullExceptionIfKeyIsNull()
            {
                var blobCache = new TestBlobCache();
                var artworkCache = new ArtworkCache(blobCache);

                await Helpers.ThrowsAsync<ArgumentNullException>(() => artworkCache.Retrieve(null, 100, 100));
            }
Example #2
0
        static BlobCache()
        {
            if (RxApp.InUnitTestRunner())
            {
                localMachine = new TestBlobCache(RxApp.TaskpoolScheduler);
                userAccount = new TestBlobCache(RxApp.TaskpoolScheduler);
                secure = new TestBlobCache(RxApp.TaskpoolScheduler);
                return;
            }
            
            var namespaces = AttemptToEarlyLoadAkavacheDLLs();

            foreach(var ns in namespaces) {
                #if WINRT
                var assm = typeof (BlobCache).GetTypeInfo().Assembly;
                #else
                var assm = Assembly.GetExecutingAssembly();
                #endif
                var fullName = typeof(BlobCache).AssemblyQualifiedName;
                var targetType = ns + ".ServiceLocationRegistration";
                fullName = fullName.Replace("Akavache.BlobCache", targetType);
                fullName = fullName.Replace(assm.FullName, assm.FullName.Replace("Akavache", ns));
                
                var registerTypeClass = Reflection.ReallyFindType(fullName, false);
                if (registerTypeClass != null) {
                    var registerer = (IWantsToRegisterStuff) Activator.CreateInstance(registerTypeClass);
                    registerer.Register();
                }
            }
        }
        public void SuccessfulLoginIntegrationTest()
        {
            var kernel = new MoqMockingKernel();
            kernel.Bind<IWelcomeViewModel>().To<WelcomeViewModel>();

            var cache = new TestBlobCache(null, (IEnumerable<KeyValuePair<string, byte[]>>)null);
            kernel.Bind<ISecureBlobCache>().ToConstant(cache);

            var mock = kernel.GetMock<IScreen>();
            var routingState = new RoutingState();
            mock.Setup(x => x.Router).Returns(routingState);

            var initialPage = kernel.Get<IRoutableViewModel>();
            kernel.Get<IScreen>().Router.NavigateAndReset.Execute(initialPage);

            var fixture = kernel.Get<IWelcomeViewModel>();
            kernel.Get<IScreen>().Router.Navigate.Execute(fixture);

            fixture.BaseUrl = IntegrationTestUrl.Current;
            fixture.Token = IntegrationTestUrl.Token;
            fixture.OkButton.Execute(null);

            kernel.Get<IScreen>().Router.ViewModelObservable().Skip(1)
                .Timeout(TimeSpan.FromSeconds(10.0), RxApp.TaskpoolScheduler)
                .First();

            fixture.ErrorMessage.Should().BeNull();
            kernel.Get<IScreen>().Router.GetCurrentViewModel().Should().Be(initialPage);
        }
Example #4
0
        public async Task ProcessSingleBuildThatFails()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));
            var stdout = new Subject<string>();
            var allLines = stdout.CreateCollection();

            var fixture = new BuildQueue(client, cache);
            var result = default(int);
            bool shouldDie = true;

            try {
                // NB: This build fails because NuGet package restore wasn't set 
                // up properly, so MSBuild is missing a ton of assemblies
                result = await fixture.ProcessSingleBuild(new BuildQueueItem() {
                    BuildId = 1,
                    BuildScriptUrl = TestBuild.BuildScriptUrl,
                    RepoUrl = TestBuild.RepoUrl,
                    SHA1 = TestBuild.FailingBecauseOfMsbuildSHA1,
                }, stdout);
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
                shouldDie = false;
            }

            var output = allLines.Aggregate(new StringBuilder(), (acc, x) => { acc.AppendLine(x); return acc; }).ToString();
            Console.WriteLine(output);

            Assert.False(shouldDie);
        }
Example #5
0
        public static TestBlobCache OverrideGlobals(IScheduler scheduler = null, params KeyValuePair <string, byte[]>[] initialContents)
        {
            var local = BlobCache.LocalMachine;
            var user  = BlobCache.UserAccount;

#if !SILVERLIGHT
            var sec = BlobCache.Secure;
#endif

            var resetBlobCache = new Action(() =>
            {
                BlobCache.LocalMachine = local;
#if !SILVERLIGHT
                BlobCache.Secure = sec;
#endif
                BlobCache.UserAccount = user;
                Monitor.Exit(gate);
            });

            var testCache = new TestBlobCache(resetBlobCache, scheduler, initialContents);
            BlobCache.LocalMachine = testCache;
#if !SILVERLIGHT
            BlobCache.Secure = testCache;
#endif
            BlobCache.UserAccount = testCache;

            Monitor.Enter(gate);
            return(testCache);
        }
Example #6
0
        static BlobCache()
        {
            // XXX: This is a hella hack
            var mutableRegistration = RxApp.DependencyResolver as IMutableDependencyResolver;
            mutableRegistration.InitializeAkavache();

            InMemory = new TestBlobCache(RxApp.TaskpoolScheduler);
        }
Example #7
0
            public async Task FailedRequestThrowsException()
            {
                var fetcher = Substitute.For<IArtworkFetcher>();
                fetcher.RetrieveAsync(Arg.Any<string>(), Arg.Any<string>()).Returns(Observable.Throw<Uri>(new ArtworkFetchException(String.Empty, null)).ToTask());
                var blobCache = new TestBlobCache();
                var fixture = new ArtworkCache(blobCache, fetcher);

                await Helpers.ThrowsAsync<ArtworkCacheException>(() => fixture.FetchOnline("A", "B"));
            }
Example #8
0
 static BlobCache()
 {
     if (RxApp.InUnitTestRunner())
     {
         localMachine = new TestBlobCache(RxApp.TaskpoolScheduler);
         userAccount  = new TestBlobCache(RxApp.TaskpoolScheduler);
         secure       = new TestBlobCache(RxApp.TaskpoolScheduler);
     }
 }
Example #9
0
        public async Task FullBuildIntegrationTest()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache);
            using (fixture.Start()) {
                var result = await fixture.Enqueue(TestBuild.RepoUrl, TestBuild.PassingBuildSHA1, TestBuild.BuildScriptUrl);
            }
        }
Example #10
0
            public async Task NotFoundRequestReturnsNull()
            {
                var fetcher = Substitute.For<IArtworkFetcher>();
                fetcher.RetrieveAsync(Arg.Any<string>(), Arg.Any<string>()).Returns(Task.FromResult<Uri>(null));
                var blobCache = new TestBlobCache();
                var fixture = new ArtworkCache(blobCache, fetcher);

                string returned = await fixture.FetchOnline("A", "B");

                Assert.Null(returned);
            }
Example #11
0
        static BlobCache()
        {
            if (RxApp.InUnitTestRunner())
            {
                localMachine = new TestBlobCache(RxApp.TaskpoolScheduler);
                userAccount  = new TestBlobCache(RxApp.TaskpoolScheduler);
#if !SILVERLIGHT
                secure = new TestBlobCache(RxApp.TaskpoolScheduler);
#endif
            }
        }
Example #12
0
        static BlobCache()
        {
            // XXX: This is a hella hack
            var mutableRegistration = RxApp.DependencyResolver as IMutableDependencyResolver;
            if (RxApp.DependencyResolver.GetService<IAkavacheHttpMixin>() == null && mutableRegistration != null)
            {
                mutableRegistration.InitializeAkavache();
            }

            InMemory = new TestBlobCache(RxApp.TaskpoolScheduler);
        }
Example #13
0
 static BlobCache()
 {
     if (RxApp.InUnitTestRunner())
     {
         localMachine = new TestBlobCache(RxApp.TaskpoolScheduler);
         userAccount = new TestBlobCache(RxApp.TaskpoolScheduler);
     #if !SILVERLIGHT
         secure = new TestBlobCache(RxApp.TaskpoolScheduler);
     #endif
     }
 }
Example #14
0
        static BlobCache()
        {
            // XXX: Everything is dumb. This is to trick RxUI into running its setup stuff in the ctor.
            LogHost.Default.Debug("Scheduler is {0}, Dep Resolver is {1}", RxApp.TaskpoolScheduler, RxApp.DependencyResolver);

            if (RxApp.DependencyResolver.GetService<IAkavacheHttpMixin>() == null && RxApp.MutableResolver != null)
            {
                RxApp.MutableResolver.InitializeAkavache();
            }

            InMemory = new TestBlobCache(RxApp.TaskpoolScheduler);
        }
Example #15
0
        static BlobCache()
        {
            // XXX: Everything is dumb. This is to trick RxUI into running its setup stuff in the ctor.
            LogHost.Default.Debug("Scheduler is {0}, Dep Resolver is {1}", RxApp.TaskpoolScheduler, RxApp.DependencyResolver);

            if (RxApp.DependencyResolver.GetService <IAkavacheHttpMixin>() == null && RxApp.MutableResolver != null)
            {
                RxApp.MutableResolver.InitializeAkavache();
            }

            InMemory = new TestBlobCache(RxApp.TaskpoolScheduler);
        }
Example #16
0
            public async Task NotFoundRequestIsMarked()
            {
                var fetcher = Substitute.For<IArtworkFetcher>();
                fetcher.RetrieveAsync(Arg.Any<string>(), Arg.Any<string>()).Returns(Task.FromResult<Uri>(null));
                var blobCache = new TestBlobCache();
                var fixture = new ArtworkCache(blobCache, fetcher);
                string artist = "A";
                string album = "B";
                string lookupKey = BlobCacheKeys.GetKeyForOnlineArtwork(artist, album);

                await fixture.FetchOnline(artist, album);

                Assert.Equal("FAILED", await blobCache.GetObjectAsync<string>(lookupKey));
            }
Example #17
0
            public async Task PullsSearchesFromCache()
            {
                string artist = "A";
                string album = "B";
                string key = BlobCacheKeys.GetKeyForOnlineArtwork(artist, album);
                var fetcher = Substitute.For<IArtworkFetcher>();
                var blobCache = new TestBlobCache();
                await blobCache.InsertObject(key, "TestArtworkKey");
                var fixture = new ArtworkCache(blobCache, fetcher);

                string returned = await fixture.FetchOnline(artist, album);

                Assert.Equal("TestArtworkKey", returned);
                fetcher.DidNotReceiveWithAnyArgs().RetrieveAsync(null, null);
            }
        public void NavigatingToPlayWithoutAPasswordShouldNavigateToLogin()
        {
            var kernel = new MoqMockingKernel();
            kernel.Bind<IPlayViewModel>().To<PlayViewModel>();

            var cache = new TestBlobCache(null, (IEnumerable<KeyValuePair<string, byte[]>>)null);
            kernel.Bind<ISecureBlobCache>().ToConstant(cache);

            kernel.GetMock<ILoginMethods>()
                .Setup(x => x.EraseCredentialsAndNavigateToLogin()).Verifiable();

            var router = new RoutingState();
            kernel.GetMock<IScreen>().Setup(x => x.Router).Returns(router);

            var fixture = kernel.Get<IPlayViewModel>();
            router.Navigate.Execute(fixture);
            kernel.GetMock<ILoginMethods>().Verify(x => x.EraseCredentialsAndNavigateToLogin(), Times.Once());
        }
Example #19
0
        public static TestBlobCache OverrideGlobals(IScheduler scheduler = null, params KeyValuePair<string, byte[]>[] initialContents)
        {
            var local = BlobCache.LocalMachine;
            var user = BlobCache.UserAccount;
            var sec = BlobCache.Secure;

            var resetBlobCache = new Action(() =>
            {
                BlobCache.LocalMachine = local;
                BlobCache.Secure = sec;
                BlobCache.UserAccount = user;
            });

            var testCache = new TestBlobCache(resetBlobCache, scheduler, initialContents);
            BlobCache.LocalMachine = testCache;
            BlobCache.Secure = testCache;
            BlobCache.UserAccount = testCache;

            return testCache;
        }
Example #20
0
        public async Task ProcessSingleBuildIntegrationTest()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));
            var stdout = new Subject<string>();
            var allLines = stdout.CreateCollection();

            var fixture = new BuildQueue(client, cache);
            var result = await fixture.ProcessSingleBuild(new BuildQueueItem() {
                BuildId = 1,
                BuildScriptUrl = TestBuild.BuildScriptUrl,
                RepoUrl = TestBuild.RepoUrl,
                SHA1 = TestBuild.PassingBuildSHA1,
            }, stdout);

            var output = allLines.Aggregate(new StringBuilder(), (acc, x) => { acc.AppendLine(x); return acc; }).ToString();
            Console.WriteLine(output);

            Assert.Equal(0, result);
            Assert.False(String.IsNullOrWhiteSpace(output));
        }
Example #21
0
        public static TestBlobCache OverrideGlobals(IScheduler scheduler = null, params KeyValuePair<string, byte[]>[] initialContents)
        {
            var local = BlobCache.LocalMachine;
            var user = BlobCache.UserAccount;
            var sec = BlobCache.Secure;

            var resetBlobCache = new Action(() =>
            {
                BlobCache.LocalMachine = local;
                BlobCache.Secure = sec;
                BlobCache.UserAccount = user;
                Monitor.Exit(gate);
            });

            var testCache = new TestBlobCache(resetBlobCache, scheduler, initialContents);
            BlobCache.LocalMachine = testCache;
            BlobCache.Secure = testCache;
            BlobCache.UserAccount = testCache;

            Monitor.Enter(gate);
            return testCache;
        }
        IKernel createDefaultKernel()
        {
            var ret = new StandardKernel();

            ret.Bind<IScreen>().ToConstant(this);
            ret.Bind<ILoginMethods>().ToConstant(this);
            ret.Bind<IWelcomeViewModel>().To<WelcomeViewModel>();
            ret.Bind<IPlayViewModel>().To<PlayViewModel>();
            ret.Bind<ISearchViewModel>().To<SearchViewModel>();
            ret.Bind<IViewForViewModel<WelcomeViewModel>>().To<WelcomeView>();
            ret.Bind<IViewForViewModel<PlayViewModel>>().To<PlayView>();
            ret.Bind<IViewForViewModel<SearchViewModel>>().To<SearchView>();
            ret.Bind<IViewForViewModel<SongTileViewModel>>().To<SongTileView>().InTransientScope();

            #if DEBUG
            var testBlobCache = new TestBlobCache();
            ret.Bind<IBlobCache>().ToConstant(testBlobCache).Named("LocalMachine");
            ret.Bind<IBlobCache>().ToConstant(testBlobCache).Named("UserAccount");
            ret.Bind<ISecureBlobCache>().ToConstant(testBlobCache);
            #else
            ret.Bind<ISecureBlobCache>().ToConstant(BlobCache.Secure);
            ret.Bind<IBlobCache>().ToConstant(BlobCache.LocalMachine).Named("LocalMachine");
            ret.Bind<IBlobCache>().ToConstant(BlobCache.UserAccount).Named("UserAccount");
            #endif

            return ret;
        }
        public void SucceededLoginSetsTheCurrentAuthenticatedClient()
        {
            var kernel = new MoqMockingKernel();
            kernel.Bind<IWelcomeViewModel>().To<WelcomeViewModel>();

            string expectedUser = "******";
            string expectedUrl = "http://bar";

            kernel.Bind<Func<string, string, IObservable<Unit>>>()
                .ToConstant<Func<string, string, IObservable<Unit>>>((url, user) => Observable.Return<Unit>(Unit.Default))
                .Named("connectToServer");

            var mock = kernel.GetMock<IScreen>();
            var routingState = new RoutingState();
            mock.Setup(x => x.Router).Returns(routingState);

            kernel.Bind<IScreen>().ToConstant(mock.Object);

            var initialPage = kernel.Get<IRoutableViewModel>();
            kernel.Get<IScreen>().Router.NavigateAndReset.Execute(initialPage);

            var cache = new TestBlobCache(null, (IEnumerable<KeyValuePair<string, byte[]>>)null);
            kernel.Bind<ISecureBlobCache>().ToConstant(cache);

            var fixture = kernel.Get<IWelcomeViewModel>();
            kernel.Get<IScreen>().Router.Navigate.Execute(fixture);

            bool errorThrown = false;
            using (UserError.OverrideHandlersForTesting(ex => { errorThrown = true; return Observable.Return(RecoveryOptionResult.CancelOperation); })) {
                fixture.Token = expectedUser;
                fixture.BaseUrl = expectedUrl;
                fixture.OkButton.Execute(null);
            }

            errorThrown.Should().BeFalse();

            kernel.Get<IScreen>().Router.GetCurrentViewModel().Should().Be(initialPage);
            kernel.GetMock<ILoginMethods>().Verify(x => x.SaveCredentials(expectedUrl, expectedUser), Times.Once());
        }
Example #24
0
            public async Task NullDataThrowsArgumentNullException()
            {
                var blobCache = new TestBlobCache();
                var artworkCache = new ArtworkCache(blobCache);

                await Helpers.ThrowsAsync<ArgumentNullException>(() => artworkCache.Store(null));
            }
Example #25
0
        public async Task BuildOutputForUnknownBuildsShouldThrow()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache, (q, o) => {
                return Task.FromResult(0);
            });

            bool shouldDie = true;
            try {
                await fixture.GetBuildOutput(42);
            } catch (Exception) {
                shouldDie = false;
            }

            Assert.False(shouldDie);
        }
Example #26
0
            public async Task StoresArtworkInBlobCache()
            {
                var blobCache = new TestBlobCache();
                var artworkCache = new ArtworkCache(blobCache);

                var data = new byte[] { 0, 1 };

                string key = await artworkCache.Store(data);

                Assert.Equal(data, await blobCache.GetAsync(key));
            }
Example #27
0
        public async Task BuildsThatSucceedShouldBeRecorded()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache, (q, o) => {
                return Task.FromResult(0);
            });

            fixture.Start();

            var queueItem = await fixture.Enqueue(TestBuild.RepoUrl, TestBuild.PassingBuildSHA1, TestBuild.BuildScriptUrl);

            Assert.NotNull(queueItem);
            Assert.True(queueItem.BuildSucceded.Value);

            fixture = new BuildQueue(client, cache);
            var result = await fixture.GetBuildOutput(queueItem.BuildId);

            Assert.Equal(0, result.Item2);
        }
Example #28
0
        public async Task BuildsThatFailShouldBeRecorded()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache, async (q, o) => {
                throw new Exception("Didn't work lol");
            });

            fixture.Start();

            var queueItem = await fixture.Enqueue(TestBuild.RepoUrl, TestBuild.PassingBuildSHA1, TestBuild.BuildScriptUrl);

            Assert.NotNull(queueItem);
            Assert.False(queueItem.BuildSucceded.Value);

            fixture = new BuildQueue(client, cache);
            var result = await fixture.GetBuildOutput(queueItem.BuildId);

            Assert.True(result.Item1.Contains("Didn't work lol"));
            Assert.NotEqual(0, result.Item2);
        }