예제 #1
0
        private IFileSystemTransaction GetStandaloneTransaction()
        {
            IFileSystemTransaction standaloneTransaction;

            using (var scopeTemp = FileSystemProvider.CreateStandaloneTransactionScope(true))
            {
                standaloneTransaction = scopeTemp.DetachTransaction();
            }
            Assert.IsNotNull(standaloneTransaction);
            Assert.IsTrue(standaloneTransaction.IsActive);
            return(standaloneTransaction);
        }
예제 #2
0
        private KtmTransactionScope CreateStandaloneKtmTransactionScope(bool dispose)
        {
            var scope_ = FileSystemProvider.CreateStandaloneTransactionScope(dispose);

            Assert.IsInstanceOf <KtmTransactionScope>(scope_);
            var scope = (KtmTransactionScope)scope_;

            Assert.IsTrue(scope.IsTransactionOwner);
            Assert.IsTrue(scope.ToBeDisposed);
            Assert.IsTrue(scope.HasChangedContext);

            Assert.AreSame(scope.UnderlyingTransaction, AmbientTransaction);
            Assert.IsInstanceOf <KtmTransaction>(AmbientTransaction);

            Assert.IsFalse(scope.UnderlyingTransaction.IsPartOfManagedAmbient);

            return(scope);
        }
예제 #3
0
        public void TestLazyNullScope()
        {
            if (!EnvironmentSupportsTransactions)
            {
                Assert.Inconclusive("Cannot test in this environment");
                return;
            }

            Assume.That(AmbientTransaction == null, "Leftovers are not expected here");

            // thus allowing to use ambient storage transaction
            Repository.Settings.StorageTransactionSettings = StorageTransactionSettings.DisallowJoiningAmbientManaged;
            // no ambient
            using (var scope = StorageTransactionScope.CreateLazy(Repository, null))
            {
                Assert.IsTrue(scope.IsNullScope);
                Assert.IsFalse(scope.HasChangedContext);
            }

            // now with ambient

            // thus disallowing to use ambient storage transaction
            Repository.Settings.StorageTransactionSettings = StorageTransactionSettings.DisallowJoiningAmbientManaged | StorageTransactionSettings.AlwaysStartNew;

            using (var outerScope = FileSystemProvider.CreateStandaloneTransactionScope(true))
            {
                Assert.IsNotNull(AmbientTransaction);

                using (var scope = StorageTransactionScope.CreateLazy(Repository, null))
                {
                    Assert.IsTrue(scope.IsNullScope);
                    Assert.IsTrue(scope.HasChangedContext);
                    Assert.IsNull(AmbientTransaction);
                }
            }
            Assert.IsNull(AmbientTransaction);
        }