[Test]public void ContentAddedDoesNotPersistsAfterRollbackTest(){ string fileName = "file3.txt"; string originalContents = "First contents"; using (TransactionScope scope = new TransactionScope()) { string newContents = "Hello transacted NTFS."; using (StreamWriter sw = TxFileStream.CreateWriter(fileName)) { sw.Write(newContents); } using (StreamReader sr = TxFileStream.CreateReader(fileName)) { string text = sr.ReadToEnd(); Assert.That(text, Is.EqualTo(newContents)); } // no call to scope.Complete() forces a rollback. } Assert.That(File.Exists(fileName)); Assert.That(File.ReadAllText(fileName), Is.EqualTo(originalContents));}
Kennedy.TxFiles.zip (36 KB)Of course, my library comes with comprehensive unit tests. Look here first to figure out how out use the library.
Note: I fixed a bug in creating transactional StreamWriter's in append mode. Previously they partially overwrote the existing content.
Posted in Visual Studio
A blog by Michael Kennedy
About: Michael is an instructor for DevelopMentor, a .NET enthusiast, an agile pioneer, an entrepreneur, a father of three girls, a husband, a student, and a teacher.
Explore Related Content
Concepts >> azure - Workflow - RESTful - Unit Testing - web - WCF - ASP.Net - MVC - LINQ
Tools >> Visual Studio ClickOnce IIS
Type >> Screencast - Tools - Article - How To - Course
@DevelopMentor_ @mkennedy @andrewclymer @bmaso @coloringinguy @danamiga @ellisteam1 @georgeshep @isidore_us @jason_diamond @markblomsma @marksm @mauricedb @mscottreed @pierrenallet @richardblewett @tonysneed @wallacekelly
Sign In