Esempio n. 1
0
        public void TestTextCheckLength()
        {
            const int MaxSymbols = 10;
            var       value      = new TextElementValue {
                Raw = new string('a', MaxSymbols)
            };
            var constraints = new FormattedTextElementConstraints {
                MaxSymbols = MaxSymbols
            };

            var error = TestHelpers.MakeValidationCheck <TextElementValue, ElementTextTooLongError>(
                value,
                constraints,
                FormattedTextValidator.CheckLength,
                val => val.Raw = new string('b', MaxSymbols + 1));

            Assert.Equal(MaxSymbols, error.MaxLength);
            Assert.Equal(value.Raw.Length, error.ActualLength);

            value.Raw = "<i><b>" + new string('a', MaxSymbols) + "</b></i>";
            error     = TestHelpers.MakeValidationCheck <TextElementValue, ElementTextTooLongError>(
                value,
                constraints,
                FormattedTextValidator.CheckLength,
                val => val.Raw = "<i><b>" + new string('b', MaxSymbols + 1) + "</b></i>");
            Assert.Equal(MaxSymbols, error.MaxLength);
            Assert.Equal(MaxSymbols + 1, error.ActualLength);
            Assert.Equal(nameof(constraints.MaxSymbols), error.ErrorType);
        }
Esempio n. 2
0
        public void TestTextCheckRestrictedSymbols()
        {
            const string AllChars = "abcdefghijklmnopqrstuvwxyz \n\t абвгдеёжзийклмнопрстуфхцчшщьыъэюя 1234567890 \\ \" .,;:~'`!? №@#$%^&_ []{}()<> /*-+=";
            var          value    = new TextElementValue {
                Raw = AllChars
            };
            var constraints = new PlainTextElementConstraints();

            var errorSpace = TestHelpers.MakeValidationCheck <TextElementValue, NonBreakingSpaceSymbolError>(
                value,
                constraints,
                PlainTextValidator.CheckRestrictedSymbols,
                val => val.Raw = "\x00A0");

            Assert.Equal(nameof(constraints.WithoutNonBreakingSpace), errorSpace.ErrorType);

            value.Raw = AllChars.ToUpper();
            var errorControlChars = TestHelpers.MakeValidationCheck <TextElementValue, ControlCharactersInTextError>(
                value,
                constraints,
                PlainTextValidator.CheckRestrictedSymbols,
                val => val.Raw = "\r");

            Assert.Equal(nameof(constraints.WithoutControlChars), errorControlChars.ErrorType);
        }
Esempio n. 3
0
        public void TestHttpsLinkValidation()
        {
            var value = new TextElementValue {
                Raw = "https://дубль-гис.рф"
            };
            var constraints = new LinkElementConstraints();

            var error = TestHelpers.MakeValidationCheck <TextElementValue, IncorrectLinkError>(
                value,
                constraints,
                LinkValidator.CheckLink,
                val => val.Raw = "https://abc. com");

            Assert.Equal(nameof(constraints.ValidLink), error.ErrorType);
        }
Esempio n. 4
0
        public void TestTextCheckListElements()
        {
            var value = new TextElementValue {
                Raw = "<ul><li> list item </li></ul>"
            };
            var constraints = new FormattedTextElementConstraints();

            var error = TestHelpers.MakeValidationCheck <TextElementValue, UnsupportedListElementsError>(
                value,
                constraints,
                FormattedTextValidator.CheckUnsupportedListElements,
                val => val.Raw = "<ul><hr></ul>");

            Assert.Equal(nameof(constraints.SupportedListElements), error.ErrorType);
        }
Esempio n. 5
0
        public void TestTextCheckNestedList()
        {
            var value = new TextElementValue {
                Raw = "<ul><li> list item </li></ul>"
            };
            var constraints = new FormattedTextElementConstraints();

            var error = TestHelpers.MakeValidationCheck <TextElementValue, NestedListError>(
                value,
                constraints,
                FormattedTextValidator.CheckNestedList,
                val => val.Raw = "<ul><li> outer list <ul><li> inner list </li></ul> </li></ul>");

            Assert.Equal(nameof(constraints.NoNestedLists), error.ErrorType);
        }
Esempio n. 6
0
        public void TestTextCheckMarkup()
        {
            var value = new TextElementValue {
                Raw = "<br/><br /><br><ul><li><b><i><strong> text &nbsp; </strong><i/></b></li><em>small</em><li></li></ul>"
            };
            var constraints = new FormattedTextElementConstraints();

            var error = TestHelpers.MakeValidationCheck <TextElementValue, InvalidHtmlError>(
                value,
                constraints,
                FormattedTextValidator.CheckValidHtml,
                val => val.Raw += "<ul>");

            Assert.Equal(nameof(constraints.ValidHtml), error.ErrorType);
        }
