G
Guest
im trying to put a transaction around my NUnit tests fixtures and a seperate
transaction around each test and I'm trying to do that in my base class so
that all my test can benefit from them.
The problem is that I can't find a way to do both transactions. it's either
around the whole fixture or around the test. is there a way to do both?
here is my base test class:
using System;
using System.Transactions;
using NUnit.Framework;
namespace Library.Tests
{
public enum TestTransactionMode
{
None,
AroundFixture,
AroundTests
}
[TestFixture]
public abstract class BaseFixtureWithTxRollback : BaseFixture
{
Transaction fixtureTransaction;
Transaction testTransaction;
private TestTransactionMode testTransactionMode =
TestTransactionMode.AroundFixture;
/// <summary>
/// The transaction mode of the test
/// </summary>
public TestTransactionMode TestTransactionMode
{
get { return testTransactionMode; }
set { testTransactionMode = value; }
}
[TestFixtureSetUp]
public override void TestFixtureSetUp()
{
base.TestFixtureSetUp();
if (testTransactionMode == TestTransactionMode.AroundFixture)
{
fixtureTransaction = new CommittableTransaction();
Transaction.Current = fixtureTransaction;
}
}
[TestFixtureTearDown]
public override void TestFixtureTearDown()
{
if (fixtureTransaction != null)
{
fixtureTransaction.Rollback();
}
}
[SetUp]
public override void TestSetUp()
{
base.TestSetUp();
if (testTransactionMode == TestTransactionMode.AroundTests)
{
testTransaction = new CommittableTransaction();
Transaction.Current = testTransaction;
}
}
[TearDown]
public override void TestTearDown()
{
base.TestTearDown();
if (testTransaction != null)
{
testTransaction.Rollback();
}
}
}
}
So basically i want to have another
TestTransactionMode.AroundTestAndFixture. I found SubordinateTransaction
class which takes ISimpleTransactionSuperior in its constructor but there is
no implementation for this interface.
transaction around each test and I'm trying to do that in my base class so
that all my test can benefit from them.
The problem is that I can't find a way to do both transactions. it's either
around the whole fixture or around the test. is there a way to do both?
here is my base test class:
using System;
using System.Transactions;
using NUnit.Framework;
namespace Library.Tests
{
public enum TestTransactionMode
{
None,
AroundFixture,
AroundTests
}
[TestFixture]
public abstract class BaseFixtureWithTxRollback : BaseFixture
{
Transaction fixtureTransaction;
Transaction testTransaction;
private TestTransactionMode testTransactionMode =
TestTransactionMode.AroundFixture;
/// <summary>
/// The transaction mode of the test
/// </summary>
public TestTransactionMode TestTransactionMode
{
get { return testTransactionMode; }
set { testTransactionMode = value; }
}
[TestFixtureSetUp]
public override void TestFixtureSetUp()
{
base.TestFixtureSetUp();
if (testTransactionMode == TestTransactionMode.AroundFixture)
{
fixtureTransaction = new CommittableTransaction();
Transaction.Current = fixtureTransaction;
}
}
[TestFixtureTearDown]
public override void TestFixtureTearDown()
{
if (fixtureTransaction != null)
{
fixtureTransaction.Rollback();
}
}
[SetUp]
public override void TestSetUp()
{
base.TestSetUp();
if (testTransactionMode == TestTransactionMode.AroundTests)
{
testTransaction = new CommittableTransaction();
Transaction.Current = testTransaction;
}
}
[TearDown]
public override void TestTearDown()
{
base.TestTearDown();
if (testTransaction != null)
{
testTransaction.Rollback();
}
}
}
}
So basically i want to have another
TestTransactionMode.AroundTestAndFixture. I found SubordinateTransaction
class which takes ISimpleTransactionSuperior in its constructor but there is
no implementation for this interface.