Exemplo n.º 1
0
        public void Min_MinimumIsDoubleAndTheValueIsLessThan_Fails()
        {
            double value = 0;
            var    sut   = new MinAttribute(1.1);

            Assert.IsFalse(sut.IsValid(value));
        }
Exemplo n.º 2
0
        public void Min_MinimumIsIntegerAndTheValueIsGreaterThan_Validates()
        {
            int value = 2;
            var sut   = new MinAttribute(1);

            Assert.IsTrue(sut.IsValid(value));
        }
Exemplo n.º 3
0
        private static Attribute ConvertToMin(XmlNhvmRuleConverterArgs rule)
        {
            NhvmMin minRule = (NhvmMin)rule.schemaRule;
            long    value   = 0;

            if (minRule.valueSpecified)
            {
                value = minRule.value;
            }

#if NETFX
            log.Info(string.Format("Converting to Min attribute with value {0}", value));
#else
            Log.Info("Converting to Min attribute with value {0}", value);
#endif
            MinAttribute thisAttribute = new MinAttribute();
            thisAttribute.Value = value;

            if (minRule.message != null)
            {
                thisAttribute.Message = minRule.message;
            }
            AssignTagsFromString(thisAttribute, minRule.tags);

            return(thisAttribute);
        }
Exemplo n.º 4
0
        public void Min_MinimumIsSpecifiedTypeAndTheValueIsLessThan_Fails()
        {
            long value = 0;
            var  sut   = new MinAttribute(typeof(long), "1");

            Assert.IsFalse(sut.IsValid(value));
        }
Exemplo n.º 5
0
        public void Min_MinimumIsSpecifiedTypeAndTheValueIsEqualTo_Validates()
        {
            long value = 1;
            var  sut   = new MinAttribute(typeof(long), "1");

            Assert.IsTrue(sut.IsValid(value));
        }
Exemplo n.º 6
0
        public void Extreme()
        {
            var v = new MinAttribute {
                Value = -10000
            };

            Assert.IsTrue(v.IsValid(-10000, null));
            Assert.IsTrue(v.IsValid(-10000L, null));
            Assert.IsTrue(v.IsValid(123UL, null));
            Assert.IsTrue(v.IsValid(123U, null));
            Assert.IsTrue(v.IsValid((ushort)5, null));
            Assert.IsTrue(v.IsValid((short)5, null));
            Assert.IsTrue(v.IsValid(true, null));
            Assert.IsTrue(v.IsValid((byte)100, null));
            Assert.IsTrue(v.IsValid((sbyte)100, null));
            Assert.IsTrue(v.IsValid(AEnum.A, null));
            Assert.IsTrue(v.IsValid(CarOptions.Spoiler | CarOptions.FogLights, null));
            Assert.IsTrue(v.IsValid('A', null));
            Assert.IsTrue(v.IsValid(-9999.99999f, null));
            Assert.IsTrue(v.IsValid(-9999.9999999999999999999999999d, null));

            Assert.IsFalse(v.IsValid(decimal.MinValue, null));
            Assert.IsFalse(v.IsValid(decimal.MinValue.ToString(), null));
            Assert.IsFalse(v.IsValid(double.MinValue, null));
            Assert.IsFalse(v.IsValid(double.MinValue + "9", null));
        }
Exemplo n.º 7
0
    public override void OnGUI(Rect position,
                               SerializedProperty property,
                               GUIContent label)
    {
        MinAttribute min = attribute as MinAttribute;

        if (property.propertyType == SerializedPropertyType.Float)
        {
            float vf = EditorGUI.FloatField(position,
                                            label.text,
                                            property.floatValue);
            property.floatValue = Mathf.Clamp(vf,
                                              min.minValue,
                                              float.MaxValue);
            return;
        }

        if (property.propertyType == SerializedPropertyType.Integer)
        {
            int vi = EditorGUI.IntField(position,
                                        label.text,
                                        property.intValue);
            property.intValue = Mathf.Clamp(vi,
                                            (int)min.minValue,
                                            int.MaxValue);
            return;
        }

        EditorGUI.LabelField(position,
                             label.text,
                             "Use range with float or int.");
    }
