Created
December 6, 2011 07:45
-
-
Save biac/1437237 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
const string RssUrl = "http://www.amazon.co.jp/gp/rss/bestsellers/books/492352/ref=zg_bs_492352_rsslink"; | |
// Amazon.co.jp: 本 > コンピュータ・IT > プログラミングのベストセラー | |
[TestMethod] | |
public void ReadAsyncTest1_基本_非同期実行開始後にWait() | |
{ | |
//* 準備 | |
FeedReader fr = new FeedReader(); | |
Stopwatch sw = Stopwatch.StartNew(); | |
//* 実行 | |
Task<FeedData> task = fr.ReadAsync(RssUrl); // ← 非同期実行開始 | |
//** (実行状況チェック) | |
//this.TestContext.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff")); //full trust じゃないと出力されないっぽいorz | |
sw.Stop(); | |
//Assert.AreEqual<long>(0, sw.ElapsedMilliseconds); | |
Assert.IsTrue(200L > sw.ElapsedMilliseconds); //実際には 50mSec 程度 | |
Assert.IsFalse(task.IsCompleted, "ReadAsync 呼び出し直後"); //非同期実行中 | |
sw.Restart(); | |
task.Wait(); // ← ここで非同期実行が終わるのを待つ | |
//* 検証 | |
sw.Stop(); | |
//Assert.AreEqual<long>(0, sw.ElapsedMilliseconds); | |
Assert.IsTrue(100L < sw.ElapsedMilliseconds); //実際には 500~1000mSec 程度掛かっている | |
Assert.IsTrue(task.IsCompleted); //非同期実行完了 | |
FeedData fd = task.Result; | |
StringAssert.StartsWith(fd.Title, "Amazon.co.jp: 本"); | |
Assert.AreEqual<int>(10, fd.Items.Count); //ランキングのRSSは上位10冊 | |
//最初のフィードアイテム | |
FeedItem first = fd.Items[0]; | |
StringAssert.StartsWith(first.Title, "#1: "); //ex) #1: WEB+DB PRESS 総集編 [Vol.1~60] | |
//最後のフィードアイテム | |
FeedItem last = fd.Items[9]; | |
StringAssert.StartsWith(last.Title, "#10: "); //ex) #10: Unityではじめるゲームづくり (DVD付) (ゲープロシリーズ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment