public void BotUserAgentPassedViaConstructor() { var cd = new CrawlerDetect(null, "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html)"); var result = cd.IsCrawler(); Assert.True(result); }
public void EmptyAllTheWay() { var cd = new CrawlerDetect(null, string.Empty); Assert.Throws(typeof(ArgumentException), () => { var result = cd.IsCrawler(string.Empty); }); }
public void NullAllTheWay() { var cd = new CrawlerDetect(null, null); Assert.Throws(typeof(ArgumentException), () => { var result = cd.IsCrawler(null); }); }
public string Check(string userAgent) { var detector = new CrawlerDetect(); var isBot = detector.IsCrawler(userAgent); if (isBot) { return(detector.Matches[0].Value); } return(null); }
public void InferBotViaFromHeader() { var headers = new WebHeaderCollection() { { "accept", "*/*" }, { "accept-encoding", "DEFLATE" }, { "cache-control", "no-cache" }, { "connection", "Keep-Alive" }, { "from", "googlebot(at)googlebot.com" }, { "host", "www.test.com" }, { "pragma", "no-cache" }, { "user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36" } }; var cd = new CrawlerDetect(headers); var result = cd.IsCrawler(); Assert.True(result); }
public void InferBotViaUserAgentHeader() { var headers = new WebHeaderCollection() { { "accept", "*/*" }, { "accept-encoding", "DEFLATE" }, { "cache-control", "no-cache" }, { "connection", "Keep-Alive" }, // {"from", "bingbot(at)microsoft.com"}, { "host", "www.test.com" }, { "pragma", "no-cache" }, { "user-agent", "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)" } }; var cd = new CrawlerDetect(headers); var result = cd.IsCrawler(); Assert.True(result); }
/// <summary> /// Test setup /// </summary> public Tests() { _detector = new CrawlerDetect(); }