コード例 #1
0
        // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
        private static void VerifyTextConstraints(int templateCode, TextElementConstraints textElementConstraints)
        {
            if (textElementConstraints.MaxSymbols < textElementConstraints.MaxSymbolsPerWord)
            {
                throw new TemplateValidationException(templateCode, TemplateElementValidationError.InvalidMaxSymbolsPerWord);
            }

            if (textElementConstraints.MaxSymbols <= 0)
            {
                throw new TemplateValidationException(templateCode, TemplateElementValidationError.NegativeMaxSymbols);
            }

            if (textElementConstraints.MaxSymbolsPerWord <= 0)
            {
                throw new TemplateValidationException(templateCode, TemplateElementValidationError.NegativeMaxSymbolsPerWord);
            }

            if (textElementConstraints.MaxLines <= 0)
            {
                throw new TemplateValidationException(templateCode, TemplateElementValidationError.NegativeMaxLines);
            }
        }
コード例 #2
0
        internal static void InternalTextChecksTest(
            IEnumerable <Validator> allChecks,
            bool containsRestrictedSymbols,
            int expectedErrorsCount,
            IObjectElementValue value,
            TextElementConstraints constraints)
        {
            var errors = new List <ObjectElementValidationError>();

            foreach (var validator in allChecks)
            {
                errors.AddRange(validator(value, constraints));
            }

            Assert.Equal(expectedErrorsCount, errors.Count);
            if (containsRestrictedSymbols)
            {
                Assert.Equal(1, errors.OfType <NonBreakingSpaceSymbolError>().Count());
                Assert.Equal(1, errors.OfType <ControlCharactersInTextError>().Count());
            }

            if (constraints.MaxSymbols.HasValue)
            {
                Assert.Equal(1, errors.OfType <ElementTextTooLongError>().Count());
            }

            if (constraints.MaxLines.HasValue)
            {
                Assert.Equal(1, errors.OfType <TooManyLinesError>().Count());
            }

            if (constraints.MaxSymbolsPerWord.HasValue)
            {
                Assert.Equal(1, errors.OfType <ElementWordsTooLongError>().Count());
            }
        }