Exemplo n.º 8
0
        public void Min_MinimumIsIntegerAndTheValueIsLessThan_Fails()
        {
            int value = 0;
            var sut   = new MinAttribute(1);

            Assert.IsFalse(sut.IsValid(value));
        }
Exemplo n.º 9
0
        public void Min_MinimumIsDoubleAndTheValueIsEqualTo_Validates()
        {
            double value = 1.1;
            var    sut   = new MinAttribute(1.1);

            Assert.IsTrue(sut.IsValid(value));
        }
Exemplo n.º 10
0
        public void Min_MinimumIsDoubleAndTheValueIsGreaterThan_Validates()
        {
            double value = 2.2;
            var    sut   = new MinAttribute(1.1);

            Assert.IsTrue(sut.IsValid(value));
        }
Exemplo n.º 11
0
        public void Min_MinimumIsIntegerAndTheValueIsEqualTo_Validates()
        {
            int value = 1;
            var sut   = new MinAttribute(1);

            Assert.IsTrue(sut.IsValid(value));
        }
Exemplo n.º 12
0
        public void Min_FormatErrorMessage_ReturnsFormattedErrorMessage()
        {
            var sut = new MinAttribute(1);

            var error = sut.FormatErrorMessage("property");

            Assert.IsTrue(!string.IsNullOrEmpty(error));
        }
Exemplo n.º 13
0
        public void Min_FormatErrorMessageWithErrorMessage_ReturnsFormattedErrorMessage()
        {
            var sut = new MinAttribute(1);

            sut.ErrorMessage = "My error.";

            var error = sut.FormatErrorMessage("property");

            Assert.IsTrue(error == "My error.");
        }
Exemplo n.º 14
0
        public void Min_FormatErrorMessageWithErrorResource_ReturnsFormattedErrorMessage()
        {
            var sut = new MinAttribute(1);

            sut.ErrorMessageResourceName = "MinAttribute_Invalid";
            sut.ErrorMessageResourceType = typeof(DataAnnotationsResources);

            var error = sut.FormatErrorMessage("property");

            Assert.IsTrue(error == string.Format(DataAnnotationsResources.MinAttribute_Invalid, "property", 1));
        }
        public void ErrorMessageTest()
        {
            var attribute = new MinAttribute(1);

            attribute.ErrorMessage = "SampleErrorMessage";

            const string invalidValue = "a";

            var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null));

            Assert.AreEqual("SampleErrorMessage", result.ErrorMessage);
        }
        public void ErrorResourcesTest()
        {
            var attribute = new MinAttribute(1);

            attribute.ErrorMessageResourceName = "ErrorMessage";
            attribute.ErrorMessageResourceType = typeof(ErrorResources);

            const string invalidValue = "a";

            var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null));

            Assert.AreEqual(ErrorResources.ErrorMessage, result.ErrorMessage);
        }
        public void GlobalizedErrorResourcesTest()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");

            var attribute = new MinAttribute(1);

            attribute.ErrorMessageResourceName = "ErrorMessage";
            attribute.ErrorMessageResourceType = typeof(ErrorResources);

            const string invalidValue = "a";

            var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null));

            Assert.AreEqual("mensaje de error", result.ErrorMessage);
        }
