Example #1
0
        public RedirectEngine(
            IConfiguration configuration,
            IUrlHelper urlHelper,
            IUrlParser urlParser,
            IUrlFormatter urlFormatter,
            IRedirectParser redirectParser,
            IHttpClient httpClient)
        {
            _configuration  = configuration;
            _urlHelper      = urlHelper;
            _urlParser      = urlParser;
            _redirectParser = redirectParser;
            _httpClient     = httpClient;
            Processors      = new List <IProcessor>
            {
                new InvalidProcessor(),
                new IdenticalProcessor(
                    _urlHelper),
                new DuplicateProcessor(
                    _configuration,
                    _urlHelper),
                new ExcludeProcessor(
                    _configuration),
                new RedirectProcessor(
                    _configuration,
                    _urlHelper,
                    _httpClient,
                    _urlParser,
                    urlFormatter,
                    new RedirectHelper(
                        _configuration,
                        _urlParser,
                        urlFormatter)
                    )
            };
            _redirects          = new List <IRedirect>();
            _parsedRedirects    = new List <IParsedRedirect>();
            _processedRedirects = new List <IProcessedRedirect>();
            _results            = new List <IResult>();
            _activeProcessors   = new List <IProcessor>();

            Exporters = new List <IExporter>
            {
                new WebConfigExporter(
                    _configuration,
                    _urlParser,
                    urlFormatter),
                new AwsS3StaticWebsiteExporter(
                    _configuration,
                    _urlParser,
                    urlFormatter)
            };
        }
        public ProcessedRedirectValidatorTests()
        {
            var redirects = new[]
            {
                new Redirect
                {
                    OldUrl = "http://www.test1.local/url1",
                    NewUrl = "http://www.test3.local/url8"
                },
                new Redirect
                {
                    OldUrl = "http://www.test1.local/url2",
                    NewUrl = "http://www.test2.local/url5"
                },
                new Redirect
                {
                    OldUrl = "http://www.test1.local/url1",
                    NewUrl = "http://www.test3.local/url8"
                },
                new Redirect
                {
                    OldUrl = "http://www.test1.local/url1",
                    NewUrl = "http://www.test3.local/url8"
                }
            };

            _redirectParser = new RedirectParser(
                TestData.TestData.DefaultConfiguration,
                new UrlParser(),
                new UrlFormatter());

            _processedRedirects = new[]
            {
                // processed redirect with cyclic redirect must be considered invalid
                new ProcessedRedirect
                {
                    ParsedRedirect = _redirectParser.ParseRedirect(
                        new Redirect
                    {
                        OldUrl = "http://www.test1.local/url1",
                        NewUrl = "http://www.test3.local/url8"
                    }),
                    Results = new[]
                    {
                        new Result
                        {
                            Type = ResultTypes.CyclicRedirect
                        }
                    }
                },
                // processed redirect with not matching new url and url response status code 404 must be considered invalid
                new ProcessedRedirect
                {
                    ParsedRedirect = _redirectParser.ParseRedirect(
                        new Redirect
                    {
                        OldUrl = "http://www.test1.local/url2",
                        NewUrl = "http://www.test2.local/url5"
                    }),
                    Results = new[]
                    {
                        new UrlResponseResult
                        {
                            Type       = ResultTypes.UrlResponse,
                            Url        = "http://www.test2.local/url9",
                            StatusCode = 404
                        }
                    }
                },
                // processed redirect with matching new url and url response status code 404 must be considered invalid
                new ProcessedRedirect
                {
                    ParsedRedirect = _redirectParser.ParseRedirect(
                        new Redirect
                    {
                        OldUrl = "http://www.test1.local/url2",
                        NewUrl = "http://www.test2.local/url5"
                    }),
                    Results = new[]
                    {
                        new UrlResponseResult
                        {
                            Type       = ResultTypes.UrlResponse,
                            Url        = "http://www.test2.local/url5",
                            StatusCode = 404
                        }
                    }
                },
                // processed redirect with matching new url and url response status code 200 must be considered valid
                new ProcessedRedirect
                {
                    ParsedRedirect = _redirectParser.ParseRedirect(
                        new Redirect
                    {
                        OldUrl = "http://www.test2.local/url3",
                        NewUrl = "http://www.test2.local/url9"
                    }),
                    Results = new[]
                    {
                        new UrlResponseResult
                        {
                            Type       = ResultTypes.UrlResponse,
                            Url        = "http://www.test2.local/url9",
                            StatusCode = 200
                        }
                    }
                },
                // processed redirect with not matching new url must be considered
                // valid or invalid depending on configuration
                new ProcessedRedirect
                {
                    ParsedRedirect = _redirectParser.ParseRedirect(
                        new Redirect
                    {
                        OldUrl = "http://www.test2.local/url4",
                        NewUrl = "http://www.test2.local/url9"
                    }),
                    Results = new[]
                    {
                        new UrlResponseResult
                        {
                            Type       = ResultTypes.UrlResponse,
                            Url        = "http://www.test2.local/url10",
                            StatusCode = 200
                        }
                    }
                }
            };
        }