Fluent interface

NRobots allows you to create instances of the Robots class using a fluent interface:

var baseUri = new Uri("http://www.microsoft.com");
var robots = RobotsBuilder.Create(baseUri)
                .ForUserAgent("bot1")
                .Disallow("/web")
                .Disallow("/cloud")
                .Allow("/web/page1.aspx")

                .ForUserAgent("bot2")
                .Disallow("/")

                .ForUserAgent("*")
                .DisallowWithComment("/blocked", "with comment")

                .Robots;

Assert.Equal(false, robots.Allowed("/web", "bot1"));
Assert.Equal(false, robots.Allowed("/web/allowed", "bot1"));
Assert.Equal(true, robots.Allowed("/web/page1.aspx", "bot1"));

Assert.Equal(false, robots.Allowed("/", "bot2"));
Assert.Equal(false, robots.Allowed("/page.aspx", "bot2"));

Assert.Equal(false, robots.Allowed("/blocked"));
Assert.Equal(false, robots.Allowed("/blocked", "*"));
Assert.Equal(true, robots.Allowed("/notblocked"));

Last edited Sep 12, 2010 at 8:48 PM by saguiitay, version 1

Comments

No comments yet.