C# Integration testing with rollback -


i try integration testing rollback. use sql server. setup, took topic, looks this:

private transactionscope scope;  [testinitialize] public void initialize() {     this.scope = new transactionscope(); }  [testcleanup] public void testcleanup() {     this.scope.dispose(); } 

testing method:

var newuser = new userdetailmodel(); newuser.id = 1; newuser.email = "test@test.cz"; newuser.firstname = "test"; newuser.lastname = "user"; newuser.username = "test.user"; await usermanager.addasync(newuser); 

there shouldn't new user in db after test completed, have new user in db test finished. tried same method database.begintransaction():

using (var transaction = unitofwork.getdbcontext().database.begintransaction()) {     var newuser = new userdetailmodel();     newuser.id = 1;     newuser.email = "test@test.cz";     newuser.firstname = "test";     newuser.lastname = "user";     newuser.username = "test.user";     await usermanager.addasync(newuser);      transaction.rollback(); } 

rollback doesn't work either.

to make transactionscope , async work use .net 4.5.1. or later , have explicitly opt-in transaction flow across thread continuations specifying transactionscopeasyncflowoption.enabled this:

new transactionscope(transactionscopeasyncflowoption.enabled) 

read more on topic: https://particular.net/blog/transactionscope-and-async-await-be-one-with-the-flow


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -