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); }
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); }
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); }
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); }
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); }
public void TestTextCheckMarkup() { var value = new TextElementValue { Raw = "<br/><br /><br><ul><li><b><i><strong> text </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); }
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); }
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); }
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); }
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)); }
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); }
public void TestTextCheckTags() { var value = new TextElementValue { Raw = "<br/><br /><br><ul><li><b><i><strong> text </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); }
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); }
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); }
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); }
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); }
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); }
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); }