Exemplo n.º 18
0
            public void Validate(Config c)
            {
                var typ = c.GetType();

                foreach (var field in typ.GetProperties())
                {
                    MinAttribute min = field.Get <MinAttribute>();
                    MaxAttribute max = field.Get <MaxAttribute>();

                    if (min == null && max == null)
                    {
                        continue;
                    }

                    object value = field.GetValue(c, index: null);

                    var opt = field.Get <OptAttribute>();
                    if (min != null)
                    {
                        var coercedMinVal = (IComparable)opt.Coerce(min.Value, field.PropertyType);
                        if (coercedMinVal.CompareTo(value) == 1)
                        {
                            throw new Exception(string.Format("invalid {0} ! {1} < {2}", opt.Name, value, coercedMinVal));
                        }
                    }
                    if (max != null)
                    {
                        var coercedMaxVal = (IComparable)opt.Coerce(max.Value, field.PropertyType);
                        if (coercedMaxVal.CompareTo(value) == -1)
                        {
                            throw new Exception(string.Format("invalid {0} ! {1} > {2}", opt.Name, value, coercedMaxVal));
                        }
                    }
                }

                if (c.HeartbeatInterval > c.ReadTimeout)
                {
                    throw new Exception(string.Format("HeartbeatInterval {0} must be less than ReadTimeout {1}",
                                                      c.HeartbeatInterval, c.ReadTimeout));
                }

                // TODO: PR go-nsq: this check was removed, seems still valid since the value can be set through code
                // https://github.com/bitly/go-nsq/commit/dd8e5fc4ad80922d884ece51f5574af3fa4f14d3#diff-b4bda758a2aef091432646c354b4dc59L376
                if (c.BackoffStrategy == null)
                {
                    throw new Exception(string.Format("BackoffStrategy cannot be null"));
                }
            }
Exemplo n.º 19
0
        public void IsValid()
        {
            var v = new MinAttribute();

            Assert.IsTrue(v.IsValid(0, null));
            v = new MinAttribute(2);
            Assert.IsTrue(v.IsValid(3, null));
            Assert.IsTrue(v.IsValid(2, null));
            Assert.IsTrue(v.IsValid((decimal)200.0, null));
            Assert.IsTrue(v.IsValid(null, null));
            Assert.IsTrue(v.IsValid("5", null));
            Assert.IsTrue(v.IsValid((long)int.MaxValue + 1, null));
            Assert.IsFalse(v.IsValid(1, null));
            Assert.IsFalse(v.IsValid("aaa", null));
            Assert.IsFalse(v.IsValid(new object(), null));
        }
        public void IsValidDoubleTests()
        {
            const double min = 3.50f;

            var attribute = new MinAttribute(min);

            Assert.IsTrue(attribute.IsValid(null));  // Optional values are always valid
            Assert.IsTrue(attribute.IsValid("4"));
            Assert.IsTrue(attribute.IsValid("4.5"));
            Assert.IsTrue(attribute.IsValid(100));
            Assert.IsTrue(attribute.IsValid("100.42"));
            Assert.IsFalse(attribute.IsValid(3));
            Assert.IsFalse(attribute.IsValid("3.498"));
            Assert.IsFalse(attribute.IsValid("-5"));
            Assert.IsFalse(attribute.IsValid("INVALID STRING"));
        }
Exemplo n.º 21
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     EditorGUI.BeginChangeCheck();
     EditorGUI.DefaultPropertyField(position, property, label);
     if (EditorGUI.EndChangeCheck())
     {
         MinAttribute minAttribute = (MinAttribute)attribute;
         if (property.propertyType == SerializedPropertyType.Float)
         {
             property.floatValue = Mathf.Max(minAttribute.min, property.floatValue);
         }
         else if (property.propertyType == SerializedPropertyType.Integer)
         {
             property.intValue = Mathf.Max((int)minAttribute.min, property.intValue);
         }
         else if (property.propertyType == SerializedPropertyType.Vector2)
         {
             var value = property.vector2Value;
             property.vector2Value = new Vector2(Mathf.Max(minAttribute.min, value.x), Mathf.Max(minAttribute.min, value.y));
         }
         else if (property.propertyType == SerializedPropertyType.Vector2Int)
         {
             var value = property.vector2IntValue;
             property.vector2IntValue = new Vector2Int(Mathf.Max((int)minAttribute.min, value.x), Mathf.Max((int)minAttribute.min, value.y));
         }
         else if (property.propertyType == SerializedPropertyType.Vector3)
         {
             var value = property.vector3Value;
             property.vector3Value = new Vector3(Mathf.Max(minAttribute.min, value.x), Mathf.Max(minAttribute.min, value.y), Mathf.Max(minAttribute.min, value.z));
         }
         else if (property.propertyType == SerializedPropertyType.Vector3Int)
         {
             var value = property.vector3IntValue;
             property.vector3IntValue = new Vector3Int(Mathf.Max((int)minAttribute.min, value.x), Mathf.Max((int)minAttribute.min, value.y), Mathf.Max((int)minAttribute.min, value.z));
         }
         else if (property.propertyType == SerializedPropertyType.Vector4)
         {
             var value = property.vector4Value;
             property.vector4Value = new Vector4(Mathf.Max(minAttribute.min, value.x), Mathf.Max(minAttribute.min, value.y), Mathf.Max(minAttribute.min, value.z), Mathf.Max(minAttribute.min, value.w));
         }
         else
         {
             EditorGUI.LabelField(position, label.text, "Use Min with float, int or Vector.");
         }
     }
 }