Esempio n. 7
0
        public void TestAllChecks(string text, int?maxLength, int?maxWordLength, int?maxLines, bool containsRestrictedSymbols = true, int expectedErrorsCount = 5)
        {
            IObjectElementValue value = new TextElementValue {
                Raw = text
            };
            var constraints = new PlainTextElementConstraints {
                MaxLines = maxLines, MaxSymbols = maxLength, MaxSymbolsPerWord = maxWordLength
            };

            TestHelpers.InternalTextChecksTest(AllChecks, containsRestrictedSymbols, expectedErrorsCount, value, constraints);

            value = new FasElementValue {
                Raw = "custom", Text = text
            };
            TestHelpers.InternalTextChecksTest(AllChecks, containsRestrictedSymbols, expectedErrorsCount, value, constraints);
        }
Esempio n. 8
0
        public void TestLinkLengthValidation()
        {
            var value = new TextElementValue {
                Raw = "http://дубль-гис.рф"
            };
            var constraints = new LinkElementConstraints {
                MaxSymbols = value.Raw.Length
            };

            var error = TestHelpers.MakeValidationCheck <TextElementValue, ElementTextTooLongError>(
                value,
                constraints,
                PlainTextValidator.CheckLength,
                val => val.Raw += "/");

            Assert.Equal(nameof(constraints.MaxSymbols), error.ErrorType);
        }
Esempio n. 9
0
        public void TestLinkWithRtlAndLtrValidation()
        {
            var value = new TextElementValue {
                Raw = "http://дубль-гис.рф"
            };
            var constraints = new LinkElementConstraints {
                MaxSymbols = value.Raw.Length
            };

            var error = TestHelpers.MakeValidationCheck <TextElementValue, IncorrectLinkError>(
                value,
                constraints,
                LinkValidator.CheckLink,
                val => val.Raw = "\u200fhttp://дубль-гис.рф\u200e");

            Assert.Equal(nameof(constraints.ValidLink), error.ErrorType);
        }
Esempio n. 10
0
        public void TestAllChecks(string text, int?maxLength, int?maxWordLength, int?maxLines, bool containsRestrictedSymbols = true, int expectedErrorsCount = 5)
        {
            IObjectElementValue value = new TextElementValue {
                Raw = text
            };
            var constraints = new FormattedTextElementConstraints {
                MaxLines = maxLines, MaxSymbols = maxLength, MaxSymbolsPerWord = maxWordLength
            };

            TestHelpers.InternalTextChecksTest(AllChecks, containsRestrictedSymbols, expectedErrorsCount, value, constraints);

            // FasComment cannot be formatted:
            value = new FasElementValue {
                Raw = "custom", Text = text
            };
            Assert.Throws <InvalidCastException>(() => TestHelpers.InternalTextChecksTest(AllChecks, containsRestrictedSymbols, expectedErrorsCount, value, constraints));
        }
Esempio n. 11
0
        public void TestTextCheckAttributes()
        {
            var value = new TextElementValue {
                Raw = "<b></b>"
            };
            var constraints = new FormattedTextElementConstraints();

            var error = TestHelpers.MakeValidationCheck <TextElementValue, UnsupportedAttributesError>(
                value,
                constraints,
                FormattedTextValidator.CheckAttributesAbsence,
                val => val.Raw = "<b class='err'><i onclick='alert(123)'></i></b>");

            Assert.Equal(2, error.UnsupportedAttributes.Count);
            Assert.Equal(error.UnsupportedAttributes, new[] { "class", "onclick" });
            Assert.Equal(nameof(constraints.SupportedAttributes), error.ErrorType);
        }
Esempio n. 12
0
        public void TestTextCheckTags()
        {
            var value = new TextElementValue {
                Raw = "<br/><br /><br><ul><li><b><i><strong> text &nbsp; </strong><i/></b></li><em>small</em><li></li></ul>"
            };
            var constraints = new FormattedTextElementConstraints();

            var error = TestHelpers.MakeValidationCheck <TextElementValue, UnsupportedTagsError>(
                value,
                constraints,
                FormattedTextValidator.CheckSupportedHtmlTags,
                val => val.Raw = "<html><head></head><body><p></p><hr></body></html>");

            Assert.Equal(5, error.UnsupportedTags.Count);
            Assert.Equal(error.UnsupportedTags, new[] { "html", "head", "body", "p", "hr" });
            Assert.Equal(nameof(constraints.SupportedTags), error.ErrorType);
        }
