public void LoadConfig(string path)
        {
            var rr   = new RewriteReader(_factory);
            var conf = rr.ReadConf(path);

            RulesSets = RewriteRuleSet.BuildRuleSets(conf).ToList();
        }
        public void Pricing_index_page_urls(string originalUrl, bool matchesCond, bool matchesRule, string expectedUrl)
        {
            //Arrange
            var samples = new RandomSampleValues();
            var factory = new RewriteFactory(samples);

            string[] lines =
            {
                @"RewriteCond %{HTTP:Host} ^directory[2]?\.uship\.com$",
                @"RewriteRule ^/tips/showtip.aspx(.*)$ http://www.uship.com/tips/showtip.aspx$1 [NC,R=301]",
                @"",
                @"# ...",
                @"",
                @"# Listing Index",
                @"RewriteRule ^/pricing/((?:[a-z]|[-])+)/((?:[a-z]|[-])+)(?:/page/([0-9]+))? /listingindex/PricingCommodity.aspx?c=$1&c2=$2&page=$3 [NC,L]",
                @"RewriteRule ^/pricing/((?:[a-z]|[-])+)(?:/page/([0-9]+))? /listingindex/PricingCommodity.aspx?c=$1&page=$2 [NC,L]",
                @"RewriteRule ^/pricing/?$ /listingindex/?c=4&c2=79 [NC,L]"
            };
            var lineNum      = 1;
            var redirects    = lines.Select(l => factory.Build(lineNum++, l));
            var ruleSet      = RewriteRuleSet.BuildRuleSets(redirects);
            var redirectData = new RedirectData(originalUrl);

            TestConditions(matchesCond, matchesRule, 3, expectedUrl, ruleSet, redirectData);
        }
        public void Vortal_rewrites_alone_should_go_to_correct_domain(string originalUrl, bool matchesCond, bool matchesRule, string expectedUrl)
        {
            //Arrange
            var samples = new RandomSampleValues();
            var factory = new RewriteFactory(samples);

            string[] lines =
            {
                @"RewriteCond %{HTTP:Host} ^(movers|vehicles|boats|motorcycles|freight)\.uship\.com$",
                @"RewriteRule ^/(.+)$ http://www.uship.com/%1/$1 [CL,NC,R=301]",
                @"",
                @"RewriteCond %{HTTP:Host} ^pets-livestock\.uship\.com$",
                @"RewriteRule ^/(.+)$ http://www.uship.com/pet-shipping/$1 [CL,NC,R=301]",
                @"",
                @"RewriteCond %{HTTP:Host} ^household-goods\.uship\.com$",
                @"RewriteRule ^/(.+)$ http://www.uship.com/furniture/$1 [CL,NC,R=301]",
                @"",
                @"# 301 these lortals to their vortals, these lortals will not exist",
                @"RewriteCond %{HTTP:Host} ^(craigslist|special-care|junk|food)(?:-agriculture)?\.uship\.com$",
                @"RewriteRule ^/(.+)$ http://www.uship.com/%1/ [CL,NC,R=301]"
            };
            var lineNum      = 1;
            var redirects    = lines.Select(l => factory.Build(lineNum++, l));
            var ruleSet      = RewriteRuleSet.BuildRuleSets(redirects);
            var redirectData = new RedirectData(originalUrl);

            TestConditions(matchesCond, matchesRule, 1, expectedUrl, ruleSet, redirectData);
        }
        //TODO all these tests could be moved into this...
        public static void BuildAndTestConditions(IEnumerable <string> lines, string originalUrl, bool matchesCond, bool matchesRule, string expectedUrl, int?expectedRuleCount = null)
        {
            var samples      = new RandomSampleValues();
            var factory      = new RewriteFactory(samples);
            var lineNum      = 1;
            var redirects    = lines.Select(l => factory.Build(lineNum++, l));
            var ruleSet      = RewriteRuleSet.BuildRuleSets(redirects);
            var redirectData = new RedirectData(originalUrl);

            TestConditions(matchesCond, matchesRule, null, expectedUrl, ruleSet, redirectData);
        }
        public void Single_ruleset_should_object_work_as_expected(string originalUrl, bool matchesCond, bool matchesRule, string expectedUrl)
        {
            //Arrange
            var samples = new RandomSampleValues();
            var factory = new RewriteFactory(samples);

            string[] lines =
            {
                @"RewriteCond %{HTTP:Host} ^(movers|household-goods|vehicles|boats|motorcycles|special-care|freight|pets-livestock|food-agriculture|junk|craigslist)[2]?\.uship\.com$",
                @"RewriteRule ^(?!.+\.axd|.+\.ashx|public/images|sticky/images)/([^?]*\u.*)/?(?:[^?]*\u.*)?$ /$1 [CL,R=301]"
            };
            var lineNum      = 1;
            var redirects    = lines.Select(l => factory.Build(lineNum++, l));
            var ruleSet      = RewriteRuleSet.BuildRuleSets(redirects);
            var redirectData = new RedirectData(originalUrl);

            TestConditions(matchesCond, matchesRule, 1, expectedUrl, ruleSet, redirectData);
        }
        public void Https_test_cases(string originalUrl, bool matchesCond, bool matchesRule, string expectedUrl)
        {
            //Arrange
            var samples = new RandomSampleValues();
            var factory = new RewriteFactory(samples);

            string[] lines =
            {
                @"# Force SSL for pages that request personally-identifiable information",
                @"RewriteCond %{HTTPS} ^(?!on).*$",
                @"RewriteCond %{SERVER_PORT} ^80$",
                @"RewriteCond %{HTTP:Host} (.*)",
                @"RewriteRule ^(/ltl-freight)(.*)$ https\://%1$1 [NC,R=301]",
            };
            var lineNum      = 1;
            var redirects    = lines.Select(l => factory.Build(lineNum++, l));
            var ruleSet      = RewriteRuleSet.BuildRuleSets(redirects);
            var redirectData = new RedirectData(originalUrl);

            TestConditions(matchesCond, matchesRule, 1, expectedUrl, ruleSet, redirectData);
        }