Shouldn't it work like this?
/// <summary>
/// Tests the insertion of a Customer entity and an VisitingAddress entity. This is done using a System.Transaction transaction scope.
/// </summary>
[Test]
public void InsertCustomerTestSimpleWithSystemTransactionTest()
{
CustomerEntity newCustomer = EntityCreator.CreateNewCustomer( 1 );
AddressEntity newAddress = EntityCreator.CreateNewAddress( 1 );
using( TransactionScope ts = new TransactionScope() )
{
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
// save 2 entities non-recursive. This should be done in one transaction, namely the transaction scope we've started.
newCustomer.TestRunId = _testRunID;
newAddress.TestRunId = _testRunID;
newCustomer.VisitingAddress = newAddress;
newCustomer.BillingAddress = newAddress;
Assert.IsTrue( adapter.SaveEntity( newAddress, true, false ) );
Assert.IsTrue( adapter.SaveEntity( newCustomer, true, false ) );
Assert.AreEqual( EntityState.Fetched, newAddress.Fields.State );
Assert.AreEqual( EntityState.Fetched, newCustomer.Fields.State );
Assert.IsTrue( (((int)newAddress.Fields[(int)AddressFieldIndex.AddressId].CurrentValue) > 0) );
Assert.IsTrue( (((int)newCustomer.Fields[(int)CustomerFieldIndex.CustomerId].CurrentValue) > 0) );
int addressID = newAddress.AddressId;
int customerID = newCustomer.CustomerId;
Assert.IsTrue( (newCustomer.VisitingAddressId == addressID) );
Assert.AreEqual( newAddress, newCustomer.BillingAddress );
Assert.IsTrue( (newAddress == newCustomer.BillingAddress) );
Assert.AreEqual( newAddress.ObjectID, newCustomer.VisitingAddress.ObjectID );
Assert.AreEqual( newAddress.ObjectID, newCustomer.BillingAddress.ObjectID );
// don't call Complete, everything will be rolled back.
}
}
// test if the data is still there. Shouldn't be as the transaction has been rolled back.
using( DataAccessAdapter adapter = new DataAccessAdapter() )
{
CustomerEntity fetchedCustomer = new CustomerEntity( newCustomer.CustomerId );
Assert.IsFalse( adapter.FetchEntity( fetchedCustomer ) );
AddressEntity fetchedAddress = new AddressEntity( newAddress.AddressId );
Assert.IsFalse( adapter.FetchEntity( fetchedAddress ) );
}
}
This is the way it should work, and this should work today with 1.0.2005.1. Please correct me if I'm wrong.
(edit)
I just got networked DTC working and the test above works ok. NO changes to the runtime libs required for this. Please let me know if it doesn't work for you.