I've been trying to get a successful test for Parent Child
relationship cascade delete but was failing again and again...
Here is the failing test:
[TestMethod]
public void TestParentDeleteCascade()
{
//Setup a parent
Parent parent = new Parent();
parent.Name = "Luke, I am your father.";
parent.Save();
Child child = new Child();
child.Name = "Noooo";
child.Parent = parent;
child.SaveAndFlush();
//Not null exception thrown here
parent.Delete();
Assert.IsFalse(Child.Exists(child.Id));
}
Here is the working test:
[TestMethod]
public void TestParentDeleteCascade()
{
//Setup a client
Parent parent = new Parent();
parent.Name = "I am your father.";
parent.Save();
Child child = new Child();
child.Name = "Noooo";
child.Parent = parent;
child.SaveAndFlush();
Parent newParent = Parent.Find(parent.Id);
newParent.Delete();
Assert.IsFalse(Child.Exists(child.Id));
}
Moral of the story: Be careful that the current object your using is
the most up to date version of that object....
Sometimes it's just not your night.....
--
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.