I am having a strange problem when testing Nhibernate repositories.
I have 10 unit tests as shown below. Each time you run them in a package, the first failure is completed, and the rest is successful. If you run them one by one, they all fail. If restarting MSDTC before my test, it sometimes behaves as before, and sometimes all tests complete successfully. I canβt find the pattern why it behaves this way.
I want the transaction rollback to start with a clean DB for each test, hence deleting the transaction.
Test / tests do not work due to this error:
System.Data.SqlClient.SqlException: MSDTC on server "MYCOMPUTERNAME \ SQLEXPRESS" is not available.
My tests look like this:
[TestInitialize] public void MyTestInitialize() { _transactionScope = new TransactionScope(); } [TestCleanup] public void MyTestCleanup() { if (_transactionScope != null) { _transactionScope.Dispose(); _transactionScope = null; } } [TestMethod] [TestCategory("RepositoryTests")] public void RepositoryCanSaveAProduct() { var platform = ProductObjectMother.CreatePlatform("100010", "Supplier 10"); var mainsegment = ProductObjectMother.CreateMainSegment("123"); var application = ProductObjectMother.CreateApplication("Foo"); var productfamily = ProductObjectMother.CreateProductFamily("X99"); Engine i = ProductObjectMother.CreateEngine(platform, productfamily, application, mainsegment); var repository = new ProductRepository(); repository.Save(i); repository.Flush(); }
Glenn source share