public void BuildSpecialCustomer_RemoveLastNameHardConstraint_ThrowsException()
 {
     Assert.That(() => ValidationBuilder.BuildValidator <SpecialCustomer2> (),
                 Throws.TypeOf <ValidationConfigurationException> ().And.Message.EqualTo(
                     "Hard constraint validator(s) 'LengthValidator' on property "
                     + "'Remotion.Validation.IntegrationTests.TestDomain.ComponentA.Person.LastName' cannot be removed."));
 }
 public void BuildValidator_MaxLengthMetaValidationRule()
 {
     Assert.That(
         () => ValidationBuilder.BuildValidator <MetaValidationTestClass1>(),
         Throws.TypeOf <ValidationConfigurationException>()
         .And.Message.EqualTo("MaxLength-Constraints greater 50 not allowed for validator 'LengthValidator'!"));
 }
 public void BuildOrderValidator_StringPropertyReStoreAttributeIsReplaced_MaxLengthMetaValidationRuleFails()
 {
     Assert.That(
         () => ValidationBuilder.BuildValidator <InvalidOrder> (),
         Throws.TypeOf <ValidationConfigurationException> ().And.Message.EqualTo(
             "'RemotionMaxLengthMetaValidationRule' failed for property 'Remotion.Data.DomainObjects.Validation.IntegrationTests.Testdomain.InvalidOrder.Number': "
             + "Max-length validation rule value '15' exceeds meta validation rule max-length value of '10'."));
 }
 public void BuildValidator_FuncMetaValidationRule()
 {
     Assert.That(() => ValidationBuilder.BuildValidator <MetaValidationTestClass4>(), Throws.TypeOf <ValidationConfigurationException>().And.Message.EqualTo(
                     "'LengthSystemMetaValidationRule' failed for member 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.MetaValidationTestClass4.Property1'.\r\n"
                     + "----------\r\n"
                     + "Invalid length validator count!"
                     ));
 }
 public void BuildValidator_DerivedClassWithoutCollector_RulesFromOtherHierarchyLevelsAreIgnored()
 {
     Assert.That(
         () => ValidationBuilder.BuildValidator <DerivedMetaValidationTestClass2>(),
         Throws.TypeOf <ValidationConfigurationException>().And.Message.EqualTo(
             "Meta validation rule 'rules => rules.Any()' failed for validator 'FluentValidation.Validators.IPropertyValidator' on property 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.BaseMetaValidationTestClass1.Property3'.\r\n"
             + "----------\r\n"
             + "Meta validation rule 'rules => rules.Any()' failed for validator 'FluentValidation.Validators.IPropertyValidator' on property 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.BaseMetaValidationTestClass1.Property4'."));
 }
 public void BuildValidator_ExpressionMetaValidationRule()
 {
     Assert.That(() => ValidationBuilder.BuildValidator <MetaValidationTestClass5>(), Throws.TypeOf <ValidationConfigurationException>().And.Message.EqualTo(
                     "'LengthSystemMetaValidationRule' failed for member 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.MetaValidationTestClass5.Property1'.\r\n"
                     + "----------\r\n"
                     + "Meta validation rule 'lengthRules => (lengthRules.Count() <= 2)' failed for validator 'FluentValidation.Validators.LengthValidator' "
                     + "on property 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.MetaValidationTestClass5.Property1'."
                     ));
 }
 public void BuildValidator_BaseClass_RulesFromOverridedDerivedPropertiesAreIgnored()
 {
     Assert.That(
         () => ValidationBuilder.BuildValidator <BaseMetaValidationTestClass1>(),
         Throws.TypeOf <ValidationConfigurationException>().And.Message.EqualTo(
             "Meta validation rule 'rules => rules.Any()' failed for validator 'FluentValidation.Validators.IPropertyValidator' on property 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.BaseMetaValidationTestClass1.Property3'.\r\n"
             + "----------\r\n"
             + "Meta validation rule 'rules => rules.Any()' failed for validator 'FluentValidation.Validators.IPropertyValidator' on property 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.BaseMetaValidationTestClass1.Property4'."));
 }
 public void BuildValidator_DerivedClassWithCollector_RulesFromOverridedBaseAndDerivedPropertiesAreApplied()
 {
     Assert.That(
         () => ValidationBuilder.BuildValidator <DerivedMetaValidationTestClass1>(),
         Throws.TypeOf <ValidationConfigurationException>().And.Message.EqualTo(
             "'LengthSystemMetaValidationRule' failed for member 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.BaseMetaValidationTestClass1.Property1'.\r\n"
             + "----------\r\n"
             + "Meta validation rule 'rules => rules.Any()' failed for validator 'FluentValidation.Validators.IPropertyValidator' on property 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.BaseMetaValidationTestClass1.Property4'.\r\n"
             + "----------\r\n"
             + "Meta validation rule 'rules => rules.Any()' failed for validator 'FluentValidation.Validators.IPropertyValidator' on property 'Remotion.Validation.IntegrationTests.TestDomain.MetaValidation.BaseMetaValidationTestClass1.Property5'."));
 }
        public void BuildAdressValidator_WhenAndUnlessConditionApplied()
        {
            var address1 = new Address {
                Country = "Deutschland", PostalCode = "DE - 432134"
            };
            var address2 = new Address {
                Country = "Deutschland", PostalCode = "AT - 1220"
            };
            var address3 = new Address {
                Street = "Maria Hilferstrasse 145", City = "Wien", PostalCode = "1090"
            };
            var address4 = new Address {
                Street = "Maria Hilferstrasse 145", City = "Salzburg", PostalCode = "1090"
            };
            var address5 = new Address {
                Country = "Brunei"
            };
            var address6 = new Address {
                Country = "Tschiputi"
            };

            var validator = ValidationBuilder.BuildValidator <Address>();

            var result1 = validator.Validate(address1);

            Assert.That(result1.IsValid, Is.True);

            var result2 = validator.Validate(address2);

            Assert.That(result2.IsValid, Is.False);
            Assert.That(result2.Errors.Count, Is.EqualTo(1));
            Assert.That(result2.Errors[0].ErrorMessage, Is.EqualTo("'PostalCode' is not in the correct format."));

            var result3 = validator.Validate(address3);

            Assert.That(result3.IsValid, Is.True);

            var result4 = validator.Validate(address4);

            Assert.That(result4.IsValid, Is.False);
            Assert.That(result4.Errors.Count, Is.EqualTo(1));
            Assert.That(result4.Errors[0].ErrorMessage, Is.EqualTo("'City' is not in the correct format."));

            var result5 = validator.Validate(address5);

            Assert.That(result5.IsValid, Is.True);

            var result6 = validator.Validate(address6);

            Assert.That(result6.IsValid, Is.False);
            Assert.That(result6.Errors.Count, Is.EqualTo(1));
            Assert.That(result6.Errors[0].ErrorMessage, Is.EqualTo("'PostalCode' must not be empty."));
        }
        public void BuildSpecialCustomerValidator_InvalidCustomerLastName_LengthValidatorFailed()
        //HardConstraintLengthValidator defined in CustomerValidationCollector1 not removed by SpecialCustomerValidationCollector1!
        {
            var specialCustomer = ObjectFactory.Create <SpecialCustomer1> (ParamList.Empty);

            specialCustomer.UserName = "******";
            specialCustomer.LastName = "LastNameTooLong";
            var validator = ValidationBuilder.BuildValidator <SpecialCustomer1> ();

            var result = validator.Validate(specialCustomer);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors[0].ErrorMessage, Is.EqualTo("'LocalizedLastName' must be between 2 and 8 characters. You entered 15 characters."));
        }
        public void BuildEmployeeValidator_ConditionalMessage()
        {
            var employee = new Employee {
                FirstName = "FirstName", LastName = "LastName"
            };

            var validator = ValidationBuilder.BuildValidator <Employee>();

            var result = validator.Validate(employee);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors.Count, Is.EqualTo(1));
            Assert.That(result.Errors[0].ErrorMessage, Is.EqualTo("Conditional Message Test: Kein Gehalt definiert"));
        }
        public void BuildOrderItemValidator_SetValueTypeToDefaulValue_ValidationFails()
        {
            var orderItem = new OrderItem();

            orderItem.Quantity = 0;

            var validator = ValidationBuilder.BuildValidator <OrderItem>();

            var result = validator.Validate(orderItem);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors.Count, Is.EqualTo(1));
            Assert.That(result.Errors[0].ErrorMessage, Is.EqualTo("'Quantity' should not be empty."));
        }
        public void BuildCustomerValidator_PersonLastNameEqualsValidatorRemovedByCollector()
        {
            var customer = ObjectFactory.Create <Customer> (ParamList.Empty);

            customer.UserName  = "******";
            customer.LastName  = "Test";
            customer.FirstName = "Firstname";

            var validator = ValidationBuilder.BuildValidator <Customer>();

            var result = validator.Validate(customer);

            Assert.That(result.IsValid, Is.True);
            Assert.That(result.Errors.Any(), Is.False);
        }
        public void BuildCustomerValidator_CustomerMixinIntroducedValidator_MixinInterfaceIntroducedValidatorIsRemovedByApplyWithMixinCollector()
        {
            var customer = ObjectFactory.Create <Customer> (ParamList.Empty);

            customer.FirstName = "Ralf";
            customer.LastName  = "Mayr";
            customer.UserName  = "******";
            ((ICustomerIntroduced)customer).Title = "Chef3";

            var validator = ValidationBuilder.BuildValidator <Customer>();

            var result = validator.Validate(customer);

            Assert.That(result.IsValid, Is.True);
        }
        public void BuildSpecialCustomerValidator_CustomerUsernameMaxLengthAndAllFirstNameNotNullValidatorsRemoved()
        //2 NotNull Validators removed (IPerson + CustomerValidationCollector!)
        {
            var specialCustomer = ObjectFactory.Create <SpecialCustomer1> (ParamList.Empty);

            specialCustomer.UserName  = "******";
            specialCustomer.LastName  = "Test1234";
            specialCustomer.FirstName = "Test456";
            var validator = ValidationBuilder.BuildValidator <SpecialCustomer1>();

            var result = validator.Validate(specialCustomer);

            Assert.That(result.IsValid, Is.True);
            Assert.That(result.Errors.Any(), Is.False);
        }
        public void BuildCustomerValidator_CustomerMixinTargetValidator()
        {
            var customer = ObjectFactory.Create <Customer> (ParamList.Empty);

            customer.FirstName = "something";
            customer.LastName  = "Mayr";
            customer.UserName  = "******";

            var validator = ValidationBuilder.BuildValidator <Customer> ();

            var result = validator.Validate(customer);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors.Count, Is.EqualTo(1));
            Assert.That(result.Errors[0].ErrorMessage, Is.EqualTo("'LocalizedFirstName' should not be equal to 'something'."));
        }
        public void CustomValidatorErrorMessages()
        {
            var person = new Person();

            person.LastName = "Test";

            var validator = ValidationBuilder.BuildValidator <Person>();

            var result = validator.Validate(person);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors.Count(), Is.EqualTo(2));
            Assert.That(
                result.Errors.Select(e => e.ErrorMessage),
                Is.EquivalentTo(new[] { "NotNullValidator Fake Message", "NotEqualValidator Fake Message" }));
        }
        public void BuildOrderValidator_ValidationFailuresAreLocalizedThroughDomainObjectResource()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var order = Order.NewObject();
                order.Number = "er";

                var validator = ValidationBuilder.BuildValidator <Order> ();

                var result1 = validator.Validate(order);
                Assert.That(result1.IsValid, Is.False);
                Assert.That(
                    result1.Errors.Select(e => e.ErrorMessage),
                    Is.EquivalentTo(new[] { "'LocalizedNumber' must be between 3 and 8 characters. You entered 2 characters." }));
            }
        }
