Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created January 18, 2011 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anaisbetts/784070 to your computer and use it in GitHub Desktop.
Save anaisbetts/784070 to your computer and use it in GitHub Desktop.
[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;
}
@GraemeF
Copy link

GraemeF commented Jan 20, 2011

If FetchImageFromSite is an ICommand then line 11 should read:

fixture.FetchImageFromSite.Execute("myCoolImage.jpg");

and line 14 should read:

Assert.False(fixture.FetchImageFromSite.CanExecute("myCoolImage.jpg"));

Unless I'm missing something :)

@anaisbetts
Copy link
Author

@GraemeF Oops, this is what happens when you code in a TextArea :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment