public void ConfigureValidator(IConfiguresValidator <Person> config)
        {
            config.UseObjectIdentity(p => p.Name);

            config.AddRule <NotNull>();

            config.ForMember(x => x.Name, m =>
            {
                m.AddRule <NotNullOrEmpty>();
            });

            config.ForMember(x => x.Birthday, m =>
            {
                m.AddRule <DateTimeInRange>(r =>
                {
                    r.Name = "NotBornBefore1900";
                    r.ConfigureRule(c => c.Start = new DateTime(1900, 1, 1));
                });
            });

            config.ForMember(x => x.Pets, m => m.AddRule <NotNull>());

            config.ForMemberItems(x => x.Pets, m => m.AddRules <PetValidatorBuilder>());

            config.WhenValueIs <Employee>(c =>
            {
                c.AddRules <EmployeePolymorphicBuilder>();
            });
        }
        public void ConfigureValidator(IConfiguresValidator <ValidatorBuilderApiVerification.InnerValidatedObject> config)
        {
            config.UseObjectIdentity(x => x.Identity);

            config.ForMember(x => x.NumericProperty, m =>
            {
                m.AddRuleWithParent <IntegerValueRule>();
            });
        }
 public void ConfigureValidator(IConfiguresValidator <FrequentShopper> config)
 {
     config.ForMember(x => x.LoyaltyPoints, m =>
     {
         m.AddRule <IntegerInRange>(c =>
         {
             c.ConfigureRule(r => r.Min = 0);
         });
     });
 }
            public void ConfigureValidator(IConfiguresValidator <ComplexObject> config)
            {
                config.UseObjectIdentity(x => x.Identity);

                config.AddRule <ObjectRule>();

                config.ForMember(x => x.StringProperty, m => m.AddRuleWithParent <StringValueRule>());

                config.ForValue(x => x.IntegerMethod(), m => m.AddRule <IntegerRule>(r => {
                    r.AddDependency(d => d.RuleType <StringValueRule>().FromAncestorLevel(1).ForMember(nameof(ComplexObject.StringProperty)));
                }));
            }
Beispiel #5
0
 public void ConfigureValidator(IConfiguresValidator <Employee> config)
 {
     config.ForMember(x => x.PayrollNumber, m =>
     {
         m.AddRule <IntegerInRange>(c =>
         {
             c.ConfigureRule(r =>
             {
                 r.Min = 1;
                 r.Max = 9999;
             });
         });
     });
 }
Beispiel #6
0
            public void ConfigureValidator(IConfiguresValidator <ComplexObject> config)
            {
                config.UseObjectIdentity(x => x.Identity);

                config.AddRule <ObjectRule>();

                config.ForMember(x => x.Associated, m => m.AddRules <ComplexChildValidator>());

                config.ForMemberItems(x => x.Children, m => m.AddRules <ComplexChildValidator>());

                config.ForMember(x => x.StringProperty, m =>
                {
                    m.AddRuleWithParent <StringValueRule>();
                    m.AddRule <ObjectRule>();
                });
            }
 public void ConfigureValidator(IConfiguresValidator <StubValidatedObject> config)
 {
     config
     .UseObjectIdentity(x => x.Identity)
     .AddRule <SampleSpecificRule>(r => {
         r.Name = "My rule";
         r.Dependencies.Add(new RelativeRuleIdentifier(typeof(SampleObjectRule), ruleName: "A rule name"));
     })
     .AddRule <SampleObjectRule>(r => r.ConfigureRule(c => c.RuleProperty = "A value"))
     .ForMember(x => x.StringProperty, m =>
     {
         m.AddRuleWithParent <StringValueRule>();
     })
     .ForMemberItems(x => x.ObjectCollection, m =>
     {
         m.AddRules <ContainedObjectValidator>();
     });
 }
        public void ConfigureValidator(IConfiguresValidator <Customer> config)
        {
            config.ForMember(x => x.Person, v =>
            {
                v.AddRules <PersonValidatorBuilder>();

                v.AddRule <MayNotHaveMoreThan5Pets>(r => {
                    r.AddDependency(d => d.RuleType <NotNull>().ForMember(nameof(Person.Pets)));
                });
            });

            config.AddRule <NotNull>();

            config.WhenValueIs <FrequentShopper>(c =>
            {
                c.AddRules <FrequentShopperPolymorphicBuilder>();
            });
        }
        public void ConfigureValidator(IConfiguresValidator <Person> config)
        {
            // With 4 levels of parallelisation (set via a threadpool), this validator
            // should take very close to 650ms to completely execute.
            // Rules 1-4 should occur in parallel taking approx 300ms between all of them.
            // Rules 5 & 6 take 200ms & 150ms respectively or approx 350ms total

            config.AddRule <ParallelisableRule>(c =>
            {
                c.ConfigureRule(r => r.MillisecondsDelay = 300);
                c.Name = "Rule 1";
            });
            config.AddRule <ParallelisableRule>(c =>
            {
                c.ConfigureRule(r => r.MillisecondsDelay = 200);
                c.Name = "Rule 2";
            });
            config.AddRule <ParallelisableRule>(c =>
            {
                c.ConfigureRule(r => r.MillisecondsDelay = 300);
                c.Name = "Rule 3";
            });
            config.AddRule <ParallelisableRule>(c =>
            {
                c.ConfigureRule(r => r.MillisecondsDelay = 200);
                c.Name = "Rule 4";
            });
            config.AddRule <NonParallelisableRule>(c =>
            {
                c.ConfigureRule(r => r.MillisecondsDelay = 200);
                c.Name = "Rule 5";
            });
            config.AddRule <NonParallelisableRule>(c =>
            {
                c.ConfigureRule(r => r.MillisecondsDelay = 150);
                c.Name = "Rule 6";
            });
        }
Beispiel #10
0
        public void ConfigureValidator(IConfiguresValidator <Pet> config)
        {
            config.UseObjectIdentity(x => x.Identity);
            config.AddRule <NotNull>();
            config.AddRule <CantBeOwnedByUnderageChildren>();

            config.ForMember(x => x.Name, m =>
            {
                m.AddRule <NotNullOrEmpty>();
            });

            config.ForMember(x => x.NumberOfLegs, m =>
            {
                m.AddRule <IntegerInRange>(r =>
                {
                    r.ConfigureRule(c =>
                    {
                        // Can't have negative legs and millipedes have max 750 legs
                        c.Min = 0;
                        c.Max = 750;
                    });
                });
            });
        }
 public void ConfigureValidator(IConfiguresValidator <string> config)
 => throw new System.NotImplementedException();
Beispiel #12
0
 public void ConfigureValidator(IConfiguresValidator <int> config) => throw new NotImplementedException();
Beispiel #13
0
 public void ConfigureValidator(IConfiguresValidator <ValidatedObject> config) => config.UseObjectIdentity(o => o.Identity);
Beispiel #14
0
 public void ConfigureValidator(IConfiguresValidator <T> config) => LastConfig = config;