public void CreateFileStreamWhenTransactionalFileSystemUnsupported() { FileTransacted._operatingSystem = OperatingSystemExtensionsFixture.WindowsXP; using (var file = FileTransacted.Create(_filename)) { Assert.That(file, Is.TypeOf <FileStream>()); } }
public void TransactionRollbackOnDispose() { using (var file = FileTransacted.Create(_filename)) { Assert.That(file, Is.TypeOf <FileStreamTransacted>()); file.Write(_buffer, 0, _buffer.Length); } Assert.That(File.Exists(_filename), Is.False, "Transaction should have been rolled back: file is found."); }
internal FileStreamTransacted(IntPtr transactionHandle, string path, int bufferSize) : base(FileTransacted.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 TransactionCommitHasToBeExplicit() { using (var file = FileTransacted.Create(_filename)) { Assert.That(file, Is.TypeOf <FileStreamTransacted>()); file.Write(_buffer, 0, _buffer.Length); ((FileStreamTransacted)file).Commit(); } Assert.That(File.Exists(_filename), "Transaction should have been committed: file is not found."); }
public void CreateFileStreamWhenNetworkPath() { var uncFilename = @"\\localhost\" + _filename.Replace(':', '$'); FileTransacted._operatingSystem = OperatingSystemExtensionsFixture.Windows7; using (var file = FileTransacted.Create(uncFilename)) { Assert.That(file, Is.TypeOf <FileStream>()); } }
public void TransactionRollbackOnFinalize() { var file = FileTransacted.Create(_filename); Assert.That(file, Is.TypeOf <FileStreamTransacted>()); file.Write(_buffer, 0, _buffer.Length); // ReSharper disable RedundantAssignment file = null; // ReSharper restore RedundantAssignment GC.Collect(); GC.WaitForPendingFinalizers(); Assert.That(File.Exists(_filename), Is.False, "Transaction should have been rolled back: file is found."); }
public void CreateFileStreamWhenGivenAmbientTransactionAndTransactionalFileSystemSupported() { FileTransacted._operatingSystem = OperatingSystemExtensionsFixture.Windows7; using (new TransactionScope()) { // grab kernel level transaction handle var dtcTransaction = TransactionInterop.GetDtcTransaction(Transaction.Current); // ReSharper disable once SuspiciousTypeConversion.Global var kernelTransaction = (IKernelTransaction)dtcTransaction; var file = FileTransacted.Create(_filename, 1024, kernelTransaction); Assert.That(file, Is.TypeOf <FileStream>()); } }
public void TransactionRollbackWithAmbientTransaction() { using (new TransactionScope()) { // ReSharper disable once SuspiciousTypeConversion.Global var kernelTransaction = (IKernelTransaction)TransactionInterop.GetDtcTransaction(Transaction.Current); using (var file = FileTransacted.Create(_filename, 1024, kernelTransaction)) { Assert.That(file, Is.TypeOf <FileStream>()); file.Write(_buffer, 0, _buffer.Length); } // this is the root scope and failing to cast a vote will abort the ambient transaction } Assert.That(File.Exists(_filename), Is.False); }
public void TransactionCommitWithAmbientTransaction() { using (var scope = new TransactionScope()) { // ReSharper disable once SuspiciousTypeConversion.Global var kernelTransaction = (IKernelTransaction)TransactionInterop.GetDtcTransaction(Transaction.Current); using (var file = FileTransacted.Create(_filename, 1024, kernelTransaction)) { Assert.That(file, Is.TypeOf <FileStream>()); file.Write(_buffer, 0, _buffer.Length); } // this is the root scope and it has to cast a vote scope.Complete(); } Assert.That(File.Exists(_filename)); }
public void MoveWhenAmbientTransactionDoesNotComplete() { using (var writer = File.CreateText(_filename)) { writer.WriteLine("test"); } Assert.That(File.Exists(_filename), Is.True); Assert.That(File.Exists(_filename + ".moved"), Is.False); FileTransacted._operatingSystem = OperatingSystemExtensionsFixture.Windows7; using (new TransactionScope()) { var dtcTransaction = TransactionInterop.GetDtcTransaction(Transaction.Current); // ReSharper disable once SuspiciousTypeConversion.Global var kernelTransaction = (IKernelTransaction)dtcTransaction; FileTransacted.Move(_filename, _filename + ".moved", kernelTransaction); // this is the root scope and failing to cast a vote will abort the ambient transaction } Assert.That(File.Exists(_filename), Is.True); Assert.That(File.Exists(_filename + ".moved"), Is.False); }