Created
December 6, 2011 09:37
-
-
Save biac/1437559 to your computer and use it in GitHub Desktop.
FeedReader: 非同期実行中に発生した例外を捕まえるテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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