Skip to content

Instantly share code, notes, and snippets.

@dvhthomas
Created October 4, 2009 05:46
Show Gist options
  • Save dvhthomas/201177 to your computer and use it in GitHub Desktop.
Save dvhthomas/201177 to your computer and use it in GitHub Desktop.
Expecting an exception in NUnit
[Test]
public void Throwing_an_exception_prevents_anything_from_being_saved()
{
Assert.Throws<Exception>(() =>
{
using (ISession session = NHibernateHelper.OpenSession())
{
Person person = ObjectMother.ValidPerson();
Person person2 = ObjectMother.ValidPersonTwo();
using (ITransaction transaction = session.BeginTransaction())
{
var ps = new PersonService(session);
ps.SaveChanges(person);
ps.SaveChanges(person2);
throw new Exception();
transaction.Commit();
}
}
});
using (ISession session = NHibernateHelper.OpenSession())
{
var ps = new PersonService(session);
long count = ps.Count();
Assert.AreEqual(0, count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment