Exemplo n.º 1
0
        public void BuildRedirectReportMatchingNewUrl()
        {
            // create and build filtered redirect report
            var configuration =
                TestData.TestData.DefaultConfiguration;
            var urlFormatter = new UrlFormatter();
            var urlParser    = new UrlParser();
            var urlHelper    = new UrlHelper(
                configuration,
                urlParser,
                urlFormatter);
            var processedRedirectValidator = new ProcessedRedirectValidator(
                configuration,
                urlHelper);
            var outputRedirectBuilder = new OutputRedirectBuilder
                                            (processedRedirectValidator);
            var outputRedirectReport = new OutputRedirectReport(
                outputRedirectBuilder,
                false);

            outputRedirectReport.Build(_redirectProcessingResult);

            // verify filtered redirect records are build
            var records = outputRedirectReport
                          .GetRecords()
                          .ToList();

            Assert.AreEqual(1, records.Count);
            Assert.AreEqual(
                "http://www.test2.local/url3",
                records[0].OldUrl);
            Assert.AreEqual(
                "http://www.test2.local/url9",
                records[0].NewUrl);
        }
Exemplo n.º 2
0
        public void BuildOutputRedirects()
        {
            // create and build filtered redirect report
            var configuration =
                TestData.TestData.DefaultConfiguration;
            var urlFormatter = new UrlFormatter();
            var urlParser    = new UrlParser();
            var urlHelper    = new UrlHelper(
                configuration,
                urlParser,
                urlFormatter);
            var processedRedirectValidator = new ProcessedRedirectValidator(
                configuration,
                urlHelper);
            var outputRedirectBuilder = new OutputRedirectBuilder
                                            (processedRedirectValidator);

            var validOutputRedirects = _redirectProcessingResult.ProcessedRedirects
                                       .Select(x => outputRedirectBuilder.Build(x))
                                       .Where(x => x.ValidMatchingOriginalNewUrl || x.ValidNotMatchingOriginalNewUrl)
                                       .ToList();

            // verify valid output redirects
            Assert.AreEqual(2, validOutputRedirects.Count);
            Assert.AreEqual(
                "http://www.test2.local/url3",
                validOutputRedirects[0].OldUrl);
            Assert.AreEqual(
                "http://www.test2.local/url9",
                validOutputRedirects[0].NewUrl);
            Assert.AreEqual(
                "http://www.test2.local/url4",
                validOutputRedirects[1].OldUrl);
            Assert.AreEqual(
                "http://www.test2.local/url10",
                validOutputRedirects[1].NewUrl);
        }
