static async Task CheckImporters(ICookieImporter importer, CookieImportState expectedState, bool expectedIsAvailable, bool checkUserSession) { var cookies = new CookieContainer(); var url = new Uri("http://nicovideo.jp/"); var res = await importer.GetCookiesAsync(url); res.AddTo(cookies); LogWriter.WriteLine("{0}:\t{1} ({2})", importer.IsAvailable ? "OK" : "Error", importer.SourceInfo.BrowserName, importer.SourceInfo.ProfileName); Assert.AreEqual(expectedState, res.Status); Assert.IsNotNull(importer.SourceInfo.BrowserName); Assert.IsNotNull(importer.SourceInfo.ProfileName); Assert.AreEqual(expectedIsAvailable, importer.IsAvailable); if (expectedIsAvailable) { Assert.IsNotNull(importer.SourceInfo.CookiePath, string.Format("{0}のSourceInfo.CookiePathにはプロフィール名が入りますが、取得できませんでした。", importer.SourceInfo.BrowserName)); Assert.AreNotEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からCookieを取得できませんでした。", importer.SourceInfo.BrowserName)); if (checkUserSession) { Assert.IsNotNull(cookies.GetCookies(new Uri("http://nicovideo.jp"))["user_session"]); } } else { Assert.AreEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からIsAvailableがfalse状態でCookieを取得する事は出来ませんが、取得されてしまっています。", importer.SourceInfo.BrowserName)); } }
static async Task CheckImporters(ICookieImporter importer, CookieImportState expectedState, bool expectedIsAvailable, bool checkUserSession) { var cookies = new CookieContainer(); var url = new Uri("http://nicovideo.jp/"); var res = await importer.GetCookiesAsync(url); res.AddTo(cookies); LogWriter.WriteLine("{0}:\t{1} ({2})", importer.IsAvailable ? "OK" : "Error", importer.SourceInfo.BrowserName, importer.SourceInfo.ProfileName); Assert.AreEqual(expectedState, res.Status); Assert.IsNotNull(importer.SourceInfo.BrowserName); Assert.IsNotNull(importer.SourceInfo.ProfileName); Assert.AreEqual(expectedIsAvailable, importer.IsAvailable); if (expectedIsAvailable) { Assert.IsNotNull(importer.SourceInfo.CookiePath, string.Format("{0}のSourceInfo.CookiePathにはプロフィール名が入りますが、取得できませんでした。", importer.SourceInfo.BrowserName)); Assert.AreNotEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からCookieを取得できませんでした。", importer.SourceInfo.BrowserName)); if (checkUserSession) Assert.IsNotNull(cookies.GetCookies(new Uri("http://nicovideo.jp"))["user_session"]); } else { Assert.AreEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からIsAvailableがfalse状態でCookieを取得する事は出来ませんが、取得されてしまっています。", importer.SourceInfo.BrowserName)); } }
#pragma warning disable 1591 public CookieImportResult(CookieCollection cookies, CookieImportState status) { _cookies = cookies; _status = status; }
/// <summary>例外を再スローさせるための例外を生成します。</summary> /// <param name="message">エラーの捕捉</param> /// <param name="result">エラーの種類</param> /// <param name="inner">内部例外</param> public CookieImportException(string message, CookieImportState result, Exception inner) : base(message, inner) { Result = result; }