예제 #1
0
        public void AcceptedValuesPermitsCasing()
        {
            var attribute = new AcceptedValuesAttribute(false, false, "a", "B", "c");

            Assert.Throws <ValidationException>(() => attribute.Validate("d", new ValidationContext(new Pet())));
            attribute.Validate("A", new ValidationContext(new Pet()));
            attribute.Validate("b", new ValidationContext(new Pet()));
            attribute.Validate("c", new ValidationContext(new Pet()));
        }
예제 #2
0
        public void AcceptedValuesEnforceNullability()
        {
            var attribute = new AcceptedValuesAttribute(true, false, "a", "B", "c");

            Assert.Throws <ValidationException>(() => attribute.Validate(null, new ValidationContext(new Pet())));
            attribute.Validate("a", new ValidationContext(new Pet()));
            attribute.Validate("c", new ValidationContext(new Pet()));
            Assert.Throws <ValidationException>(() => attribute.Validate("d", new ValidationContext(new Pet())));

            attribute = new AcceptedValuesAttribute(true, true, "a", "B", "c");
            Assert.Throws <ValidationException>(() => attribute.Validate("A", new ValidationContext(new Pet())));
            attribute.Validate(null, new ValidationContext(new Pet()));
            attribute.Validate("c", new ValidationContext(new Pet()));
            Assert.Throws <ValidationException>(() => attribute.Validate("d", new ValidationContext(new Pet())));
        }