public EnsureTrailingSlashTests()
        {
            var config = new UrlRequestConfiguration()
                .EnsureTrailingSlash();

            _pipeline = new UrlRequestPipeline(config);
        }
        public void Init(HttpApplication context)
        {
            var config = new UrlRequestConfiguration();

            _pipeline = new UrlRequestPipeline(config);

            context.BeginRequest += Context_BeginRequest;
        }
        public void UpperCaseUrlBecomesLowerCase()
        {
            var config = new UrlRequestConfiguration();
            config.LowerCaseUrl();

            var pipeline = new UrlRequestPipeline(config);

            var result = pipeline.Process(new Uri("http://localhost/HOME/"));

            Assert.True(result.RedirectRequired);
            Assert.Equal(new Uri("http://localhost/home/"), result.ProcessedUrl.Uri);
        }
        public void LowerCaseUrlDoesNotResultInARewrite()
        {
            var config = new UrlRequestConfiguration();
            config.LowerCaseUrl();

            var pipeline = new UrlRequestPipeline(config);

            var result = pipeline.Process(new Uri("http://localhost/home/"));

            Assert.False(result.RedirectRequired);
            Assert.Equal(new Uri("http://localhost/home/"), result.ProcessedUrl.Uri);
        }
        public void CanDoANumberOfRewriteRulesAtOnce()
        {
            var config = new UrlRequestConfiguration();

            config
                .LowerCaseUrl()
                .StripDefaultNames()
                .EnsureTrailingSlash()
                .CanonicalDomain("www.bla.com")
                .AddRewriteMap("rewrites.config");

            var pipeline = new UrlRequestPipeline(config);

            var result = pipeline.Process(new Uri("http://bla.com/Index.html"));

            Assert.Equal(new Uri("http://www.bla.com/"), result.ProcessedUrl.Uri);
            Assert.Equal(4, result.RuleResults.Count);
        }
        public void IfNoRedirectsAreRequiredAllProcessedUrlsInResultsShouldBeNull()
        {
            var config = new UrlRequestConfiguration();

            config
                .LowerCaseUrl()
                .StripDefaultNames()
                .EnsureTrailingSlash()
                .CanonicalDomain("www.bla.com");

            var pipeline = new UrlRequestPipeline(config);
            var result = pipeline.Process(new Uri("http://www.bla.com/home/"));

            Assert.Equal(new Uri("http://www.bla.com/home/"), result.ProcessedUrl.Uri);
            Assert.False(result.RedirectRequired);

            var processedUris = result.RuleResults.Select(x => x.ProcessedUrl).Where(x => x != null);
            Assert.Empty(processedUris);
        }
        public void IfLowerCaseOnlyThenHaveOneProcessedUriInResults()
        {
            var config = new UrlRequestConfiguration();

            config
                .LowerCaseUrl()
                .StripDefaultNames()
                .EnsureTrailingSlash()
                .CanonicalDomain("www.bla.com");

            var pipeline = new UrlRequestPipeline(config);
            var result = pipeline.Process(new Uri("http://www.bla.com/HOME/"));

            Assert.Equal(new Uri("http://www.bla.com/home/"), result.ProcessedUrl.Uri);
            Assert.True(result.RedirectRequired);

            var processedUris = result.RuleResults.Select(x => x.ProcessedUrl).Where(x => x != null);
            Assert.Single(processedUris);
        }
 public UrlFactoryMiddleware(OwinMiddleware next, UrlRequestConfiguration config) : base(next)
 {
     _pipeline = new UrlRequestPipeline(config);
 }