public void CreateFileTranscationally_Commit() { if (Environment.OSVersion.Version.Major < 6) { Assert.Ignore("TxF not supported"); return; } string filepath = testFixturePath.CombineAssert("temp").Combine("test"); if (File.Exists(filepath)) { File.Delete(filepath); } infosCreated.Add(filepath); using (var tx = new FileTransaction("Commit TX")) { tx.Begin(); tx.WriteAllText(filepath, "Transactioned file."); tx.Commit(); Assert.That(tx.Status == TransactionStatus.Committed); } Assert.That(File.Exists(filepath), "The file should exists after the transaction."); Assert.That(File.ReadAllLines(filepath)[0], Is.EqualTo("Transactioned file.")); }
public void NestedFileTransaction_CanBeCommitted() { if (Environment.OSVersion.Version.Major < 6) { Assert.Ignore("TxF not supported"); return; } Assert.That(tm.CurrentTransaction, Is.Null); var stdTx = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); stdTx.Begin(); Assert.That(tm.CurrentTransaction, Is.Not.Null); Assert.That(tm.CurrentTransaction, Is.EqualTo(stdTx)); // invocation.Proceed() in interceptor var childTx = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); Assert.That(childTx, Is.InstanceOf(typeof(ChildTransaction))); Assert.That(tm.CurrentTransaction, Is.EqualTo(childTx), "Now that we have created a child, it's the current tx."); var txF = new FileTransaction(); childTx.Enlist(new FileResourceAdapter(txF)); childTx.Begin(); txF.WriteAllText(_FilePath, "Hello world"); childTx.Commit(); stdTx.Commit(); Assert.That(File.Exists(_FilePath)); Assert.That(File.ReadAllLines(_FilePath)[0], Is.EqualTo("Hello world")); // first we need to dispose the child transaction. tm.Dispose(childTx); // now we can dispose the main transaction. tm.Dispose(stdTx); Assert.That(txF.Status, Is.EqualTo(TransactionStatus.Committed)); Assert.That(txF.IsDisposed); }
public void CreateFileTranscationally_Commit() { if (Environment.OSVersion.Version.Major < 6) { Assert.Ignore("TxF not supported"); return; } string filepath = testFixturePath.CombineAssert("temp").Combine("test"); if (File.Exists(filepath)) File.Delete(filepath); infosCreated.Add(filepath); using (var tx = new FileTransaction("Commit TX")) { tx.Begin(); tx.WriteAllText(filepath, "Transactioned file."); tx.Commit(); Assert.That(tx.Status == TransactionStatus.Committed); } Assert.That(File.Exists(filepath), "The file should exists after the transaction."); Assert.That(File.ReadAllLines(filepath)[0], Is.EqualTo("Transactioned file.")); }