Beispiel #1
0
        public void EvaluateShouldReturnSuccessForNullValue()
        {
            // arrange
            var rule = new SizeRule<IEnumerable<int>>( 1 );
            var property = new Property<IEnumerable<int>>( "Points", null );
            var expected = ValidationResult.Success;

            // act
            var actual = rule.Evaluate( property );

            // assert
            Assert.Equal( expected, actual );
        }
Beispiel #2
0
 public BoxStyle(SizeRule sizeRule, float sizeX = 0, float sizeY = 0, TextAlignment align = TextAlignment.LEFT, float padding = 0)
 {
     SizeRule = sizeRule;
     if (sizeRule == SizeRule.Auto)
     {
         Size = new Vector2();
     }
     else if (sizeRule == SizeRule.Fix)
     {
         Size = new Vector2(sizeX, sizeY);
     }
     Align   = align;
     Padding = padding;
 }
Beispiel #3
0
        public DefaultValidation()
        {
            IRule trim = new TrimLeadingWhitespace();

            PrimitiveRuleBindings.Add(new RuleBinding("*", "FT", trim));
            PrimitiveRuleBindings.Add(new RuleBinding("*", "ST", trim));
            PrimitiveRuleBindings.Add(new RuleBinding("*", "TX", trim));

            IRule size200   = new SizeRule(200);
            IRule size65536 = new SizeRule(65536);

            PrimitiveRuleBindings.Add(new RuleBinding("*", "FT", size65536));
            PrimitiveRuleBindings.Add(new RuleBinding("*", "ID", size200));
            PrimitiveRuleBindings.Add(new RuleBinding("*", "IS", size200));
        }
Beispiel #4
0
        /// <summary>   Initializes a new instance of the DefaultValidation class. </summary>
        public DefaultValidation()
        {
            IRule trim = new TrimLeadingWhitespace();

            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "FT", trim));
            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "ST", trim));
            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "TX", trim));

            IRule size200   = new SizeRule(200);
            IRule size32000 = new SizeRule(32000);

            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "FT", size32000));
            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "ID", size200));
            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "IS", size200));

            IRule nonNegativeInteger = new RegexPrimitiveRule("\\d*", "");

            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "SI", nonNegativeInteger));

            IRule number = new RegexPrimitiveRule("(\\+|\\-)?\\d*\\.?\\d*", "");

            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "NM", number));

            //IRule telephoneNumber = new RegexPrimitiveRule("(\\d{1,2} )?(\\(\\d{3}\\))?\\d{3}-\\d{4}(X\\d{1,5})?(B\\d{1,5})?(C.*)?", "Version 2.4 Section 2.9.45");
            //PrimitiveRuleBindings.Add(new RuleBinding("*", "TN", telephoneNumber));

            System.String datePattern = "(\\d{4}([01]\\d(\\d{2})?)?)?"; //YYYY[MM[DD]]
            IRule         date        = new RegexPrimitiveRule(datePattern, "Version 2.5 Section 2.16.24");

            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "DT", date));

            System.String timePattern = "([012]\\d([0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?([\\+\\-]\\d{4})?";
            IRule         time        = new RegexPrimitiveRule(timePattern, "Version 2.5 Section 2.16.79");

            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "TM", time));

            System.String datetimePattern =
                "(\\d{4}([01]\\d(\\d{2}([012]\\d([0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?)?)?)?([\\+\\-]\\d{4})?";
            IRule datetime = new RegexPrimitiveRule(datetimePattern, "Version 2.5 Section 2.16.25");

            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "TSComponentOne", datetime));
            this.PrimitiveRuleBindings.Add(new RuleBinding("*", "DTM", datetime));
        }
Beispiel #5
0
        public void EvaluateShouldReturnExpectedResultForInvalidValue( int count )
        {
            // arrange
            var value = Enumerable.Range( 1, count );
            var rule = new SizeRule<IEnumerable<int>>( 1, 10 );
            var property = new Property<IEnumerable<int>>( "Points", value );

            // act
            var actual = rule.Evaluate( property );

            // assert
            Assert.Equal( "The Points field must be a sequence with a minimum count of 1 and a maximum count of 10.", actual.ErrorMessage );
            Assert.Equal( 1, actual.MemberNames.Count() );
            Assert.Equal( "Points", actual.MemberNames.Single() );
        }