nhibernate error recovery

Posted by Berryl on Stack Overflow See other posts from Stack Overflow or by Berryl
Published on 2010-05-18T11:34:53Z Indexed on 2010/05/18 14:10 UTC
Read the original article Hit count: 372

I downloaded Rhino Security today and started going through some of the tests. Several that run perfectly in isolation start getting errors after one that purposely raises an exception runs though. Here is that test:

    [Test]
    public void EntitesGroup_CanCreate()
    {
        var group = _authorizationRepository.CreateEntitiesGroup("Accounts");

        _session.Flush();
        _session.Evict(group);

        var fromDb = _session.Get<EntitiesGroup>(group.Id);
        Assert.NotNull(fromDb);
        Assert.That(fromDb.Name, Is.EqualTo(group.Name));
    }

And here are the tests and error messages that fail:

    [Test]
    public void User_CanSave() {
        var ayende = new User {Name = "ayende"};
        _session.Save(ayende);
        _session.Flush();
        _session.Evict(ayende);

        var fromDb = _session.Get<User>(ayende.Id);
        Assert.That(fromDb, Is.Not.Null);
        Assert.That(ayende.Name, Is.EqualTo(fromDb.Name));
    }

  ----> System.Data.SQLite.SQLiteException : Abort due to constraint violation column Name is not unique


    [Test]
    public void UsersGroup_CanCreate()
    {
        var group = _authorizationRepository.CreateUsersGroup("Admininstrators");

        _session.Flush();
        _session.Evict(group);

        var fromDb = _session.Get<UsersGroup>(group.Id);
        Assert.NotNull(fromDb);
        Assert.That(fromDb.Name, Is.EqualTo(group.Name));
    }

 failed: NHibernate.AssertionFailure : null id in Rhino.Security.Tests.User entry (don't flush the Session after an exception occurs)

Does anyone see how I can reset the state of the in memory SQLite db after the first test? 

I changed the code to use nunit instead of xunit so maybe that is part of the problem here as well.

Cheers,
Berryl

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about unit-testing