Exemplo n.º 22
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MinAttribute attribute = (MinAttribute)base.attribute;

            switch (property.propertyType)
            {
            case SerializedPropertyType.Integer:
                int valueI = EditorGUI.IntField(position, label, property.intValue);
                property.intValue = Mathf.Max(valueI, attribute.minInt);
                break;

            case SerializedPropertyType.Float:
                float valueF = EditorGUI.FloatField(position, label, property.floatValue);
                property.floatValue = Mathf.Max(valueF, attribute.minFloat);
                break;
            }
        }
        public void IsValidIntegerTests()
        {
            const int min       = 42;
            var       attribute = new MinAttribute(min);

            Assert.IsTrue(attribute.IsValid(null));  // Optional values are always valid
            Assert.IsTrue(attribute.IsValid("42"));
            Assert.IsTrue(attribute.IsValid(42.5));
            Assert.IsTrue(attribute.IsValid("50"));
            Assert.IsTrue(attribute.IsValid(100));
            Assert.IsTrue(attribute.IsValid("10000000000"));
            Assert.IsFalse(attribute.IsValid("41"));
            Assert.IsFalse(attribute.IsValid("10"));
            Assert.IsFalse(attribute.IsValid(0));
            Assert.IsFalse(attribute.IsValid("-1"));
            Assert.IsFalse(attribute.IsValid(-50));
            Assert.IsFalse(attribute.IsValid("fifty"));
        }
Exemplo n.º 24
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MinAttribute attribute = (MinAttribute)base.attribute;

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                int v = EditorGUI.IntField(position, label, property.intValue);
                property.intValue = (int)Mathf.Max(v, attribute.min);
            }
            else if (property.propertyType == SerializedPropertyType.Float)
            {
                float v = EditorGUI.FloatField(position, label, property.floatValue);
                property.floatValue = Mathf.Max(v, attribute.min);
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use Min with float or int.");
            }
        }
Exemplo n.º 25
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        MinAttribute min = (MinAttribute)attribute;

        if (property.propertyType == SerializedPropertyType.Float || property.propertyType == SerializedPropertyType.Integer)
        {
            if (property.floatValue < min.min)
            {
                property.floatValue = min.min;
            }
            label.text += " (>=" + min.min + ")";

            property.floatValue = EditorGUI.FloatField(position, label, property.floatValue);
        }
        else
        {
            Debug.LogError("Min Attribute does not support the type of the variable: " + property.name);
        }
    }
