Wrapping the tests in transactions is fine. I should not have had the first using statement for the session though, since of course I was in fact closing the session (duh)!
Sorry for the noise... Berryl On Mar 19, 12:25 pm, Berryl Hesh <[email protected]> wrote: > Hello > > I am trying to work through some repository ideas I found on Fabio's > blog (http://fabiomaulo.blogspot.com/2009/09/repository-or-dao- > repository.html) and running into some session state issues in a > SQLite test fixture. > > If I try to wrap each test in a transaction and roll it back I get an > error on the second test saying the session is closed. > > If I do not wrap the tests in transactions but rather try to delete > each saved item in a tear down method I get an error saying a column > unique constraint is being violated (I do want the column to be unique > but why should it be a violation after the item has been deleted??) > > I am reluctant to just blow away the SQLite db and recreate it on each > and every test, but maybe that is the right answer. > > Some sample code below; tests run in isolation. > > What is the best way to do the testing for this scenario without > errors? > > Cheers, > Berryl > > === code with tx wrappers: fails on 2nd test as Session is Closed === > > [Test] > public void > Add_IfTheProjectIsTransient_ItIsSavedAndAvailable() > { > using (var session = _SessionFactory.GetCurrentSession()) > using(var tx = session.BeginTransaction()) { > > .... add it & assert it's available and persistent > > tx.Rollback(); > } > } > > [Test] > public void Add_IfTheProjectIsPersistent_ItIsNoProblem() { > using (var session = _SessionFactory.GetCurrentSession()) > using (var tx = session.BeginTransaction()) { > > ... add it twice & assert no error > tx.Rollback(); > } > } > > === attempted tear down gets unique column violation ===== > > [TearDown] > public void TearDown() > { > foreach (var p in _repos.GetOpenProjects()) > { > _repos.Remove(p); > _SessionFactory.GetCurrentSession().Evict(p); > } > _SessionFactory.GetCurrentSession().Clear(); > } > > == add method in repository ==== > > public void Add(T item) { > _sessionFactory.GetCurrentSession().SaveOrUpdate(item); > } -- You received this message because you are subscribed to the Google Groups "nhusers" 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/nhusers?hl=en.
