Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void EmptyAllTheWay()
        {
            var cd = new CrawlerDetect(null, string.Empty);

            Assert.Throws(typeof(ArgumentException), () =>
            {
                var result = cd.IsCrawler(string.Empty);
            });
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Test setup
 /// </summary>
 public Tests()
 {
     _detector = new CrawlerDetect();
 }