Can I use TransactionScope rollback with selenium or batting?

I am trying to do automated web testing of my ASP.NET application. I was hoping to use the AutoRollback attribute from the Xunit.net extensions to undo any database changes that were made during the test. AutoRollback uses TransactionScope to start a transaction before a test and roll back.

When I try to hit my web application during a transaction, it always expires. It seems that this should work, some ideas? Here is my test:

[Fact] [AutoRollback] public void Entity_should_be_in_list() { Entity e = new Entity { Name = "Test", }; dataContext.Entities.InsertOnSubmit(e); dataContext.SubmitChanges(); selenium.Open("http://localhost/MyApp"); Assert.True(selenium.IsTextPresent("Test")); } 
+6
c # selenium
source share
1 answer

Your ASP.NET application has a separate database context, and it does not know that you want to join the transaction launched by Xunit.net. Apparently, the database blocks some resources when the transaction starts; the web application has been patiently waiting for some time and will eventually refuse.

I think it's best to start with an empty database and use an SQL script to create the schema and populate the lookup tables (your database is under source control , right?). Another approach is to back up the database before running the tests, and then restore after completion.

+5
source share

All Articles