private void AlphaFS_BackupFileStream_FilePortionIsLocked_ThrowsIOException(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var file = tempRoot.CreateFile(); Console.WriteLine("Input File Path: [{0}]", file.FullName); using (var bfs = new Alphaleonis.Win32.Filesystem.BackupFileStream(file.FullName, System.IO.FileMode.Open)) try { bfs.ReadStreamInfo(); bfs.Lock(0, 10); UnitTestAssert.ThrowsException <System.IO.IOException>(() => bfs.Lock(0, 10)); } finally { bfs.Unlock(0, 10); } } Console.WriteLine(); }
private void AlphaFS_BackupFileStream_InitializeInstance(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var file = tempRoot.CreateFile(); Console.WriteLine("Input File Path: [{0}]", file.FullName); using (var bfs = new Alphaleonis.Win32.Filesystem.BackupFileStream(file.FullName, System.IO.FileMode.Open)) { UnitTestConstants.Dump(bfs.ReadStreamInfo()); UnitTestConstants.Dump(bfs); } } Console.WriteLine(); }
private void AlphaFS_BackupFileStream_ThrowIOException_SegmentAlreadyUnlocked(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var file = tempRoot.CreateFile(); Console.WriteLine("Input File Path: [{0}]", file.FullName); using (var bfs = new Alphaleonis.Win32.Filesystem.BackupFileStream(file.FullName, System.IO.FileMode.Open)) { bfs.ReadStreamInfo(); ExceptionAssert.IOException(() => bfs.Unlock(0, 10)); } } Console.WriteLine(); }
private void BackupFileStream_InitializeInstance(bool isNetwork) { if (!System.IO.File.Exists(UnitTestConstants.NotepadExe)) { Assert.Inconclusive("Test ignored because {0} was not found.", UnitTestConstants.NotepadExe); } UnitTestConstants.PrintUnitTestHeader(isNetwork); var tempPath = System.IO.Path.GetTempPath(); if (isNetwork) { tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); } using (var rootDir = new TemporaryDirectory(tempPath, "BackupFileStream")) { var file = System.IO.Path.Combine(rootDir.Directory.FullName, System.IO.Path.GetFileName(UnitTestConstants.NotepadExe)); Console.WriteLine("\nInput File Path: [{0}]\n", file); System.IO.File.Copy(UnitTestConstants.NotepadExe, file); using (var bfs = new Alphaleonis.Win32.Filesystem.BackupFileStream(file, System.IO.FileMode.Open)) { #region IOException bfs.Lock(0, 10); var gotException = false; try { bfs.Lock(0, 10); } catch (Exception ex) { var exName = ex.GetType().Name; gotException = exName.Equals("IOException", StringComparison.OrdinalIgnoreCase); Console.WriteLine("\tCaught Exception (Expected): [{0}] Message: [{1}]", exName, ex.Message); } Assert.IsTrue(gotException, "The exception is not caught, but is expected to."); bfs.Unlock(0, 10); #endregion // IOException #region IOException #2 gotException = false; try { bfs.Unlock(0, 10); } catch (Exception ex) { var exName = ex.GetType().Name; gotException = exName.Equals("IOException", StringComparison.OrdinalIgnoreCase); Console.WriteLine("\tCaught Exception (Expected): [{0}] Message: [{1}]", exName, ex.Message); } Assert.IsTrue(gotException, "The exception is not caught, but is expected to."); #endregion // IOException #2 UnitTestConstants.Dump(bfs.ReadStreamInfo(), -10); Console.WriteLine(); UnitTestConstants.Dump(bfs, -14); Console.WriteLine(); } } Console.WriteLine(); }