Hello. I'm writing an integration tests for my database, and I've got one question. At the beginning of a test method I'm adding some objects to database and at the end of the method I should remove it.
So I've got a code like:
var group = new ContactGroup { Name = UserLogin + "_test_group" };
group.ID = _provider.AddGroup(UserLogin, group);
Assert.That(_provider.GetGroup(UserLogin, group.ID), Is.Not.Null);
_provider.RemoveGroup(UserLogin, group.ID);
The point is that if assertion fails, RemoveGroup won't be executed. What can I do about it?
If i try this:
var group = new ContactGroup { Name = UserLogin + "_test_group" };
group.ID = _provider.AddGroup(UserLogin, group);
try
{
Assert.That(_provider.GetGroup(UserLogin, group.ID), Is.Not.Null);
}
finally
{
_provider.RemoveGroup(UserLogin, group.ID);
}
should I rethrow AssertionException like this
catch (AssertionException)
{
throw;
}
?