O'Reilly logo

Programming Reactive Extensions and LINQ by Paul Betts, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Async Methods with .First()

For unit tests whose sole goal is to test the actual values coming out of a method, the easiest way to call async methods is by just adding .First() on the end so that it will wait for the result. The following shows how we could write a simple, value-based test for an Rx async method; we could even use this to test our stub to make sure it does what we want.

[TestMethod] void FetchWebpageSuccessCase() {     var result = FetchWebpageStub("http://www.google.com").First();     Assert.IsFalse(String.IsNullOrEmpty(result));     Assert.IsTrue(result.ToLower().Contains("html")); }

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required