Exemplo n.º 26
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MinAttribute attribute = (MinAttribute)base.attribute;

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                int v = EditorGUI.IntField(position, label, property.intValue);
                property.intValue = (int)Mathf.Max(v, attribute.min);
            }
            else if (property.propertyType == SerializedPropertyType.Float)
            {
                float v = EditorGUI.FloatField(position, label, property.floatValue);
                property.floatValue = Mathf.Max(v, attribute.min);
            }
            else if (property.propertyType == SerializedPropertyType.Vector2)
            {
                Vector2 v = EditorGUI.Vector2Field(position, label, property.vector2Value);
                property.vector2Value = new Vector2(
                    Mathf.Max(v.x, attribute.min),
                    Mathf.Max(v.y, attribute.min));
            }
            else if (property.propertyType == SerializedPropertyType.Vector3)
            {
                Vector3 v = EditorGUI.Vector2Field(position, label, property.vector3Value);
                property.vector3Value = new Vector3(
                    Mathf.Max(v.x, attribute.min),
                    Mathf.Max(v.y, attribute.min),
                    Mathf.Max(v.z, attribute.min));
            }
            else if (property.propertyType == SerializedPropertyType.Vector4)
            {
                Vector4 v = EditorGUI.Vector2Field(position, label, property.vector4Value);
                property.vector4Value = new Vector4(
                    Mathf.Max(v.x, attribute.min),
                    Mathf.Max(v.y, attribute.min),
                    Mathf.Max(v.z, attribute.min),
                    Mathf.Max(v.w, attribute.min));
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use Min with int, float, or vector2/3/4.");
            }
        }
Exemplo n.º 27
0
        private static string WriteExtenders(PropertyInfo p, out bool isValidatable)
        {
            isValidatable = false;
            StringBuilder sb = new StringBuilder();

            sb.Append(".extend({ editState : false, disableValidation : false, empty : true })");

            RequiredAttribute requiredAttribute = p.GetCustomAttribute <RequiredAttribute>();

            if (requiredAttribute != null)
            {
                sb.Append($".extend({{ required: {{ message: \"{requiredAttribute.FormatErrorMessage(p.Name)}\", onlyIf: function() {{ return ko.utils.isPropertyValidatable(self, \"{ p.Name}\"); }} }} }})");
                isValidatable = true;
            }

            MinLengthAttribute minLengthAttribute = p.GetCustomAttribute <MinLengthAttribute>();

            if (minLengthAttribute != null)
            {
                sb.Append(string.Format(".extend({ minLength: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", minLengthAttribute.FormatErrorMessage(p.Name), minLengthAttribute.Length, p.Name));
                isValidatable = true;
            }

            MaxLengthAttribute maxLengthAttribute = p.GetCustomAttribute <MaxLengthAttribute>();

            if (maxLengthAttribute != null)
            {
                sb.Append(string.Format(".extend({ maxLength: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", maxLengthAttribute.FormatErrorMessage(p.Name), maxLengthAttribute.Length, p.Name));
                isValidatable = true;
            }

            RegularExpressionAttribute regularExpressionAttribute = p.GetCustomAttribute <RegularExpressionAttribute>();

            if (regularExpressionAttribute != null)
            {
                sb.Append(string.Format(".extend({ pattern: { message: \"{0}\", params: /{1}/, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", regularExpressionAttribute.FormatErrorMessage(p.Name), regularExpressionAttribute.Pattern, p.Name));
                isValidatable = true;
            }

            UrlAttribute urlAttribute = p.GetCustomAttribute <UrlAttribute>();

            if (urlAttribute != null)
            {
                sb.Append(string.Format(".extend({ pattern: { message: \"{0}\", params: /{1}/, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", urlAttribute.FormatErrorMessage(p.Name), urlAttribute, p.Name));
                isValidatable = true;
            }

            DateAttribute dateAttribute = p.GetCustomAttribute <DateAttribute>();

            if (dateAttribute != null)
            {
                sb.Append(string.Format(".extend({ date: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } })", dateAttribute.FormatErrorMessage(p.Name), p.Name));
                isValidatable = true;
            }

            NumericAttribute numericAttribute = p.GetCustomAttribute <NumericAttribute>();

            if (numericAttribute != null)
            {
                sb.Append(
                    string.Format(".extend({ number: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } }).extend({ numeric: {2} })",
                                  numericAttribute.FormatErrorMessage(p.Name), p.Name, numericAttribute.Precision));
                isValidatable = true;
            }

            EmailAttribute emailAttribute = p.GetCustomAttribute <EmailAttribute>();

            if (emailAttribute != null)
            {
                sb.Append(string.Format(".extend({ email: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } })", emailAttribute.FormatErrorMessage(p.Name), p.Name));
                isValidatable = true;
            }

            DigitsAttribute digitsAttribute = p.GetCustomAttribute <DigitsAttribute>();

            if (digitsAttribute != null)
            {
                sb.Append(string.Format(".extend({ digit: { message: \"{0}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{1}\"); } } }).extend({ numeric: 0 })", digitsAttribute.FormatErrorMessage(p.Name), p.Name));
                isValidatable = true;
            }

            MinAttribute minAttribute = p.GetCustomAttribute <MinAttribute>();

            if (minAttribute != null)
            {
                sb.Append(string.Format(".extend({ min: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", minAttribute.FormatErrorMessage(p.Name), minAttribute.Min, p.Name));
                isValidatable = true;
            }

            MaxAttribute maxAttribute = p.GetCustomAttribute <MaxAttribute>();

            if (maxAttribute != null)
            {
                sb.Append(string.Format(".extend({ max: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", maxAttribute.FormatErrorMessage(p.Name), maxAttribute.Max, p.Name));
                isValidatable = true;
            }

            EqualToAttribute equalToAttribute = p.GetCustomAttribute <EqualToAttribute>();

            if (equalToAttribute != null)
            {
                sb.Append(string.Format(".extend({ equal: { message: \"{0}\", params: {1}, onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", equalToAttribute.FormatErrorMessage(p.Name), equalToAttribute.OtherProperty, p.Name));
                isValidatable = true;
            }

            CompareAttribute compareAttribute = p.GetCustomAttribute <CompareAttribute>();

            if (compareAttribute != null)
            {
                sb.Append(string.Format(".extend({ equal: { message: \"{0}\", params: \"{1}\", onlyIf: function() { return ko.utils.isPropertyValidatable(self, \"{2}\"); } } })", compareAttribute.FormatErrorMessage(p.Name), compareAttribute.OtherProperty, p.Name));
                isValidatable = true;
            }

            FormatterAttribute formatterAttribute = p.GetCustomAttribute <FormatterAttribute>();

            if (formatterAttribute != null)
            {
                sb.Append(string.Format(".formatted({0}, {1})", formatterAttribute.Formatter, JsonConvert.SerializeObject(formatterAttribute.Arguments)));
            }

            return(sb.ToString());
        }
        public void CheckDoubleValidation(double value, bool expected)
        {
            var attribute = new MinAttribute(0);

            Assert.Equal(expected, attribute.IsValid(value));
        }
