public void IsValidCompareDifferentTypes()
        {
            EqualToValidator equalToValidator = new EqualToValidator(10);

            Assert.IsFalse(equalToValidator.IsValid(10M));
            Assert.IsFalse(equalToValidator.IsValid("10"));
        }
        public void IsValidCompareStringWithOrdinalIgnoreCaseComparer()
        {
            EqualToValidator equalToValidator = new EqualToValidator("TEST", StringComparer.OrdinalIgnoreCase);

            Assert.IsTrue(equalToValidator.IsValid("test"));
            Assert.IsTrue(equalToValidator.IsValid("TEST"));
        }
        public void IsValidCompareIntegerValue()
        {
            EqualToValidator equalToValidator = new EqualToValidator(10);

            Assert.IsTrue(equalToValidator.IsValid(10));
            Assert.IsFalse(equalToValidator.IsValid(1));
        }
        public void IsValidCompareString()
        {
            EqualToValidator equalToValidator = new EqualToValidator("TEST");

            Assert.IsFalse(equalToValidator.IsValid("test"));
            Assert.IsFalse(equalToValidator.IsValid("Test"));
            Assert.IsTrue(equalToValidator.IsValid("TEST"));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NotEqualToValidator"/> class.
        /// </summary>
        /// <param name="valueToCompare">The value to compare.</param>
        /// <param name="comparer">The comparer.</param>
        /// <exception cref="System.ArgumentNullException">valueToCompare</exception>
        public NotEqualToValidator(object valueToCompare, IEqualityComparer comparer = null)
        {
            if (valueToCompare == null)
            {
                throw new ArgumentNullException("valueToCompare");
            }

            m_EqualToValidator = new EqualToValidator(valueToCompare, comparer);
            m_ValidatorProperties = new ValidatorProperties { { Constants.ValidationMessageParameterNames.VALUE_TO_COMPARE, ValueToCompare } };
        }
Exemplo n.º 6
0
        public void GetValidator()
        {
            const string               valueToCompare             = "TEST";
            IEqualityComparer          comparer                   = StringComparer.OrdinalIgnoreCase;
            EqualToValidationAttribute equalToValidationAttribute = new EqualToValidationAttribute(valueToCompare, comparer);

            Assert.IsInstanceOf(typeof(EqualToValidator), equalToValidationAttribute.GetValidator());

            EqualToValidator equalToValidator = (EqualToValidator)equalToValidationAttribute.GetValidator();

            Assert.AreEqual(valueToCompare, equalToValidator.ValueToCompare);
            Assert.AreEqual(comparer, equalToValidator.Comparer);
        }
        public void IsValidCompareNullValue()
        {
            EqualToValidator equalToValidator = new EqualToValidator(string.Empty);

            Assert.IsFalse(equalToValidator.IsValid(null));
        }
        public void IsValidCompareEmptyString()
        {
            EqualToValidator equalToValidator = new EqualToValidator(string.Empty);

            Assert.IsTrue(equalToValidator.IsValid(string.Empty));
        }