public void IsValid_TR_False()
        {
            var attr = new AllowedValuesAttribute("DE", "FR", "GB");
            var act  = attr.IsValid(Country.TR);

            Assert.IsFalse(act);
        }
        public void IsValid_Null_True()
        {
            var attr = new AllowedValuesAttribute("DE", "FR", "GB");
            var act  = attr.IsValid(null);

            Assert.IsTrue(act);
        }
        public void IsValid_GB_True()
        {
            var attr = new AllowedValuesAttribute("DE", "FR", "GB");
            var act  = attr.IsValid(Country.GB);

            Assert.IsTrue(act);
        }
Exemple #4
0
        public void IsValid_Fail_Test(object value)
        {
            var attribute = new AllowedValuesAttribute("5", "test2")
            {
                AllowNull = false
            };

            Assert.False(attribute.IsValid(value));
        }
Exemple #5
0
        public void IsValid_Exception_Test(object value)
        {
            var attribute = new AllowedValuesAttribute("5", "test2")
            {
                AllowNull = false
            };

            Assert.Throws <ArgumentException>(() => attribute.IsValid(value));
        }
Exemple #6
0
        public void IsValid_Success_Test(object value)
        {
            var attribute = new AllowedValuesAttribute("test1", "test2")
            {
                AllowNull = true
            };

            Assert.True(attribute.IsValid(value));
        }
Exemple #7
0
        public void FormatMessage_Exception_Test()
        {
            var attribute = new AllowedValuesAttribute("5", "test2")
            {
                AllowNull = false
            };

            Assert.Equal(
                $"The value of field 'test' is not one of allowed values [5, test2].",
                attribute.FormatErrorMessage("test"));
        }
        public void AllowedValuesSetValidateEmptyOrWhitespaceStringNotAllowed(string valueToValidate)
        {
            AllowedValuesAttribute ava = new AllowedValuesAttribute(allowedValues: new string[] { "ptv", "vrk" });

            ava.IsValid(valueToValidate).Should().BeFalse();
        }
        public void AllowedValuesDefined(string valueToValidate)
        {
            AllowedValuesAttribute ava = new AllowedValuesAttribute(allowedValues: new string[] { "", " ", "ptv", "something else" });

            ava.IsValid(string.Empty).Should().BeTrue();
        }
        public void AllowedListEmptyNothingShouldBeValid(string valueToValidate)
        {
            AllowedValuesAttribute ava = new AllowedValuesAttribute(allowedValues: new string[] { });

            ava.IsValid(valueToValidate).Should().BeFalse();
        }
        public void NullValueAlwaysAllowed()
        {
            AllowedValuesAttribute ava = new AllowedValuesAttribute(allowedValues: new string[] { "ptv", "vrk" });

            ava.IsValid(null).Should().BeTrue();
        }
        public void NullAllowedEmptyAllowedList()
        {
            AllowedValuesAttribute ava = new AllowedValuesAttribute(allowedValues: new string[] { });

            ava.IsValid(null).Should().BeTrue();
        }
        public void AllowedValuesSetValidateCaseSensitivity(string valueToValidate)
        {
            AllowedValuesAttribute ava = new AllowedValuesAttribute(allowedValues: new string[] { "ptv", "vrk" });

            ava.IsValid(valueToValidate).Should().BeFalse();
        }