示例#19
0
        public void CustomValidatorErrorMessages()
        {
            var person = new SpecialCustomer1();

            person.FirstName = null;
            person.LastName  = "Test";

            var validator = ValidationBuilder.BuildValidator <Person>();

            var result = validator.Validate(person);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors.Count(), Is.EqualTo(2));
            Assert.That(
                result.Errors.Select(e => e.ErrorMessage),
                Is.EquivalentTo(new[] { "'LocalizedFirstName' must not be empty.", "'LastName' should not be equal to 'Test'." }));
        }
        public void BuildCustomerValidator_CustomerMixinIntroducedValidator_AttributeBaseRuleNotRemoveByRuleWithRemoveFrom()
        {
            var customer = ObjectFactory.Create <Customer> (ParamList.Empty);

            customer.FirstName = "Ralf";
            customer.LastName  = "Mayr";
            customer.UserName  = "******";
            ((ICustomerIntroduced)customer).Title = "Chef1";

            var validator = ValidationBuilder.BuildValidator <Customer>();

            var result = validator.Validate(customer);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors.Count, Is.EqualTo(1));
            Assert.That(result.Errors[0].ErrorMessage, Is.EqualTo("'LocalizedTitle' should not be equal to 'Chef1'."));
        }
        public void BuildCustomerValidator_InvalidCustomerUserName_EqualsValidatorFailed()
        {
            var customer = ObjectFactory.Create <Customer> (ParamList.Empty);

            customer.UserName = "******";
            customer.LastName = "Muster";

            var validator = ValidationBuilder.BuildValidator <Customer> ();

            var result = validator.Validate(customer);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Errors.Count(), Is.EqualTo(2));
            Assert.That(
                result.Errors.Select(e => e.ErrorMessage),
                Is.EquivalentTo(new[] { "'UserName' should not be equal to 'Test'.", "'LocalizedFirstName' must not be empty." }));
        }
        public void BuildCustomerValidator_ValidationFailuresAreLocalizedThroughMixinResource()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var customer = Customer.NewObject();
                customer.Email = "InvalidMail";
                ((ICustomerIntroduced)customer).Address = Address.NewObject();
                ((ICustomerIntroduced)customer).Title   = "Chef1";

                var validator = ValidationBuilder.BuildValidator <Customer>();

                var result1 = validator.Validate(customer);
                Assert.That(result1.IsValid, Is.False);
                Assert.That(
                    result1.Errors.Select(e => e.ErrorMessage),
                    Is.EquivalentTo(new[] { "'LocalizedTitle' should not be equal to 'Chef1'.", "'LocalizedMail' is not a valid email address." }));
            }
        }
        public void BuildProductValidator_MandaroyReStoreAttributeIsAppliedOnDomainObject()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var product1 = Product.NewObject();
                var product2 = Product.NewObject();
                product2.Order = Order.NewObject();;

                var validator = ValidationBuilder.BuildValidator <Product> ();

                var result1 = validator.Validate(product1);
                Assert.That(result1.IsValid, Is.False);
                Assert.That(result1.Errors.Count, Is.EqualTo(1));
                Assert.That(result1.Errors[0].ErrorMessage, Is.EqualTo("'Order' must not be empty."));

                var result2 = validator.Validate(product2);
                Assert.That(result2.IsValid, Is.True);
            }
        }
        public void BuildCustomerValidator_MandaroyReStoreAttributeAppliedOnDomainObjectMixin()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var customer1 = Customer.NewObject();
                var customer2 = Customer.NewObject();
                ((ICustomerIntroduced)customer2).Address = Address.NewObject();

                var validator = ValidationBuilder.BuildValidator <Customer>();

                var result1 = validator.Validate(customer1);
                Assert.That(result1.IsValid, Is.False);
                Assert.That(result1.Errors.Count, Is.EqualTo(1));
                Assert.That(result1.Errors[0].ErrorMessage, Is.EqualTo("'Address' must not be empty."));

                var result2 = validator.Validate(customer2);
                Assert.That(result2.IsValid, Is.True);
            }
        }
示例#25
0
        public void CultureIsSetBeforeValidatorIsCreated_UsesNewCultureForLocalization()
        {
            var person = new SpecialCustomer1();

            person.FirstName = null;
            person.LastName  = "value";

            using (new CultureScope("de-AT"))
            {
                var validator = ValidationBuilder.BuildValidator <Person>();

                var result = validator.Validate(person);

                Assert.That(result.IsValid, Is.False);
                Assert.That(
                    result.Errors.Select(e => e.ErrorMessage),
                    Is.EquivalentTo(new[] { "'Lokalisierter Vorname' darf keinen Null-Wert aufweisen." }));
            }
        }
 public void BuildValidator_MaxLengthMetaValidationRule_IgnoredForConditionalRules()
 {
     ValidationBuilder.BuildValidator <MetaValidationTestClass3>();
 }
 public void BuildValidator_MaxValidatorCountRule()
 {
     Assert.That(
         () => ValidationBuilder.BuildValidator <MetaValidationTestClass2>(),
         Throws.TypeOf <ValidationConfigurationException>().And.Message.EqualTo("More than three validators per property are not allowed!"));
 }