Guest User

Untitled

a guest
Jul 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. [Fact]
  2. public void FetchImageFromSiteCommandTest()
  3. {
  4. // Replace the immediate scheduler with an event loop (a thread who just
  5. // waits in the background to process stuff as it arrives, one at a time)
  6. var origSched = RxApp.DeferredScheduler;
  7. RxApp.DeferredScheduler = new EventLoopScheduler();
  8.  
  9. // MyCoolViewModel has an ICommand called FetchImageFromSite
  10. var fixture = new MyCoolViewModel();
  11. fixture.FetchImageFromSite("myCoolImage.jpg").Execute();
  12.  
  13. // While it's running, make sure we can't execute anything
  14. Assert.False(fixture.FetchImageFromSite.CanExecute("myCoolImage.jpg"));
  15. Assert.False(fixture.DownloadedImages.Any(x => x.Name == "myCoolImage.jpg"));
  16.  
  17. // Wait until it completes
  18. fixture.FetchImageFromSite.ItemsInflight
  19. .Where(count => count == 0)
  20. .First();
  21.  
  22. // Verify that the Image is downloaded
  23. Assert.True(fixture.DownloadedImages.Any(x => x.Name == "myCoolImage"));
  24.  
  25. // Now we *should* be able to execute the command
  26. Assert.True(fixture.FetchImageFromSite.CanExecute("myCoolImage.jpg"));
  27.  
  28. // Replace the old scheduler
  29. RxApp.DeferredScheduler = origSched;
  30. }
Add Comment
Please, Sign In to add comment