Created
October 4, 2009 05:46
-
-
Save dvhthomas/201177 to your computer and use it in GitHub Desktop.
Expecting an exception in NUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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