public void CheckInvalidWordInUrl()
 {
     Assert.Empty(ContentValidation.Verify("some random content containing links /us/allowed/"));
     Assert.Empty(ContentValidation.Verify("some random content containing links /yourself/us/"));
     Assert.Empty(ContentValidation.Verify(" /us/ "));
     Assert.Empty(ContentValidation.Verify("/us-"));
 }
 public ValidationModule(
     IEnumerable<Logging.ILog> logs,
     IEnumerable<Logging.ITimedLog> timedLogs,
     ContentValidation.IValidatorFactory validatorFactory
     )
     : base()
 {
     if (null == logs)
         this.Logs = new List<Logging.ILog>();
     else
         this.Logs = new List<Logging.ILog>(logs);
     if (null == timedLogs)
         this.TimedLogs = new List<Logging.ITimedLog>();
     else
         this.TimedLogs = new List<Logging.ITimedLog>(timedLogs);
     this.ValidatorFactory = validatorFactory;
 }
        bool ValidateContent(string?relativePath, Line line, List <ValidationError> validationErrors)
        {
            if (!validateContent)
            {
                return(false);
            }

            if (relativePath != null &&
                validationExcludes.Any(relativePath.Contains))
            {
                return(false);
            }

            var errors = ContentValidation.Verify(line.Original).ToList();

            if (!errors.Any())
            {
                return(false);
            }

            validationErrors.AddRange(errors.Select(error => new ValidationError(error.error, line.LineNumber, error.column, line.Path)));
            return(true);
        }
        internal ProcessResult Apply(List <Line> lines, string newLine, string?relativePath)
        {
            var  missingSnippets  = new List <MissingSnippet>();
            var  validationErrors = new List <ValidationError>();
            var  missingIncludes  = new List <MissingInclude>();
            var  usedSnippets     = new List <Snippet>();
            var  usedIncludes     = new List <Include>();
            var  builder          = new StringBuilder();
            Line?tocLine          = null;
            var  headerLines      = new List <Line>();

            for (var index = 0; index < lines.Count; index++)
            {
                var line = lines[index];

                if (validateContent)
                {
                    var errors = ContentValidation.Verify(line.Original).ToList();
                    if (errors.Any())
                    {
                        validationErrors.AddRange(errors.Select(error => new ValidationError(error.error, line.LineNumber, error.column, line.Path)));
                        continue;
                    }
                }

                if (includeProcessor.TryProcessInclude(lines, line, usedIncludes, index, missingIncludes))
                {
                    continue;
                }

                if (line.Current.StartsWith("#"))
                {
                    if (tocLine != null)
                    {
                        headerLines.Add(line);
                    }

                    continue;
                }

                if (line.Current == "toc")
                {
                    tocLine = line;
                    continue;
                }

                if (SnippetKeyReader.TryExtractKeyFromLine(line, out var key))
                {
                    builder.Clear();

                    void AppendLine(string s)
                    {
                        builder.Append(s);
                        builder.Append(newLine);
                    }

                    ProcessSnippetLine(AppendLine, missingSnippets, usedSnippets, key, line);
                    builder.TrimEnd();
                    line.Current = builder.ToString();
                }
            }

            if (writeHeader)
            {
                lines.Insert(0, new Line(HeaderWriter.WriteHeader(relativePath !, header, newLine), "", 0));
            }

            if (tocLine != null)
            {
                tocLine.Current = TocBuilder.BuildToc(headerLines, tocLevel, tocExcludes, newLine);
            }

            return(new ProcessResult(
                       missingSnippets: missingSnippets,
                       usedSnippets: usedSnippets.Distinct().ToList(),
                       usedIncludes: usedIncludes.Distinct().ToList(),
                       missingIncludes: missingIncludes,
                       validationErrors: validationErrors));
        }
 public int GetCountWithStatus(ContentValidation.ValidationStatus status)
 {
     return this.Instances.Where(i => i.Status == status).Count();
 }
 public Task CheckInvalidWord()
 {
     return(Verifier.Verify(ContentValidation.Verify(" you ")));
 }
 public void CheckInvalidWordDoesNotThrowWhenNoMatch()
 {
     Assert.Empty(ContentValidation.Verify(" some random content which doesn't contain invalid words. "));
 }
 public void CheckInvalidWordDoesNotThrowWhenIsQuote()
 {
     Assert.Empty(ContentValidation.Verify("> you "));
 }
 public Task CheckInvalidWordStringEnd()
 {
     return(Verifier.Verify(ContentValidation.Verify("the you")));
 }
 public Task CheckInvalidWordWithComma()
 {
     return(Verifier.Verify(ContentValidation.Verify(" you, ")));
 }
 public Task CheckInvalidWordWithQuestionMark()
 {
     return(Verifier.Verify(ContentValidation.Verify(" you? ")));
 }
 public Task CheckInvalidWordIndicatesAllViolationsInTheExceptionMessageIgnoringCase()
 {
     return(Verifier.Verify(ContentValidation.Verify(" you, and you again! Still Yourself? Us")));
 }
示例#13
0
 public Task CheckInvalidWordSentenceStart()
 {
     return(Verify(ContentValidation.Verify("you ")));
 }