Vinny K
Vinny K

Reputation: 1

How to use Transaction Scope rollback for multiple database connections within the same NUnit database test

I am creating a test that injects data in two separate databases(in separate sql servers), then do some action and verify data on a third database.

Now I would like to teardown all the test data from the three databases after each test, but I am unable to use Transaction Scope when my tests interact with multiple databases

Can anyone please help in how to use transaction scope / rollback feature for multiple connections?

I tried using Transaction scope using the following code, this works fine on the tests where only one database connection is created however this does not work on the test where it creates three connections. I use Nunit 3 and .Net core for one project & .Net Framework 4.7 for another separate project, the below error is when using .Net Core

private TransactionScope transaction;

        [SetUp]
        public void BeforeTest()
        {
            transaction = new TransactionScope();
        }

        [TearDown]
        public void AfterTest()
        {
            transaction.Dispose();
        }

I get an error " System.PlatformNotSupportedException : This platform does not support distributed transactions." In my test I use Entity Framework DBcontext to interact with databases. Any help would be highly appreciated. Thanks

Upvotes: 0

Views: 270

Answers (0)

Related Questions