Hi,
As part of learning nhibernate i am trying to set up some basic unit
tests. As part of the set up I blow away and re-copy a small firebird
database to my testing directory. I am having a problem though, in
that somehow I am holding onto a database connection after each test
so although any test will pass on its own my setup fails if I try to
run 2 tests in a row. An abbreviated version of the offending code is
as follows:

        [SetUp]
        public void SetUp()
        {
           // copy a new test file overwrite the old
           UnitTestSetUpTearDown.CopyTestFile("NHIBERNATE.FDB");
        }

        [Test]
        public void TestDoNothing()
        {

--- standard connection string setup etc before this results in a
valid Configuration  object for my test db

            cfg.AddAssembly("NhibernateExample1");

            using (var factory = cfg.BuildSessionFactory())
            {
                using (var ses = factory.OpenSession())
                {
                   using (var trans = ses.BeginTransaction())
                    {
                       trans.Commit();
                    }
                }
            }
        }

        [Test]
        public void TestDoNothingAgain()
        {
            TestDoNothing();
        }

SetUp before TestDoNothingAgain() seems to have trouble deleting the
old database file. Anything short of commenting out:

using (var trans = ses.BeginTransaction())
{
     trans.Commit();
}

doesn't seem to work.. have tried calling every procedure I can find
that might be to do with closing connections on both trans and ses but
no luck.

Any suggestions as to what i need to do to delete this file?

Error is as folllows:

NHibernate.Examples.QuickStart.UnitTestingClasses.TestDoNothingAgain:
System.IO.IOException : The process cannot access the file 'C:
\Documents and Settings\Administrator\Local Settings\Temp
\nunit20\ShadowCopyCache\3944_633820564853125000\Tests\assembly
\dl3\d63c7fa7\7439d31b_07fac901\NHIBERNATE.FDB' because it is being
used by another process.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at UnitTestUtilities.UnitTestSetUpTearDown.CopyTestFile(String
testFileNoDir) in C:\Documents and Settings\Administrator\My Documents
\Visual Studio 2008\Projects\utilityClasses
\UnitTestSetUpTearDownProcs.cs:line 28
at NHibernate.Examples.QuickStart.UnitTestingClasses.SetUp() in C:
\Documents and Settings\Administrator\My Documents\Visual Studio
2008\Projects
\NhibernateExample1\NhibernateExample1\UnitTestingClasses.cs:line 131




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to