public void ValidSnippet_ReturnsTrue_IfAllFieldsValid()
        {
            // Arrange

            // Act
            var valid = validator.Validate(availableLanguages, validLanguage, validCode);

            // Assert
            Assert.IsTrue(valid);
        }
Beispiel #2
0
        protected override IEnumerable <SnippetValidationResult> Validate(SnippetValidationContext context)
        {
            foreach (SnippetValidationResult result in _defaultValidator.Validate(context.Snippet))
            {
                yield return(result);
            }

            if (context.Snippet.Author != "Josef Pihrt")
            {
                yield return(new SnippetValidationResult(
                                 context.Snippet,
                                 string.Empty,
                                 "Snippet author is not 'Josef Pihrt'.",
                                 ResultImportance.Information));
            }

            if (context.Snippet.CodeText.Contains("\t"))
            {
                yield return(new SnippetValidationResult(
                                 context.Snippet,
                                 string.Empty,
                                 "Snippet code contains tab.",
                                 ResultImportance.Information));
            }

            if (context.Snippet.Shortcut.Any(f => char.IsWhiteSpace(f)))
            {
                yield return(new SnippetValidationResult(
                                 context.Snippet,
                                 string.Empty,
                                 "Snippet shortcut contains white-space.",
                                 ResultImportance.Information));
            }

            if (RegexHelper.TrimEnd.IsMatch(context.Snippet.CodeText))
            {
                yield return(new SnippetValidationResult(
                                 context.Snippet,
                                 string.Empty,
                                 "Snippet code contains trailing white-space.",
                                 ResultImportance.Information));
            }

            Match match = RegexHelper.InvalidLeadingSpaces.Match(context.Snippet.CodeText);

            if (match.Success)
            {
                Console.WriteLine(match.Value);

                yield return(new SnippetValidationResult(
                                 context.Snippet,
                                 string.Empty,
                                 "Snippet code contains invalid leading spaces.",
                                 ResultImportance.Information));
            }
        }