After much more searching and digging through log files, I found the issue. As suspected, it was my fault entirely. A collection on the Team class was mapped incorrectly, causing a constraint to be put on a table that I did not expect. It looks like it was a toss-up whether this constraint was placed there, or another one. I removed that collection and the issue has been resolved.
On Nov 17, 4:41 pm, JakeS <[email protected]> wrote: > I cleaned up my test base class-- getting rid of the SessionScope and > relying only on TransactionScopes within my tests. I was just > grasping at straws-- maybe the testrunner was leaving a scope open or > something. That wasn't the problem. > > It looks like the problem comes in my use of an Any[] mappying > attribute with Cascade = CascadeEnum.SaveUpdate. > > If I have this it causes the issue: > [Any(typeof (int), MetaType = typeof (string), TypeColumn = > "RecipientType", IdColumn = "RecipientID", > Cascade = CascadeEnum.SaveUpdate)] > [Any.MetaValue("USER", typeof (User))] > [Any.MetaValue("TEAM", typeof (Team))] > public IFeedback Recipient { get; set; } > > But if I set Cascade = CascadeEnum.None, it works. > > I still don't understand why it only worked SOME times and not > others. I'm definitely in over my head. > > On Nov 17, 3:59 pm, JakeS <[email protected]> wrote: > > > > > I'm using nunit to test out my activerecord models and make sure my > > mapping works as expected. Strangely, I'm getting an error every once > > in a while when running my tests: > > > System.Data.SqlClient.SqlException: The INSERT statement conflicted > > with the FOREIGN KEY constraint "FK618CE2931513F4CD". The conflict > > occurred in database "TestDatabase", table "dbo.Team", column 'Id'. > > The statement has been terminated. > > > I'll run a test once, get this error. If I run it again, I may or may > > not get the same error. Sometimes it goes through fine, sometimes it > > does not. It's driving me crazy. > > > All of my test classes inherit from this: > > > public class ActiveRecordSetupFixture : BaseControllerTest > > { > > private static bool _alreadySetup = false; > > private static SessionScope _scope; > > > //The test's [TestFixtureSetUp] will call this method > > protected void Setup() > > { > > SetupActiveRecord(); > > } > > > private static void SetupActiveRecord() > > { > > if (!_alreadySetup) > > { > > > log4net.Config.XmlConfigurator.Configure(); > > > ActiveRecordStarter.Initialize(typeof > > (ModelBase<>).Assembly, ActiveRecordSectionHandler.Instance); > > _alreadySetup = true; > > ActiveRecordStarter.DropSchema(); > > ActiveRecordStarter.CreateSchema(); > > } > > > _scope = new SessionScope(FlushAction.Auto); > > } > > > } > > > Any ideas if I'm doing something wrong with my test setup, or if it's > > something in my mapping? If it's a mapping problem, why does it only > > happen sometimes? -- 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=.
