Ok, this is what I have in CommonEntityBase:
protected override void OnRelatedEntitySet(IEntity2 relatedEntity, string fieldName)
{
OnPropertyChanged(fieldName);
}
protected override void OnRelatedEntityUnset(IEntity2 relatedEntity, string fieldName)
{
OnPropertyChanged(fieldName);
}
And this is my unit test:
[Test]
public void Go()
{
UserEntity user = new UserEntity();
int eventCalledCount = 0;
UserCertificateEntity eventCalledCertificate = null;
user.PropertyChanged += new PropertyChangedEventHandler(
delegate(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Certificate")
{
eventCalledCount++;
// Save the certificate to ensure that at the time of the event the
// property has been updated:
eventCalledCertificate = user.Certificate;
}
});
// Try setting the certificate:
user.Certificate = new UserCertificateEntity();
Assert.AreEqual(1, eventCalledCount);
Assert.IsTrue(object.ReferenceEquals(user.Certificate, eventCalledCertificate));
// Try setting a different certificate:
user.Certificate = new UserCertificateEntity();
Assert.AreEqual(2, eventCalledCount);
Assert.IsTrue(object.ReferenceEquals(user.Certificate, eventCalledCertificate));
// Try clearing the certificate:
user.Certificate = null;
Assert.AreEqual(3, eventCalledCount);
Assert.IsNull(eventCalledCertificate);
}
This test fails on the first Assert.AreEqual line, because OnRelatedEntitySet is called in the user certificate entity, not the user.
So, could you please give me an example of how to implement this functionality? I can't call the user's OnPropertyChanged method from UserCertificate code.
Even if I could, what field name would I use?