Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

NHibernateProjectRepository creates and manages NHibernate SessionFactory objects. A SessionFactory object has a Dispose method that must be called to clean up resources. Otherwise, the SessionFactory objects will remain in memory and will not be garbage collected.

NHibernateProjectRepository, IProjectRepository and (I)ProjectService all have a Dispose method, to make sure all resources are cleaened up.

If you use NHibernateProjectRepository or ProjectService in your tests, always call the Dispose method when you're finished! Otherwise, you will get memory leaks and possibly other tests failing because of out of memory errors!

 

Gena:

Here are 2 code snippets:

Code Block
[TestFixture]
public class ProjectIntegrationTest
{
    [Test]
    [Category("DataAccess")]
    public void SaveProject()
    {
            using (var repository = new NHibernateProjectRepository()) // <== Disposed() automatically
            {
                var project = new Project();

                repository.Create(path);
                repository.SaveOrUpdate(project);

                using (var repository2 = new NHibernateProjectRepository()) // <== Disposed() automatically
                {
                    repository2.Open();

                    retrievedProject = repository2.GetProject();

                    // ... asserts ...
                }
            }
      }
}

Another way, if test class has a lot of such integration tests:

Code Block

[TestFixture]
[Category("DataAccess")]
public class ProjectDataAccessTest
{
    NHibernateProjectRepository repository;

    [SetUp]
    public void SetUp()
    {
        repository = new NHibernateProjectRepository();
    }

    [TearDown]
    public void TearDown()
    {
        repository.Dispose();
    }

    [Test]
    public void SaveProject()
    {
            var project = new Project();

            repository.Create(path);
            repository.SaveOrUpdate(project);

            using (var repository2 = new NHibernateProjectRepository()) // <== Disposed() automatically
            {
                repository2.Open();

                retrievedProject = repository2.GetProject();

                // ... asserts ...
            }
      }
}

... or just make sure you call it explicitly (smile)