Пример #1
0
        public async Task DownloadFileFromCacheNotThereYet()
        {
            var f = new dummyFile();

            f.GetStream = () =>
            {
                throw new InvalidOperationException();
            };

            // Install original data in cache
            var dc   = new dummyCache();
            var data = await TestUtils.GetFileAsBytes("test.pdf");

            await f.SaveFileInCache(f.DateToReturn, data, dc);

            // Create VM's and hook them up.
            var vm     = new FileDownloadController(f, dc);
            var pf     = new PDFFile(vm);
            var dummy1 = pf.NumberOfPages;

            // Start it off
            Debug.WriteLine("FIring the download or update");
            vm.DownloadOrUpdate.Execute(null);

            await pf.WhenAny(x => x.NumberOfPages, x => x.Value)
            .Where(x => x != 0)
            .Timeout(TimeSpan.FromSeconds(1), Observable.Return <int>(0))
            .FirstAsync();

            Assert.AreEqual(10, pf.NumberOfPages);
        }
Пример #2
0
        public async Task CheckTest2()
        {
            var data = await TestUtils.GetFileAsBytes("test2.pdf");

            var f = new dummyFile();

            f.GetStream = () =>
            {
                throw new InvalidOperationException();
            };

            // Install original data in cache
            var dc = new dummyCache();
            await f.SaveFileInCache(f.DateToReturn, data, dc);

            // Create VM's and hook them up.
            var vm     = new FileDownloadController(f, dc);
            var pf     = new PDFFile(vm);
            var dummy1 = pf.NumberOfPages;

            // Start it off
            vm.DownloadOrUpdate.Execute(null);
            await pf.WhenAny(x => x.NumberOfPages, y => y.Value)
            .Where(y => y != 0)
            .Take(1)
            .Timeout(TimeSpan.FromSeconds(1), Observable.Return(0))
            .FirstAsync();

            Assert.AreEqual(6, pf.NumberOfPages);

            // Now, make sure that we still get a "1" out of the update guy.
        }
Пример #3
0
        public async Task GetFileViaCacheSequenceTwice()
        {
            // Pretend a cache miss, and fetch the file to do the render. ANd then
            // do it again.
            var f    = new dummyFile();
            var data = await TestUtils.GetFileAsBytes("test.pdf");

            f.GetStream = () =>
            {
                return(Observable.Return(new StreamReader(new MemoryStream(data))));
            };
            var dc = new dummyCache();
            var vm = new FileDownloadController(f, dc);

            var pf     = new PDFFile(vm);
            var dummy1 = pf.NumberOfPages;

            vm.DownloadOrUpdate.Execute(null);

            await pf.WhenAny(x => x.NumberOfPages, y => y.Value)
            .Where(y => y != 0)
            .Take(1)
            .Timeout(TimeSpan.FromSeconds(1), Observable.Return(0))
            .FirstAsync();

            Assert.AreEqual(10, pf.NumberOfPages);

            var pupdate = await pf.GetPageStreamAndCacheInfo(5).Timeout(TimeSpan.FromSeconds(1)).FirstAsync();

            // First rendering
            var page = await pupdate.Item2.FirstAsync();

            // Get the # of times we've done a data lookup. And this shouldn't change when we get it again.
            var getCalls = dc.NumberTimesGetCalled;

            Debug.WriteLine("Get was called {0} times after first page was rendered.", getCalls);
            var pageAgain = await pupdate.Item2.FirstAsync();

            Assert.AreEqual(getCalls, dc.NumberTimesGetCalled);
        }