Exemplo n.º 3
0
        public void BuildProcessedRedirectReport()
        {
            var oldUrlRaw = "http://www.test.local/old";
            var newUrlRaw = "http://www.test.local/new";

            var configuration  = TestData.TestData.DefaultConfiguration;
            var parsedRedirect = TestData.TestData.GetParsedRedirects(
                configuration,
                new[]
            {
                new Redirect
                {
                    OldUrl = oldUrlRaw,
                    NewUrl = newUrlRaw
                }
            })
                                 .FirstOrDefault();

            var redirectProcessingResult = new RedirectProcessingResult
            {
                ProcessedRedirects = new[]
                {
                    new ProcessedRedirect
                    {
                        ParsedRedirect = parsedRedirect,
                        Results        = new []
                        {
                            new Result
                            {
                                Type    = ResultTypes.ExcludedRedirect,
                                Message = ResultTypes.ExcludedRedirect,
                                Url     = newUrlRaw
                            },
                            new Result
                            {
                                Type    = ResultTypes.DuplicateOfFirst,
                                Message = ResultTypes.DuplicateOfFirst,
                                Url     = newUrlRaw
                            },
                            new Result
                            {
                                Type    = ResultTypes.DuplicateOfLast,
                                Message = ResultTypes.DuplicateOfLast,
                                Url     = newUrlRaw
                            }
                        }
                    }
                }
            };

            // create and build processed redirect report
            var urlHelper = new UrlHelper(
                configuration,
                new UrlParser(),
                new UrlFormatter());
            var processedRedirectValidator =
                new ProcessedRedirectValidator(
                    configuration,
                    urlHelper);
            var outputRedirectBuilder = new OutputRedirectBuilder
                                            (processedRedirectValidator);
            var processedRedirectReport = new ProcessedRedirectReport(
                outputRedirectBuilder);

            processedRedirectReport.Build(redirectProcessingResult);

            // verify processed redirect records are build
            var records = processedRedirectReport
                          .GetRecords()
                          .ToList();

            Assert.AreEqual(1, records.Count);
            Assert.AreEqual(
                oldUrlRaw,
                records[0].OriginalOldUrl);
            Assert.AreEqual(
                newUrlRaw,
                records[0].OriginalNewUrl);
            Assert.AreEqual(
                oldUrlRaw,
                records[0].ParsedOldUrl);
            Assert.AreEqual(
                newUrlRaw,
                records[0].ParsedNewUrl);

            Assert.AreEqual(
                3,
                records[0].ResultCount);
            Assert.AreEqual(
                string.Join(",", new []
            {
                ResultTypes.DuplicateOfFirst,
                ResultTypes.DuplicateOfLast,
                ResultTypes.ExcludedRedirect
            }),
                records[0].ResultTypes);

            Assert.AreEqual(
                true,
                records[0].ExcludedRedirect);
            Assert.AreEqual(
                ResultTypes.ExcludedRedirect,
                records[0].ExcludedRedirectMessage);
            Assert.AreEqual(
                newUrlRaw,
                records[0].ExcludedRedirectUrl);

            Assert.AreEqual(
                true,
                records[0].DuplicateOfFirst);
            Assert.AreEqual(
                ResultTypes.DuplicateOfFirst,
                records[0].DuplicateOfFirstMessage);
            Assert.AreEqual(
                newUrlRaw,
                records[0].DuplicateOfFirstUrl);

            Assert.AreEqual(
                true,
                records[0].DuplicateOfLast);
            Assert.AreEqual(
                ResultTypes.DuplicateOfLast,
                records[0].DuplicateOfLastMessage);
            Assert.AreEqual(
                newUrlRaw,
                records[0].DuplicateOfLastUrl);
        }
        static void Reports(
            string outputDir,
            IRedirectProcessingResult redirectProcessingResult,
            IProcessedRedirectValidator processedRedirectValidator)
        {
            // create and write redirect summary report
            // ----------------------------------------
            var redirectSummaryReportCsvFile = Path.Combine(
                outputDir,
                "redirect_summary.csv");

            System.Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine(
                string.Format(
                    "Building and writing redirect summary report file '{0}'",
                    redirectSummaryReportCsvFile));

            var redirectSummaryReport =
                new RedirectSummaryReport(
                    processedRedirectValidator);

            redirectSummaryReport.Build(
                redirectProcessingResult);
            redirectSummaryReport.WriteReportCsvFile(
                redirectSummaryReportCsvFile);

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("Done");
            System.Console.WriteLine(string.Empty);

            // create and write old url domain report
            // --------------------------------------
            var oldUrlDomainReportCsvFile = Path.Combine(
                outputDir,
                "oldurl_domains.csv");

            System.Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine(
                string.Format(
                    "Building and writing old url domains report file '{0}'",
                    oldUrlDomainReportCsvFile));

            var oldUrlDomainReport =
                new OldUrlDomainReport();

            oldUrlDomainReport.Build(
                redirectProcessingResult);
            oldUrlDomainReport.WriteReportCsvFile(
                oldUrlDomainReportCsvFile);

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("Done");
            System.Console.WriteLine(string.Empty);

            // create and write new url domain report
            // --------------------------------------
            var newUrlDomainReportCsvFile = Path.Combine(
                outputDir,
                "newurl_domains.csv");

            System.Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine(
                string.Format(
                    "Building and writing new url domains report file '{0}'",
                    newUrlDomainReportCsvFile));

            var newUrlDomainReport =
                new NewUrlDomainReport();

            newUrlDomainReport.Build(
                redirectProcessingResult);
            newUrlDomainReport.WriteReportCsvFile(
                newUrlDomainReportCsvFile);

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("Done");
            System.Console.WriteLine(string.Empty);

            // create and write processed redirect report
            // ------------------------------------------
            var processedRedirectReportCsvFile = Path.Combine(
                outputDir,
                "processed_redirects.csv");

            System.Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine(
                string.Format(
                    "Building and writing processed redirects report file '{0}'",
                    processedRedirectReportCsvFile));

            var outputRedirectBuilder = new OutputRedirectBuilder(
                processedRedirectValidator);
            var processedRedirectReport =
                new ProcessedRedirectReport(
                    outputRedirectBuilder);

            processedRedirectReport.Build(
                redirectProcessingResult);
            processedRedirectReport.WriteReportCsvFile(
                processedRedirectReportCsvFile);

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("Done");
            System.Console.WriteLine(string.Empty);

            // create and write output redirect report
            // ---------------------------------------
            var outputRedirectReportCsvFile = Path.Combine(
                outputDir,
                "output_redirects.csv");

            System.Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine(
                string.Format(
                    "Building and writing output redirects report file '{0}'",
                    outputRedirectReportCsvFile));

            var outputRedirectReport =
                new OutputRedirectReport(
                    outputRedirectBuilder,
                    false);

            outputRedirectReport.Build(
                redirectProcessingResult);
            outputRedirectReport.WriteReportCsvFile(
                outputRedirectReportCsvFile);

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("Done");
            System.Console.WriteLine(string.Empty);

            // create and write output redirect including not matching new url report
            // ----------------------------------------------------------------------
            var outputRedirectIncludingNotMatchingNewUrlReportCsvFile = Path.Combine(
                outputDir,
                "output_redirects_incl_not_matching.csv");

            System.Console.ForegroundColor = ConsoleColor.Yellow;
            System.Console.WriteLine(
                string.Format(
                    "Building and writing output redirects including not matching new url report file '{0}'",
                    outputRedirectIncludingNotMatchingNewUrlReportCsvFile));

            var outputRedirectIncludingNotMatchingNewUrlReport =
                new OutputRedirectReport(
                    outputRedirectBuilder,
                    true);

            outputRedirectIncludingNotMatchingNewUrlReport.Build(
                redirectProcessingResult);
            outputRedirectIncludingNotMatchingNewUrlReport.WriteReportCsvFile(
                outputRedirectIncludingNotMatchingNewUrlReportCsvFile);

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("Done");
            System.Console.ForegroundColor = ConsoleColor.Gray;
        }