Skip to content

Instantly share code, notes, and snippets.

@biac
Created December 6, 2011 09:37
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 biac/1437559 to your computer and use it in GitHub Desktop.
Save biac/1437559 to your computer and use it in GitHub Desktop.
FeedReader: 非同期実行中に発生した例外を捕まえるテスト
#if DEBUG
[TestMethod]
public void ReadAsync2Test2_フィード取得中に例外発生()
{
FeedReader fd = new FeedReader() {
test__RaiseErrorUrl = RssUrls[2],
test__RaiseException = new System.Net.WebException("ユニットテスト用の例外シミュレート")
};
Task<IList<FeedData>> task = fd.ReadAsync(RssUrls);
IList<FeedData> fdList = null;
try
{
//fdList = task.Result; //→ System.AggregateException が出る。catch が書きにくい!
fdList = task.GetAwaiter().GetResult();
Assert.Fail("予期した例外が出なかったorz");
}
catch (System.Net.WebException ex) {
Assert.AreEqual<string>("ユニットテスト用の例外シミュレート", ex.Message);
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment