/// <summary> /// Generate a number of MakeDownloaders. /// </summary> /// <param name="count"></param> /// <returns></returns> private static async Task <PDFFile[]> MakeDownloaders(int count) { // In this test we make sure not to access the # of pages. Func <Task <PDFFile> > creator = async() => { 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); vm.DownloadOrUpdate.Execute(null); return(new PDFFile(vm)); }; List <PDFFile> r = new List <PDFFile>(); for (int i = 0; i < count; i++) { r.Add(await creator()); } return(r.ToArray()); }
public async Task TriggerSuccessfulFileDownloadCached() { var f = new dummyFile(); var data = new byte[] { 0, 1, 2, 3 }; var mr = new MemoryStream(data); f.GetStream = () => Observable.Return(new StreamReader(mr)); var dc = new dummyCache(); await f.SaveFileInCache(DateTime.Now.ToString(), new byte[] { 0, 1, 2 }, dc); var vm = new FileDownloadController(f, dc); var dummy = vm.IsDownloaded; int downloadUpdateCount = 0; vm.FileDownloadedAndCached.Subscribe(_ => downloadUpdateCount++); vm.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => vm.IsDownloaded == true, 1000); Assert.IsTrue(vm.IsDownloaded); await TestUtils.SpinWait(() => downloadUpdateCount == 1, 1000); Assert.AreEqual(1, downloadUpdateCount); }
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. }
public async Task DownloadCalledOnceOnCacheUpdate() { var f = new dummyFile(); f.GetStream = () => { var data = new byte[] { 0, 1, 2, 3 }; var mr = new MemoryStream(data); Debug.WriteLine("Just called GetStream"); return(Observable.Return(new StreamReader(mr))); }; var dc = new dummyCache(); await f.SaveFileInCache(DateTime.Now.ToString(), new byte[] { 0, 1 }, dc); var vm = new FileDownloadController(f, dc); int isDownloadingCounter = 0; vm.WhenAny(x => x.IsDownloading, x => x.Value) .Subscribe(_ => isDownloadingCounter++); var dummy = vm.IsDownloaded; var dummy1 = vm.IsDownloading; vm.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => f.GetStreamCalled == 1, 1000); Assert.AreEqual(1, f.GetStreamCalled); }
public async Task MonitorPageUpdateLateRenderRequest() { // In this test we make sure not to access the # of pages. 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); // Setup the look before we setup the render. var pupdatetmp = pf.GetPageStreamAndCacheInfo(5).Timeout(TimeSpan.FromSeconds(5)).FirstAsync(); vm.DownloadOrUpdate.Execute(null); var pupdate = await pupdatetmp; // Make sure what came back looks ok! Assert.IsNotNull(pupdate); var page = await pupdate.Item2.FirstAsync(); Assert.AreEqual(5, (int)page.Index); }
public async Task LoadVMButNoImageLoad() { // WHen this VM isn't attached to a actual View, we should not // trigger any loading or similar. All should remain very quiet. // (e.g. lazy loading). // Get the infrastructure setup var f = new dummyFile(); var data = await TestUtils.GetFileAsBytes("test.pdf"); int timesLoaded = 0; f.GetStream = () => { timesLoaded++; return(Observable.Return(new StreamReader(new MemoryStream(data)))); }; var dc = new dummyCache(); var vm = new FileDownloadController(f, dc); vm.DownloadOrUpdate.Execute(null); var pf = new PDFFile(vm); // Now, build the VM var pdfVM = new PDFPageViewModel(pf.GetPageStreamAndCacheInfo(1), dc); await TestUtils.SpinWait(() => timesLoaded != 0, 1000); Assert.AreEqual(1, timesLoaded); Assert.AreEqual(0, dc.NumberTimesGetCalled); }
public async Task MonitorPageUpdateEarlyRenderRequest() { // In this test we make sure not to access the # of pages. 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); // Run the download (which will complete synchronously here), and then schedule the watch // for new items. vm.DownloadOrUpdate.Execute(null); var pupdate = await pf.GetPageStreamAndCacheInfo(5).Timeout(TimeSpan.FromSeconds(5)).FirstAsync(); // Make sure all that came back is ok. Assert.IsNotNull(pupdate); var page = await pupdate.Item2.FirstAsync(); Assert.AreEqual(5, (int)page.Index); }
public async Task SizePerpareCausesErrorsIfCalledEarly() { // Get the size stuff ready, and then call it to make sure // there are no issues with doing the size calculation. // Get the infrastructure setup 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); vm.DownloadOrUpdate.Execute(null); // Now, build the VM var pdfVM = new PDFPageViewModel(pf.GetPageStreamAndCacheInfo(1), dc); // Next, fire off the size thing. var r = pdfVM.CalcRenderingSize(IWalker.ViewModels.PDFPageViewModel.RenderingDimension.Horizontal, (double)100, (double)100); Assert.IsNull(r); }
public async Task TriggerSuccessfulFIleDownloadCheckLate() { var f = new dummyFile(); var data = new byte[] { 0, 1, 2, 3 }; var mr = new MemoryStream(data); f.GetStream = () => Observable.Return(new StreamReader(mr)); var vm = new FileDownloadController(f, new dummyCache()); int downloadUpdateCount = 0; vm.FileDownloadedAndCached.Subscribe(_ => downloadUpdateCount++); vm.DownloadOrUpdate.Execute(null); // ReactiveUI won't cause a "subscription" until this is first accessed. // Make sure that it reflects the fact that it is downloaded, even though // the trigger for this happens earlier. var bogus = vm.IsDownloaded; await TestUtils.SpinWait(() => vm.IsDownloaded == true, 1000); await TestUtils.SpinWait(() => downloadUpdateCount == 1, 1000); Assert.AreEqual(1, downloadUpdateCount); }
public async Task WaitForFirstSlideAfterReady() { // Get the dummy file and input real PDF data. // Hook it up to the download controller 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 fdc = new FileDownloadController(f, dc); var pf = new PDFFile(fdc); var dummy1 = pf.NumberOfPages; // Run the download fdc.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => pf.NumberOfPages != 0, 1000); // The first spin guy var hero = new FirstSlideHeroViewModel(pf, null); // Make sure the thing is ready now. await TestUtils.SpinWait(() => hero.HeroPageUC != null, 1000); }
public void SetupTesting() { // Turn off auto-download to make sure that we control when a download occurs // for various tests. Settings.AutoDownloadNewMeeting = false; FileDownloadController.Reset(); }
public async Task CheckCacheLookupHappensOnce() { // When we have an item that is cached, we shouldn't do the full load // too many times, (once) when looking at only the page number. var f = new dummyFile(); var data = await TestUtils.GetFileAsBytes("test.pdf"); 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 TestUtils.SpinWait(() => pf.NumberOfPages == 10, 1000); // Now, make sure we did it only once. // TODO: Currently this is 2 b.c. there is a second lookup for a date, which also includes // going after the file data. This should get fixed and split the database up. Assert.AreEqual(3, dc.NumberTimesGetCalled); }
public async Task CheckDateCalledOnceCacheFilled() { var f = new dummyFile(); f.GetStream = () => { var data = new byte[] { 0, 1, 2, 3 }; var mr = new MemoryStream(data); return(Observable.Return(new StreamReader(mr))); }; var dc = new dummyCache(); await f.SaveFileInCache(f.DateToReturn, new byte[] { 0, 1, 2 }, dc); var vm = new FileDownloadController(f, dc); int isDownloadingCounter = 0; vm.WhenAny(x => x.IsDownloading, x => x.Value) .Subscribe(_ => isDownloadingCounter++); var dummy = vm.IsDownloaded; var dummy1 = vm.IsDownloading; vm.DownloadOrUpdate.Execute(null); Assert.AreEqual(1, f.GetDateCalled); }
public async Task CheckDateCalledOnceCacheEmpty() { var f = new dummyFile(); f.GetStream = () => { var data = new byte[] { 0, 1, 2, 3 }; var mr = new MemoryStream(data); return(Observable.Return(new StreamReader(mr))); }; var dc = new dummyCache(); var vm = new FileDownloadController(f, dc); int isDownloadingCounter = 0; vm.WhenAny(x => x.IsDownloading, x => x.Value) .Subscribe(_ => isDownloadingCounter++); var dummy = vm.IsDownloaded; var dummy1 = vm.IsDownloading; vm.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => f.GetDateCalled == 0, 100); await Task.Delay(100); // Just in case. :-) Assert.AreEqual(0, f.GetDateCalled); }
public async Task ButtonNotGoodTillDownload() { // Build a PDF file that will only download after we ask it to. 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 pdf = new PDFFile(vm); // Open a single talk and see if we can see it open. var now = new TimePeriod(DateTime.Now, DateTime.Now + TimeSpan.FromSeconds(1000)); var exp = new ExpandingSlideThumbViewModel(pdf, now); // Make sure there are no slides - also primes the pump for Rx. Assert.IsNull(exp.TalkAsThumbs); await TestUtils.SpinWait(() => exp.CanShowThumbs == false, 1000); // Now, make sure that things go "true" after we fire off the file. vm.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => exp.CanShowThumbs == true, 1000); }
public async Task TestFileUpdated() { // First, we need to get the file into the cache. Use the infrastructure to do that. var df = new dummyFile("test.pdf", "test.pdf"); var data = await TestUtils.GetFileAsBytes("test.pdf"); await df.SaveFileInCache(df.DateToReturn, data, Blobs.LocalStorage); // Now, we are going to update the cache, and see if it gets re-read. df.DateToReturn = "this is the second one"; var dfctl = new FileDownloadController(df); var pdfFile = new PDFFile(dfctl); var vm = new FileSlideListViewModel(pdfFile, new TimePeriod(DateTime.Now, DateTime.Now)); var list = vm.SlideThumbnails; Assert.IsNotNull(list); Assert.AreEqual(0, list.Count); dfctl.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => list.Count != 0, 200); await Task.Delay(10); Assert.AreEqual(10, list.Count); // 2 - when we do the update. Assert.AreEqual(1, df.GetStreamCalled); }
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); }
public async Task TestFileNoAutoDownload() { // Cached file, even if no auto upload, should be checked against the internet. Settings.AutoDownloadNewMeeting = false; var df = new dummyFile("test.pdf", "test.pdf"); var data = await TestUtils.GetFileAsBytes("test.pdf"); await df.SaveFileInCache(df.DateToReturn, data, Blobs.LocalStorage); // Now, we are going to update the cache, and see if it gets re-read (which it should since we have it) df.DateToReturn = "this is the second one"; var dfctl = new FileDownloadController(df); var pdfFile = new PDFFile(dfctl); var vm = new FileSlideListViewModel(pdfFile, new TimePeriod(DateTime.Now, DateTime.Now)); var list = vm.SlideThumbnails; Assert.IsNotNull(list); Assert.AreEqual(0, list.Count); dfctl.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => list.Count != 0, 200); await Task.Delay(10); Assert.AreEqual(10, list.Count); Assert.AreEqual(1, df.GetStreamCalled); }
public async Task FetchSlideOnlyOnce() { // Subscribe to all the slides and get back MemoryStreams for all of them // to stress out the simultaneous reading of everything. var df = new dummyFile("test.pdf", "test.pdf"); var dfctl = new FileDownloadController(df); dfctl.DownloadOrUpdate.Execute(null); var pdfFile = new PDFFile(dfctl); var vm = new FileSlideListViewModel(pdfFile, new TimePeriod(DateTime.Now, DateTime.Now)); var list = vm.SlideThumbnails; // Listen for everything to be rendered. var allImages = list .Select(item => item.PDFPageVM.ImageStream.Where(i => i != null)) .Select(strm => strm.FirstAsync()) .Select(async stream => await stream) .ToArray(); // Fire off the rendering of everything var renderOptions = Tuple.Create(PDFPageViewModel.RenderingDimension.Horizontal, (double)150, (double)150); foreach (var item in list) { item.PDFPageVM.RenderImage.Execute(renderOptions); } // And now wait for everything. await Task.WhenAll(allImages); // Make sure we had to download the file only once. Assert.AreEqual(1, df.GetStreamCalled); }
public void NoFileDownloadedIsNotCached() { var f = new dummyFile(); var vm = new FileDownloadController(f, new dummyCache()); var dummy = vm.IsDownloaded; Assert.IsFalse(vm.IsDownloaded); }
public async Task MakeSureNothingRenderedWhenImageCached() { // The exact image we need is in the cache. So we should never make a // request to load the PDF file or PdfDocument. // Get the infrastructure setup var f = new dummyFile(); var data = await TestUtils.GetFileAsBytes("test.pdf"); int loaderCalled = 0; f.GetStream = () => { loaderCalled++; throw new InvalidOperationException(); }; // Create the cache, and add everything into it that the system should need. var dc = new dummyCache(); await f.SaveFileInCache(f.DateToReturn, data, dc); var dt = await f.GetCacheCreateTime(dc); var pageSize = new IWalkerSize() { Width = 1280, Height = 720 }; await dc.InsertObject(string.Format("{0}-{1}-p1-DefaultPageSize", f.UniqueKey, dt.Value.ToString()), pageSize); var imageData = new byte[] { 0, 1, 2, 3, 4 }; await dc.Insert(string.Format("{0}-{1}-p1-w100-h56", f.UniqueKey, dt.Value), imageData); Debug.WriteLine("Setup is done, and data has been inserted into the cache. Testing starting"); // Create the rest of the infrastructure. var vm = new FileDownloadController(f, dc); var pf = new PDFFile(vm); // Now, build the VM var pdfVM = new PDFPageViewModel(pf.GetPageStreamAndCacheInfo(1), dc); // Subscribe so we can "get" the image. MemoryStream lastImage = null; pdfVM.ImageStream.Subscribe(img => lastImage = img); Assert.IsNull(lastImage); // Render, and make sure things "worked" pdfVM.RenderImage.Execute(Tuple.Create(IWalker.ViewModels.PDFPageViewModel.RenderingDimension.Horizontal, (double)100, (double)100)); vm.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => lastImage != null, 2000); Assert.AreEqual(0, loaderCalled); Assert.IsNotNull(lastImage); Assert.AreEqual(4, dc.NumberTimesInsertCalled); // Nothing new should have happened }
public void CtorHasNothingAccessedNoCache() { var f = new dummyFile(); var dc = new dummyCache(); var vm = new FileDownloadController(f, dc); Assert.AreEqual(0, f.GetDateCalled); Assert.AreEqual(0, f.GetStreamCalled); }
public async Task RenderNormalRenderEarlyTrigger() { // Normal sequence of things when there is no image cached. // WHen this VM isn't attached to a actual View, we should not // trigger any loading or similar. All should remain very quiet. // (e.g. lazy loading). // Get the infrastructure setup var f = new dummyFile(); var data = await TestUtils.GetFileAsBytes("test.pdf"); int timesLoaded = 0; f.GetStream = () => { timesLoaded++; return(Observable.Return(new StreamReader(new MemoryStream(data)))); }; var dc = new dummyCache(); var vm = new FileDownloadController(f, dc); // It shouldn't matter where the download is triggered from - let it happen early // here before other things are hooked up. vm.DownloadOrUpdate.Execute(null); var pf = new PDFFile(vm); // Now, build the VM var pdfVM = new PDFPageViewModel(pf.GetPageStreamAndCacheInfo(1), dc); // Subscribe so we can "get" the image. MemoryStream lastImage = null; Debug.WriteLine("Subscribing to ImageStream"); pdfVM.ImageStream.Subscribe(img => { lastImage = img; Debug.WriteLine("Just got an image."); }); Assert.IsNull(lastImage); // Render, and make sure things "worked" Debug.WriteLine("Going to fire off a render request"); pdfVM.RenderImage.Execute(Tuple.Create(IWalker.ViewModels.PDFPageViewModel.RenderingDimension.Horizontal, (double)100, (double)100)); await TestUtils.SpinWait(() => timesLoaded != 0, 1000); await TestUtils.SpinWait(() => dc.NumberTimesGetCalled == 3, 1000); await TestUtils.SpinWait(() => lastImage != null, 1000); Assert.AreEqual(1, timesLoaded); Assert.AreEqual(3, dc.NumberTimesGetCalled); // Once for data, once for size cache, and once again for data file. Assert.IsNotNull(lastImage); }
public async Task CtorHasNothingAccessedCache() { var f = new dummyFile(); var dc = new dummyCache(); await f.SaveFileInCache(f.DateToReturn, new byte[] { 0, 1, 2, 3 }, dc); var vm = new FileDownloadController(f, dc); Assert.AreEqual(0, f.GetDateCalled); Assert.AreEqual(0, f.GetStreamCalled); }
public async Task IsDownloadingFlipsCorrectly() { // http://stackoverflow.com/questions/21588945/structuring-tests-or-property-for-this-reactive-ui-scenario var f = new dummyFile(); var newSR = new Subject <StreamReader>(); f.GetStream = () => { return(newSR); }; var dc = new dummyCache(); var vm = new FileDownloadController(f, dc); var dummy = vm.IsDownloaded; var dummy1 = vm.IsDownloading; Assert.IsFalse(vm.IsDownloading); Assert.IsFalse(vm.IsDownloaded); // Fire off the download Debug.WriteLine("Starting download/update"); vm.DownloadOrUpdate.Execute(null); // Since the download is synchronous, it should get here just fine. await TestUtils.SpinWait(() => vm.IsDownloading == true, 1000); await TestUtils.SpinWait(() => vm.IsDownloaded == false, 1000); Assert.IsTrue(vm.IsDownloading); Assert.IsFalse(vm.IsDownloaded); Debug.WriteLine("Going to wait a bit here"); await Task.Delay(1000); // And now stuff the data in. Debug.WriteLine("Going to send the data one"); var data = new byte[] { 0, 1, 2, 3 }; var mr = new MemoryStream(data); newSR.OnNext(new StreamReader(mr)); newSR.OnCompleted(); Debug.WriteLine("Done sending the data along"); // And make sure it finishes. await TestUtils.SpinWait(() => vm.IsDownloaded == true, 1000); Assert.IsTrue(vm.IsDownloaded); Assert.IsFalse(vm.IsDownloading); }
public async Task FileDownlaodedIsCached() { var f = new dummyFile(); var dc = new dummyCache(); await f.SaveFileInCache(DateTime.Now.ToString(), new byte[] { 0, 1 }, dc); var vm = new FileDownloadController(f, dc); bool value = false; var dispose = vm.WhenAny(x => x.IsDownloaded, y => y.Value) .Subscribe(v => value = v); await TestUtils.SpinWait(() => vm.IsDownloaded == true, 1000); await TestUtils.SpinWait(() => value == true, 1000); dispose.Dispose(); }
public async Task ShowSlidesInSecondTalkCausesFirstNonDownloadedToShowButton() { // The normal one, that will download and whose button we can press. var now = new TimePeriod(DateTime.Now, DateTime.Now + TimeSpan.FromSeconds(1000)); var pf = await MakeDownloaders(1); var exp1 = pf.Select(pdf => new ExpandingSlideThumbViewModel(pdf, now)).First(); // The second one that will be "stuck". 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 pdf2 = new PDFFile(vm); var exp2 = new ExpandingSlideThumbViewModel(pdf2, now); // Initialize the download guys Assert.IsNull(exp1.TalkAsThumbs); Assert.IsNull(exp2.TalkAsThumbs); // The first talk should have slides ready to show, and the second one not since // we've not started the download yet. await TestUtils.SpinWait(() => exp1.CanShowThumbs == true, 1000); await TestUtils.SpinWait(() => exp2.CanShowThumbs == false, 1000); // Show the thumbs for the first talk. exp1.ShowSlides.Execute(null); // And now both should be false. await TestUtils.SpinWait(() => exp1.CanShowThumbs == false, 1000); await TestUtils.SpinWait(() => exp2.CanShowThumbs == false, 1000); }
public async Task RenderAlreadyCachedFile() { // If the file has already been downloaded and installed locally (on a previous // look) then PDF rendering should happen automatically this time, even if // the download isn't triggered. // Get the infrastructure setup var f = new dummyFile(); var data = await TestUtils.GetFileAsBytes("test.pdf"); int loaderCalled = 0; f.GetStream = () => { loaderCalled++; throw new InvalidOperationException(); }; var dc = new dummyCache(); await f.SaveFileInCache(f.DateToReturn, data, dc); var vm = new FileDownloadController(f, dc); var pf = new PDFFile(vm); // Now, build the VM var pdfVM = new PDFPageViewModel(pf.GetPageStreamAndCacheInfo(1), dc); // Subscribe so we can "get" the image. MemoryStream lastImage = null; pdfVM.ImageStream.Subscribe(img => lastImage = img); Assert.IsNull(lastImage); // Render, and make sure things "worked" pdfVM.RenderImage.Execute(Tuple.Create(IWalker.ViewModels.PDFPageViewModel.RenderingDimension.Horizontal, (double)100, (double)100)); vm.DownloadOrUpdate.Execute(null); await TestUtils.SpinWait(() => lastImage != null, 2000); Assert.AreEqual(0, loaderCalled); Assert.IsNotNull(lastImage); }
public async Task CachedFileGetsUpdated() { var data = await TestUtils.GetFileAsBytes("test.pdf"); var data2 = await TestUtils.GetFileAsBytes("test2.pdf"); var sender = new Subject <StreamReader>(); var f = new dummyFile(); f.GetStream = () => { return(sender); }; // Install original data in cache var dc = new dummyCache(); await f.SaveFileInCache("old date", 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 TestUtils.SpinWait(() => pf.NumberOfPages != 0, 1000); Assert.AreEqual(10, pf.NumberOfPages); Debug.WriteLine("Got the first file through"); // Next, do the next download and fetch the values. Debug.WriteLine("Sending a new stream reader"); sender.OnNext(new StreamReader(new MemoryStream(data2))); Debug.WriteLine("New stream reader is sent"); sender.OnCompleted(); await TestUtils.SpinWait(() => pf.NumberOfPages != 10, 1000); Assert.AreEqual(6, pf.NumberOfPages); }
public async Task TestFileNotUpdated() { // First, we need to get the file into the cache. Use the infrastructure to do that. var df = new dummyFile("test.pdf", "test.pdf"); var data = await TestUtils.GetFileAsBytes("test.pdf"); await df.SaveFileInCache(df.DateToReturn, data, Blobs.LocalStorage); // Now, we are going to update the cache, and see if it gets re-read. var dfctl = new FileDownloadController(df); var pdfFile = new PDFFile(dfctl); var vm = new FileSlideListViewModel(pdfFile, new TimePeriod(DateTime.Now, DateTime.Now)); var list = vm.SlideThumbnails; Assert.IsNotNull(list); Assert.AreEqual(0, list.Count); Assert.AreEqual(0, df.GetStreamCalled); }