daelmo wrote:
My suggestion is: don't do this that way. I mean, having a pending transaction between the page lifecycle. You better:
A. Grab all the info on Page_Load, then on Page_Unload you can create and persist entities. You can use UnitOfWork objects to hold all actions and then commit such object. or
B. Persist and commit on Page_Load, then delete or undo in some way such actions in Page_Unload.
What is the scenario? What are you trying to achieve?
Thanks. I agree. having a long living transaction is a bad idea, esp. in a multithreaded environment, and I should have a teardown that clears the data somehow, not rely on Rollback.
We are trying to achieve a database fixture that is empty at the start of each Page_Load. It gets filled at page load time explicitly or with a test using something like WatiN to drive the browser.
The scenario is that we are testing a single control or group of related controls render properly and its events work how we want, not an application workflow at this point.
We already have the targetted database test fixture creation tool as we created it for TDD use when creating Linq to LLB for the control - it is used extensivley in TDD and has proven very effective - , so we can dynamically produce a very small database populated specifically targetted for a web page/control. We just need to consider the different ways to return the fixture to its empty state after the page has rendered. There are hundreds of controls in the entire set of applications we are building.
Currently, we backup the empty database once then restore it automatically before each test run.
I think creating a teardown method in the test fixture that sends truncate table commands would work fine too and might be easier for us, although it is an additional thing to create in the fixture that requires knowledge of what the data being created is. I didn't understand how using a UoW could help me do this.
Thanks for the comments.