TransactionalTestBase is a Visual Basic .NET (VB.NET) Unit Test base class which automatically rolls back any ADO.NET or LINQ transactions.
It uses ServicedComponent with System.Transactions and provides event hooks for ease of use.
This example is the least amount of code required to setup a working Unit Test. There are more examples further down this README.
Create a new Unit Test class. Include any (required) Microsoft Unit Test. Add the TransactionalTestBase file wherever your test are. Subclass child tests off this class.
Each Sub that is decorated with the TestMethod() Attribute will automatically be wrapped in a transaction and rolled back when finished (or when an exception is encountered).
- Init Unit Test
- (Transactions are created)
- PostTransactionBegin (we are now in transactions)
- Unit Test Runs
- (Unit Test passes or fails)
- (Transactions are rolled back)
- PostRollback (we’re out of the transaction, everything has been rolled back)
Unit Test Ends -> PreRollback -> (Transactions rolled back) -> PostRollback -> End
You can optionally override the following functions in your Unit tests.
PreTransactionBegin - called before the transaction is created.
PostTransactionBegin - called after the transaction is created, just before the Unit test is executed.
PreRollback - called after the unit test has run, failed or caused an exception; before the transaction is rolled back.
PostRollback - called after the transaction has been rolled back:
Normally only overriding PostTransactionBegin to add Set-Up code is required. All transactions will roll back when each Unit Test finishes.