public void FileCookieInject_FileNotExists() { Assert.Throws <ArgumentException>(() => { FileCookieInject cookieInject = new FileCookieInject("notexists.cookies"); }); }
public void FileCookieInject() { FileCookieInject cookieInject = new FileCookieInject("Downloader\\test.cookies"); var spider = new DefaultSpider(); cookieInject.Inject(spider.Downloader, spider); var cookies = spider.Downloader.GetCookies(new Uri("http://baidu.com")); Assert.Equal("b", cookies["a"].Value); Assert.Equal("e", cookies["c"].Value); }
public void FileCookieInject() { if (Environment.GetEnvironmentVariable("TRAVIS") == "1") { return; } FileCookieInject cookieInject = new FileCookieInject("source\\test.cookies"); var spider = new DefaultSpider(); cookieInject.Inject(spider.Downloader, spider); var cookies = spider.Downloader.GetCookies(new Uri("http://baidu.com")); Assert.Equal("b", cookies["a"].Value); Assert.Equal("e", cookies["c"].Value); }
public void InjectCookiesBeforeSpiderRun() { var path = "www.baidu.com.cookies"; if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, "a=b&c=d"); FileCookieInject inject = new FileCookieInject(); Site site = new Site(); site.AddStartUrl("http://www.baidu.com"); DefaultSpider spider = new DefaultSpider("a", site); inject.Inject(spider, false); Assert.AreEqual("a=b&c=d", site.Cookies.ToString()); }
public void InjectCookies() { var path = "a.cookies"; if (File.Exists(path)) { File.Delete(path); } File.AppendAllLines(path, new[] { "www.baidu.com" }); File.AppendAllLines(path, new[] { "a=b;c=d" }); FileCookieInject inject = new FileCookieInject(path); var downloader = new HttpClientDownloader(); inject.Inject(downloader); var cookies = downloader.GetCookies(new Uri("http://www.baidu.com")); Assert.Equal("b", cookies["a"].Value); Assert.Equal("d", cookies["c"].Value); }
public void InjectCookiesBeforeSpiderRun() { var path = "a.cookies"; if (File.Exists(path)) { File.Delete(path); } File.AppendAllLines(path, new[] { "www.baidu.com" }); File.AppendAllLines(path, new[] { "a=b;c=d" }); FileCookieInject inject = new FileCookieInject(); Site site = new Site(); site.AddStartUrl("http://www.baidu.com"); DefaultSpider spider = new DefaultSpider("a", site); inject.Inject(spider.Downloader, spider, false); var cookies = spider.Downloader.GetCookies(new System.Uri("http://www.baidu.com")); Assert.Equal("b", cookies["a"].Value); Assert.Equal("d", cookies["c"].Value); }
public void InjectCookiesBeforeSpiderRun() { var path = "a.cookies"; if (File.Exists(path)) { File.Delete(path); } File.AppendAllLines(path, new[] { "www.baidu.com" }); File.AppendAllLines(path, new[] { "a=b;c=d" }); FileCookieInject inject = new FileCookieInject(); Site site = new Site(); site.AddStartUrl("http://www.baidu.com"); DefaultSpider spider = new DefaultSpider("a", site); inject.Inject(spider, false); var cookies = spider.Cookies.GetCookies("www.baidu.com"); Assert.Contains(cookies, c => c.Name == "a" && c.Value == "b"); Assert.Contains(cookies, c => c.Name == "c" && c.Value == "d"); }
public void InjectCookiesBeforeSpiderRun() { var path = "a.cookies"; if (File.Exists(path)) { File.Delete(path); } File.AppendAllLines(path, new[] { "www.baidu.com" }); File.AppendAllLines(path, new[] { "a=b;c=d" }); FileCookieInject inject = new FileCookieInject(path, new App()); Site site = new Site(); site.AddRequests("http://www.baidu.com"); var downloader = new HttpWebRequestDownloader(); inject.Inject(downloader, true); var cookies = downloader.GetCookies(new Uri("http://www.baidu.com")); Assert.Equal("b", cookies["a"].Value); Assert.Equal("d", cookies["c"].Value); }