Esempio n. 13
0
        public void TestTextCheckMaxLines()
        {
            var value = new TextElementValue {
                Raw = "1 <br> 2 <br/> 3 <br /> 4 \n 4"
            };
            var constraints = new FormattedTextElementConstraints {
                MaxLines = 4
            };

            var error = TestHelpers.MakeValidationCheck <TextElementValue, TooManyLinesError>(
                value,
                constraints,
                FormattedTextValidator.CheckLinesCount,
                val => val.Raw += "<ul><li> 5 </li></ul>");

            Assert.Equal(constraints.MaxLines, error.MaxLinesCount);
            Assert.Equal(constraints.MaxLines + 1, error.ActualLinesCount);
            Assert.Equal(nameof(constraints.MaxLines), error.ErrorType);
        }
Esempio n. 14
0
        public void TestTextCheckMaxLines()
        {
            const int MaxLines = 10;
            var       value    = new TextElementValue {
                Raw = new string('\n', MaxLines - 1)
            };
            var constraints = new PlainTextElementConstraints {
                MaxLines = MaxLines
            };

            var error = TestHelpers.MakeValidationCheck <TextElementValue, TooManyLinesError>(
                value,
                constraints,
                PlainTextValidator.CheckLinesCount,
                val => val.Raw = new string('\n', MaxLines));

            Assert.Equal(MaxLines, error.MaxLinesCount);
            Assert.Equal(MaxLines + 1, error.ActualLinesCount);
            Assert.Equal(nameof(constraints.MaxLines), error.ErrorType);
        }
Esempio n. 15
0
        public void TestTextCheckLength()
        {
            const int MaxSymbols = 50;
            var       value      = new TextElementValue {
                Raw = new string('a', MaxSymbols)
            };
            var constraints = new PlainTextElementConstraints {
                MaxSymbols = MaxSymbols
            };

            var error = TestHelpers.MakeValidationCheck <TextElementValue, ElementTextTooLongError>(
                value,
                constraints,
                PlainTextValidator.CheckLength,
                val => val.Raw = new string('b', MaxSymbols + 1));

            Assert.Equal(MaxSymbols, error.MaxLength);
            Assert.Equal(MaxSymbols + 1, error.ActualLength);
            Assert.Equal(nameof(constraints.MaxSymbols), error.ErrorType);
        }
Esempio n. 16
0
        public void TestTextCheckLongWords()
        {
            const int MaxSymbols = 10;
            var       value      = new TextElementValue {
                Raw = new string('a', MaxSymbols)
            };
            var constraints = new PlainTextElementConstraints {
                MaxSymbolsPerWord = MaxSymbols
            };

            var error = TestHelpers.MakeValidationCheck <TextElementValue, ElementWordsTooLongError>(
                value,
                constraints,
                PlainTextValidator.CheckWordsLength,
                val => val.Raw = new string('b', MaxSymbols + 1));

            Assert.Equal(MaxSymbols, error.MaxWordLength);
            Assert.Equal(1, error.TooLongWords.Count);
            Assert.Equal(value.Raw, error.TooLongWords.First());
            Assert.Equal(nameof(constraints.MaxSymbolsPerWord), error.ErrorType);
        }
Esempio n. 17
0
        public void TestLinkSchemeValidation()
        {
            var value = new TextElementValue {
                Raw = "http://дубль-гис.рф"
            };
            var constraints = new LinkElementConstraints();

            var error = TestHelpers.MakeValidationCheck <TextElementValue, IncorrectLinkError>(
                value,
                constraints,
                LinkValidator.CheckLink,
                val => val.Raw = "ftp://дубль-гис.рф");

            Assert.Equal(nameof(constraints.ValidLink), error.ErrorType);

            value.Raw = "http://xn----9sbhbxp9bk7f.xn--p1ai";
            error     = TestHelpers.MakeValidationCheck <TextElementValue, IncorrectLinkError>(
                value,
                constraints,
                LinkValidator.CheckLink,
                val => val.Raw = "file://дубль-гис.рф");
            Assert.Equal(nameof(constraints.ValidLink), error.ErrorType);
        }
Esempio n. 18
0
        public void TestLinkRestrictedSymbolsValidation()
        {
            var value = new TextElementValue {
                Raw = "http://дубль-гис.рф"
            };
            var constraints = new LinkElementConstraints();

            var controlCharsError = TestHelpers.MakeValidationCheck <TextElementValue, ControlCharactersInTextError>(
                value,
                constraints,
                PlainTextValidator.CheckRestrictedSymbols,
                val => val.Raw += "\r");

            Assert.Equal(nameof(constraints.WithoutControlChars), controlCharsError.ErrorType);

            value.Raw = "http://google.com/search?abc=123";
            var nonBreakingSpaceError = TestHelpers.MakeValidationCheck <TextElementValue, NonBreakingSpaceSymbolError>(
                value,
                constraints,
                PlainTextValidator.CheckRestrictedSymbols,
                val => val.Raw += (char)160);

            Assert.Equal(nameof(constraints.WithoutNonBreakingSpace), nonBreakingSpaceError.ErrorType);
        }