Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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