AFAIK, validation is not propagated to related objects when executed
explicitly like in your test.
However, it will be performed during Save()/Update() for each saved/updated
object in the graph.

IMO, this makes sense because the related object might be lazy loaded, so in
order to validate it,
it has to be retrieved from the DB first.


On Tue, Jul 28, 2009 at 9:25 AM, bdaniel7 <[email protected]> wrote:

>
> Hello, i have the following setup:
>
> [ActiveRecord(Lazy = true, DynamicInsert = true, DynamicUpdate = true,
> SelectBeforeUpdate = true)]
> public class Incident : ActiveRecordValidationBase<Incident>
> {
>    Address address;
>
>    [BelongsTo(Cascade = CascadeEnum.SaveUpdate, Update=false)]
>    [ValidateNonEmpty(RunWhen = RunWhen.Insert)]
>    public virtual Address Address
>    {
>        get { return address; }
>        set { address = value; }
>    }
>
>    //... other props
> }
>
> [ActiveRecord( Lazy=true, DynamicInsert=true, DynamicUpdate=true,
> SelectBeforeUpdate=true )]
> public class Address : ActiveRecordValidationBase<Address>
> {
>    // all properties are required: street, street nr, city, postcode
>    [Property]
>    [ValidateNonEmpty]
>    public virtual string Street
>    {
>        get { return street; }
>        set { street = value; }
>    }
> }
>
> [Test]
> public void Validate_Incident()
> {
>        Incident i = new Incident();
>        i.Address = new Address();
>
>        CachedValidationRegistry registry = new CachedValidationRegistry();
>        ValidatorRunner runner = new ValidatorRunner( registry );
>
>        bool valid = runner.IsValid( i );
>        Assert.That(valid, Is.False);
> }
>
> The test fails, meaning that the incident is considered valid, even
> though the address (or other props) are not filled in.
> The validation is not performed in the controller either, in a code
> like this:
>
> public void Save( [DataBind( "incident", Validate=true )] Incident
> incident )
> {
>    ...
> }
>
> Am i doing something wrong? Is there a bug? This issue is driving me
> crazy...
>
> Dan
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to