Exemplo n.º 1
0
        public void ShouldCalculateLength()
        {
            var counter = new LengthCounter();
            var result  = counter.calculate("I have a transportation device which is a red bike which I love to ride.");

            Assert.Contains("1, 4", result);
            Assert.Contains("4, 4", result);
            Assert.Contains("14, 1", result);
            Assert.Contains("6, 1", result);
            Assert.Contains("5, 2", result);
            Assert.Contains("2, 2", result);
            Assert.Contains("3, 1", result);
        }
        public static IEnumerable <ObjectElementValidationError> CheckLength(IObjectElementValue value, IElementConstraints elementConstraints)
        {
            var textValue = TextValueExtractor(value);

            if (string.IsNullOrEmpty(textValue))
            {
                return(Array.Empty <ObjectElementValidationError>());
            }

            var constraints = (FormattedTextElementConstraints)elementConstraints;

            if (!constraints.MaxSymbols.HasValue)
            {
                return(Array.Empty <ObjectElementValidationError>());
            }

            var textLength = new LengthCounter()
                             .GetLength(textValue);

            return(textLength > constraints.MaxSymbols.Value
                ? new[] { new ElementTextTooLongError(constraints.MaxSymbols.Value, textLength) }
                : Array.Empty <ObjectElementValidationError>());
        }
Exemplo n.º 3
0
 protected AbstractLengthCounterTest(int maxlen)
 {
     this.maxlen   = maxlen;
     lengthCounter = new LengthCounter(maxlen);
 }