Hello again,
i used the latest code from the trunk, the validation is work
perfectly. but now I faced another problem: Property of a class
registered with NotifyPropertyChangedBehavior when called from inside
of its class will never raise INotifyPropertyChanged.PropertyChanged
event.
to help quickly understand what i mean i wrote a unit testing below.
(sorry i wrote it using vs team system).
actually i though it was the behavior of CastleDynamicProxy, not a bug
in componentbehavior instead,, but i'm not really sure, let the
masters decide it.
regards
ktutnik.
================ Unit test
/*usings cutted*/
using SysCom = System.ComponentModel;
namespace ExperimentalTest.ComponentBehavior
{
public class CustomerWithNoInterface
{
public virtual string Email { get; set; }
public void ChangeEmail()
{
Email = "NEW_MAIL";
}
}
public class Customer : ICustomer
{
public virtual string Email { get; set; }
public void ChangeEmail()
{
Email = "NEW_MAIL";
}
}
public interface ICustomer
{
string Email { get; set; }
void ChangeEmail();
}
public class CustomerValidationDef : ValidationDef<ICustomer>
{
public CustomerValidationDef()
{
Define(x =>
x.Email).IsEmail().WithMessage("INCORRECT_EMAIL_MESSAGE");
}
}
public class CustomerNoInterfaceValidationDef :
ValidationDef<CustomerWithNoInterface>
{
public CustomerNoInterfaceValidationDef()
{
Define(x =>
x.Email).IsEmail().WithMessage("INCORRECT_EMAIL_MESSAGE");
}
}
[TestClass]
public class InheritanceTest
{
WindsorContainer container = null;
[TestInitialize]
public void Initialize()
{
container = new WindsorContainer();
container.AddFacility<FactorySupportFacility>();
container.AddFacility<ComponentBehaviorsFacility>();
container.AddFacility<PersistenceConversationFacility>();
var configuration = new FluentConfiguration();
configuration.Register(new Type[]
{ typeof(CustomerValidationDef),
typeof(CustomerNoInterfaceValidationDef) })
.SetDefaultValidatorMode(ValidatorMode.UseExternal)
.AddEntityTypeInspector<NHVTypeInspector>();
var engine = new ValidatorEngine();
engine.Configure(configuration);
var entityValidator = new EntityValidator(engine);
container.Register(Component.For<IEntityValidator>().Instance(entityValidator));
var behaviorStore = new BehaviorDictionary();
behaviorStore.For<Customer>()
.Add<NotifyPropertyChangedBehavior>()
.Add<DataErrorInfoBehavior>();
behaviorStore.For<CustomerWithNoInterface>()
.Add<NotifyPropertyChangedBehavior>()
.Add<DataErrorInfoBehavior>();
container.Register(Component.For<IBehaviorStore>().Instance(behaviorStore));
container.Register(Component.For<ICustomer>().ImplementedBy<Customer>().LifeStyle.Transient);
container.Register(Component.For<CustomerWithNoInterface>().LifeStyle.Transient);
}
[TestMethod]//FAILED
public void
ICustomer_PropertyChanged_WhenAssignPropertyFromInside_ShouldDispatched()
{
var isChanged = false;
var customer = container.Resolve<ICustomer>();
((SysCom.INotifyPropertyChanged)customer).PropertyChanged
+= (s, e) => { isChanged = true; };
customer.ChangeEmail();
Assert.IsTrue(isChanged);
}
[TestMethod]//PASS
public void
CustomerWithNoProxy_PropertyChanged_WhenAssignPropertyFromInside_ShouldDispatched()
{
var isChanged = false;
var customer =
container.Resolve<CustomerWithNoInterface>();
((SysCom.INotifyPropertyChanged)customer).PropertyChanged
+= (s, e) => { isChanged = true; };
customer.ChangeEmail();
Assert.IsTrue(isChanged);
}
}
}