public void CreateFileStreamWhenTransactionalFileSystemUnsupported()
 {
     TransactionalFile._operatingSystem = OperatingSystemExtensionsFixture.WindowsXP;
     using (var file = TransactionalFile.Create(_filename))
     {
         file.Should().BeOfType <FileStream>();
     }
 }
 internal TransactionalFileStream(IntPtr transactionHandle, string path, int bufferSize)
     : base(TransactionalFile.CreateFileTransactedHandle(transactionHandle, path), FileAccess.Write, bufferSize)
 {
     if (_logger.IsDebugEnabled)
     {
         _logger.DebugFormat("Transacted file stream created for writing at path '{0}'.", path);
     }
     _transactionHandle = transactionHandle;
 }
 public void TransactionRollbackOnDispose()
 {
     using (var file = TransactionalFile.Create(_filename))
     {
         file.Should().BeOfType <TransactionalFileStream>();
         file.Write(_buffer, 0, _buffer.Length);
     }
     File.Exists(_filename).Should().BeFalse("Transaction should have been rolled back: file is found.");
 }
        public void CreateFileStreamWhenNetworkPath()
        {
            var uncFilename = @"\\localhost\" + _filename.Replace(':', '$');

            TransactionalFile._operatingSystem = OperatingSystemExtensionsFixture.Windows7;
            using (var file = TransactionalFile.Create(uncFilename))
            {
                file.Should().BeOfType <FileStream>();
            }
        }
 public void TransactionCommitHasToBeExplicit()
 {
     using (var file = TransactionalFile.Create(_filename))
     {
         file.Should().BeOfType <TransactionalFileStream>();
         file.Write(_buffer, 0, _buffer.Length);
         ((TransactionalFileStream)file).Commit();
     }
     File.Exists(_filename).Should().BeTrue("Transaction should have been committed: file is not found.");
 }
        public void TransactionRollbackOnFinalize()
        {
            var file = TransactionalFile.Create(_filename);

            file.Should().BeOfType <TransactionalFileStream>();
            file.Write(_buffer, 0, _buffer.Length);
            file = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            File.Exists(_filename).Should().BeFalse("Transaction should have been rolled back: file is found.");
        }
 public void CreateFileStreamWhenGivenAmbientTransactionAndTransactionalFileSystemSupported()
 {
     TransactionalFile._operatingSystem = OperatingSystemExtensionsFixture.Windows7;
     using (new TransactionScope())
     {
         // grab kernel level transaction handle
         var dtcTransaction    = TransactionInterop.GetDtcTransaction(Transaction.Current);
         var kernelTransaction = (IKernelTransaction)dtcTransaction;
         var file = TransactionalFile.Create(_filename, 1024, kernelTransaction);
         file.Should().BeOfType <FileStream>();
     }
 }
Beispiel #8
0
        public void TransactionRollbackWithAmbientTransaction()
        {
            using (new TransactionScope())
            {
                var kernelTransaction = (IKernelTransaction)TransactionInterop.GetDtcTransaction(Transaction.Current);
                using (var file = TransactionalFile.Create(_filename, 1024, kernelTransaction))
                {
                    file.Should().BeOfType <FileStream>();
                    file.Write(_buffer, 0, _buffer.Length);
                }
                // this is the root scope and failing to cast a vote will abort the ambient transaction
            }

            File.Exists(_filename).Should().BeFalse();
        }
Beispiel #9
0
        public void TransactionCommitWithAmbientTransaction()
        {
            using (var scope = new TransactionScope())
            {
                var kernelTransaction = (IKernelTransaction)TransactionInterop.GetDtcTransaction(Transaction.Current);
                using (var file = TransactionalFile.Create(_filename, 1024, kernelTransaction))
                {
                    file.Should().BeOfType <FileStream>();
                    file.Write(_buffer, 0, _buffer.Length);
                }
                // this is the root scope and it has to cast a vote
                scope.Complete();
            }

            File.Exists(_filename).Should().BeTrue();
        }
        public void MoveWhenAmbientTransactionCompletes()
        {
            using (var writer = File.CreateText(_filename))
            {
                writer.WriteLine("test");
            }

            File.Exists(_filename).Should().BeTrue();
            File.Exists(_filename + ".moved").Should().BeFalse();

            TransactionalFile._operatingSystem = OperatingSystemExtensionsFixture.Windows7;
            using (var scope = new TransactionScope())
            {
                var dtcTransaction    = TransactionInterop.GetDtcTransaction(Transaction.Current);
                var kernelTransaction = (IKernelTransaction)dtcTransaction;
                TransactionalFile.Move(_filename, _filename + ".moved", kernelTransaction);
                // this is the root scope and it has to cast a vote
                scope.Complete();
            }

            File.Exists(_filename).Should().BeFalse();
            File.Exists(_filename + ".moved").Should().BeTrue();
        }
        public void MoveWhenAmbientTransactionDoesNotComplete()
        {
            using (var writer = File.CreateText(_filename))
            {
                writer.WriteLine("test");
            }

            File.Exists(_filename).Should().BeTrue();
            File.Exists(_filename + ".moved").Should().BeFalse();

            TransactionalFile._operatingSystem = OperatingSystemExtensionsFixture.Windows7;
            using (new TransactionScope())
            {
                var dtcTransaction = TransactionInterop.GetDtcTransaction(Transaction.Current);
                // ReSharper disable once SuspiciousTypeConversion.Global
                var kernelTransaction = (IKernelTransaction)dtcTransaction;
                TransactionalFile.Move(_filename, _filename + ".moved", kernelTransaction);
                // this is the root scope and failing to cast a vote will abort the ambient transaction
            }

            File.Exists(_filename).Should().BeTrue();
            File.Exists(_filename + ".moved").Should().BeFalse();
        }