Пример #1
0
        public void When_Required_And_CollectionValue_Is_Null()
        {
            var customer = new Customer();

            var validator = new Required<Customer, IEnumerable>();
            var context = new RuleValidatorContext<Customer, IEnumerable>(customer, "Contacts", customer.Contacts, null, null);

            //Validate the validator only, return true of no error returned
            var result = validator.Validate(context, null);

            Assert.IsNotEmpty(result.Message);
        }
Пример #2
0
        public void When_Required_And_StringValue_Is_Null()
        {
            var customer = new Customer();

            var validator = new Required<Customer, string>();
            var context = new RuleValidatorContext<Customer, string>(customer, "Name", customer.Name, null, null);

            //Validate the validator only, return true of no error returned
            var result = validator.Validate(context, null);

            Assert.IsNotEmpty(result.Message);
        }
Пример #3
0
        public void When_Required_And_StringValue_Is_Null()
        {
            var customer = new Customer();

            var validator = new Required<Customer, string>();
            var context = new RuleValidatorContext<Customer, string>(customer, "Name", customer.Name, null, ValidationLevelType.Error, null);

            var notification = new ValidationNotification();

            //Validate the validator only, return true of no error returned
            validator.Validate(context, null, notification);

            Assert.IsNotEmpty(notification.Errors[0].Message);
        }
Пример #4
0
        public void When_Required_And_CollectionValue_Is_Empty_IsInvalid()
        {
            var customer = new Customer() {Contacts = new List<Contact>()};

            var validator = new Required<Customer, IEnumerable>();
            var context = new RuleValidatorContext<Customer, IEnumerable>(customer, "Contacts", customer.Contacts, null, ValidationLevelType.Error, null);

            var notification = new ValidationNotification();

            //Validate the validator only, return true of no error returned
            validator.Validate(context, null, notification);

            Assert.IsNotEmpty(notification.Errors[0].Message);
        }
Пример #5
0
        public void When_Required_And_CollectionValue_Is_Null()
        {
            var customer = new Customer();

            var validator = new Required <Customer, IEnumerable>();
            var context   = new RuleValidatorContext <Customer, IEnumerable>(customer, "Contacts", customer.Contacts, null, ValidationLevelType.Error, null);

            var notification = new ValidationNotification();

            //Validate the validator only, return true of no error returned
            validator.Validate(context, null, notification);

            Assert.IsNotEmpty(notification.Errors[0].Message);
        }