Exemplo n.º 29
0
        public void Min_EmptyValue_Validates()
        {
            var sut = new MinAttribute(1);

            Assert.IsTrue(sut.IsValid(string.Empty));
        }
        public void KnownRulesConvertAssing()
        {
            NhvMapping       map = XmlMappingLoader.GetXmlMappingFor(typeof(WellKnownRules));
            NhvmClass        cm  = map.@class[0];
            XmlClassMapping  rm  = new XmlClassMapping(cm);
            MemberInfo       mi;
            List <Attribute> attributes;

            mi         = typeof(WellKnownRules).GetField("AP");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            Assert.AreEqual("A string value", ((ACustomAttribute)attributes[0]).Value1);
            Assert.AreEqual(123, ((ACustomAttribute)attributes[0]).Value2);
            Assert.AreEqual("custom message", ((ACustomAttribute)attributes[0]).Message);

            mi         = typeof(WellKnownRules).GetField("StrProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            NotEmptyAttribute nea = FindAttribute <NotEmptyAttribute>(attributes);

            Assert.AreEqual("not-empty message", nea.Message);

            NotNullAttribute nna = FindAttribute <NotNullAttribute>(attributes);

            Assert.AreEqual("not-null message", nna.Message);

            NotNullNotEmptyAttribute nnea = FindAttribute <NotNullNotEmptyAttribute>(attributes);

            Assert.AreEqual("notnullnotempty message", nnea.Message);

            LengthAttribute la = FindAttribute <LengthAttribute>(attributes);

            Assert.AreEqual("length message", la.Message);
            Assert.AreEqual(1, la.Min);
            Assert.AreEqual(10, la.Max);

            PatternAttribute pa = FindAttribute <PatternAttribute>(attributes);

            Assert.AreEqual("pattern message", pa.Message);
            Assert.AreEqual("[0-9]+", pa.Regex);
            Assert.AreEqual(RegexOptions.Compiled, pa.Flags);

            EmailAttribute ea = FindAttribute <EmailAttribute>(attributes);

            Assert.AreEqual("email message", ea.Message);

            IPAddressAttribute ipa = FindAttribute <IPAddressAttribute>(attributes);

            Assert.AreEqual("ipAddress message", ipa.Message);

            EANAttribute enaa = FindAttribute <EANAttribute>(attributes);

            Assert.AreEqual("ean message", enaa.Message);

            CreditCardNumberAttribute ccna = FindAttribute <CreditCardNumberAttribute>(attributes);

            Assert.AreEqual("creditcardnumber message", ccna.Message);

            IBANAttribute iban = FindAttribute <IBANAttribute>(attributes);

            Assert.AreEqual("iban message", iban.Message);

            mi         = typeof(WellKnownRules).GetField("DtProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            FutureAttribute fa = FindAttribute <FutureAttribute>(attributes);

            Assert.AreEqual("future message", fa.Message);
            PastAttribute psa = FindAttribute <PastAttribute>(attributes);

            Assert.AreEqual("past message", psa.Message);

            mi         = typeof(WellKnownRules).GetField("DecProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            DigitsAttribute dga = FindAttribute <DigitsAttribute>(attributes);

            Assert.AreEqual("digits message", dga.Message);
            Assert.AreEqual(5, dga.IntegerDigits);
            Assert.AreEqual(2, dga.FractionalDigits);

            MinAttribute mina = FindAttribute <MinAttribute>(attributes);

            Assert.AreEqual("min message", mina.Message);
            Assert.AreEqual(100, mina.Value);

            MaxAttribute maxa = FindAttribute <MaxAttribute>(attributes);

            Assert.AreEqual("max message", maxa.Message);
            Assert.AreEqual(200, maxa.Value);

            DecimalMaxAttribute decimalmaxa = FindAttribute <DecimalMaxAttribute>(attributes);

            Assert.AreEqual("decimal max message", decimalmaxa.Message);
            Assert.AreEqual(200.1m, decimalmaxa.Value);

            DecimalMinAttribute decimalmina = FindAttribute <DecimalMinAttribute>(attributes);

            Assert.AreEqual("decimal min message", decimalmina.Message);
            Assert.AreEqual(99.9m, decimalmina.Value);

            mi         = typeof(WellKnownRules).GetField("BProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            AssertTrueAttribute ata = FindAttribute <AssertTrueAttribute>(attributes);

            Assert.AreEqual("asserttrue message", ata.Message);
            AssertFalseAttribute afa = FindAttribute <AssertFalseAttribute>(attributes);

            Assert.AreEqual("assertfalse message", afa.Message);


            mi         = typeof(WellKnownRules).GetField("ArrProp");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            SizeAttribute sa = FindAttribute <SizeAttribute>(attributes);

            Assert.AreEqual("size message", sa.Message);
            Assert.AreEqual(2, sa.Min);
            Assert.AreEqual(9, sa.Max);

            mi         = typeof(WellKnownRules).GetField("Pattern");
            attributes = new List <Attribute>(rm.GetMemberAttributes(mi));
            PatternAttribute spa = FindAttribute <PatternAttribute>(attributes);

            Assert.AreEqual("{validator.pattern}", spa.Message);
            Assert.AreEqual(@"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", spa.Regex);
            Assert.AreEqual(RegexOptions.CultureInvariant | RegexOptions.IgnoreCase, spa.Flags);
        }