This question is locked. New answers and comments are not allowed.
It does not appear that OA plays well with TransactionScope. My OA version is 2012.2.816.1. Here is the use case that consistently fails:
1. Create an integration test and surround the code inside the integration test with a using(TransactionScope... block.
2. Create a new context, add an item to the context, and call the SaveChanges. Note I am NOT calling transaction.Complete() because when it leaves the block, I want the change rolled back.
3. Load that same item from the context
4. The item was not actually saved to the database -- you can tell because the ID field is still 0.
Here is a sample code block:
This is causing significant headaches for our integration testing. Two questions:
1. What is the support of OA with Transaction Scope?
2. How can an automatic rollback of changes be implemented, if TS is not supported? In order to accurately test code, I need changes to be saved to the DB, tests cases run, and then rolled back between tests. I'm not wild about running a script between each test, when TS typically has done this for me.
Thanks!
1. Create an integration test and surround the code inside the integration test with a using(TransactionScope... block.
2. Create a new context, add an item to the context, and call the SaveChanges. Note I am NOT calling transaction.Complete() because when it leaves the block, I want the change rolled back.
3. Load that same item from the context
4. The item was not actually saved to the database -- you can tell because the ID field is still 0.
Here is a sample code block:
using
(TransactionScope transaction =
new
TransactionScope())
{
using
(MyDbContext context =
new
MyDbContext())
{
var item =
new
Item();
item.Name =
"some random new name"
;
context.Add(item);
context.SaveChanges();
// the item.Id property is still 0, even though it should have been saved, so the below will fail
Assert.AreNotEqual(0, item.Id);
}
}
This is causing significant headaches for our integration testing. Two questions:
1. What is the support of OA with Transaction Scope?
2. How can an automatic rollback of changes be implemented, if TS is not supported? In order to accurately test code, I need changes to be saved to the DB, tests cases run, and then rolled back between tests. I'm not wild about running a script between each test, when TS typically has done this for me.
Thanks!