Does TransactionScope cause a lock?

I am writing some Unit tests against the database, and we use transactions to make sure our test data is deleted at the end.

I'm having a problem where the methods I'm testing use their own TransactionScope objects and seem to be blocked when they hit the database.

This is inside my base class:

BaseScope = new CommittableTransaction(new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUnCommitted, Timeout = new System.TimeSpan(0, 5, 0) });

and then inside the method I'm testing, it does:

using (TransactionScope scope = new TransactionScope())

For the first time, when the code inside the 2nd area touches the database, it freezes. Do I have any way to solve this problem?

+3
source share
3 answers

, , , , , Mocks Stubs.

, , , Unit Testing. (EIT). , , Unit Test mocks. - . .., EIT, ( ) .

. "reset " script .

+6

TransactionScope, , .. . SQLServer 2008, , DTX, . Oracle, , , .

, TransactionScopeOption, . , DTX , . , Oracle, DTX , , " ". " " , , ROLLBACK FORCE . (, SQLServer) ... .

:

  • , , . , , , . , . .
  • , , SQL. , , .

( Oracle PENDING_TRANS $... SQLServer XACT_STATE()).

+4

, , , , . , "ambient" (///), , , .

MSDN CommittableTransactionClass ( ):

TransactionScope, . TransactionScope DependentTransaction , .. , . .

CommittableTransaction , . . , . " " TransactionScopeOption " . , . set reset , , .

, CommittableTransaction, , , .

, , , . finally, , , . , , , , . , RequiresNew, Required.

+3

Source: https://habr.com/ru/post/1768517/


All Articles