Created
January 18, 2011 07:04
-
-
Save anaisbetts/784070 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void FetchImageFromSiteCommandTest() | |
{ | |
// Replace the immediate scheduler with an event loop (a thread who just | |
// waits in the background to process stuff as it arrives, one at a time) | |
var origSched = RxApp.DeferredScheduler; | |
RxApp.DeferredScheduler = new EventLoopScheduler(); | |
// MyCoolViewModel has an ICommand called FetchImageFromSite | |
var fixture = new MyCoolViewModel(); | |
fixture.FetchImageFromSite("myCoolImage.jpg").Execute(); | |
// While it's running, make sure we can't execute anything | |
Assert.False(fixture.FetchImageFromSite.CanExecute("myCoolImage.jpg")); | |
Assert.False(fixture.DownloadedImages.Any(x => x.Name == "myCoolImage.jpg")); | |
// Wait until it completes | |
fixture.FetchImageFromSite.ItemsInflight | |
.Where(count => count == 0) | |
.First(); | |
// Verify that the Image is downloaded | |
Assert.True(fixture.DownloadedImages.Any(x => x.Name == "myCoolImage")); | |
// Now we *should* be able to execute the command | |
Assert.True(fixture.FetchImageFromSite.CanExecute("myCoolImage.jpg")); | |
// Replace the old scheduler | |
RxApp.DeferredScheduler = origSched; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@GraemeF Oops, this is what happens when you code in a TextArea :)