I'm still in .NET 4.0 and I was wondering whether this pattern will hold up well in various kinds of async unit testing situations:
/// <summary>
/// Noaa weather test: should read remote XML.
/// </summary>
[TestMethod]
public void ShouldReadRemoteXml()
{
var uri = new Uri("http://www.weather.gov/xml/current_obs/KLAX.xml");
var wait = HttpVerbAsyncUtility.GetAsync(uri)
.ContinueWith(
t =>
{
Assert.IsFalse(t.IsFaulted, "An unexpected XML read error has occurred.");
Assert.IsTrue(t.IsCompleted, "The expected XML read did not take place.");
if(t.IsCompleted && !t.IsFaulted)
FrameworkFileUtility.Write(t.Result, @"NoaaWeather.xml");
})
.Wait(TimeSpan.FromSeconds(7));
Assert.IsTrue(wait, "The expected XML read did not take place within seven seconds.");
}
Will this Task.ContinueWith()...Task.Wait()
pattern hold up in the real world? I'm relatively new to formally thinking about Unit Testing (especially asynchronous unit testing) so please don't hold back on the basics :)