public void Timestamp_DeleteDirectory_GrandparentDirectoryIsntUpdated() { // arrange using (var driver = new DiskDriver()) { var beforeCreate = DateTime.Now; var f = driver.CreateOrGetDirectory(@"c:\parent\subfolder\folder"); var parent = driver.GetDirectory(@"c:\parent"); var expected = beforeCreate.AddMinutes(-5); parent.LastAccessTime = parent.LastWriteTime = parent.CreationTime = expected; Assert.IsTrue(parent.LastAccessTime == expected); Assert.IsTrue(parent.LastWriteTime == expected); Assert.IsTrue(parent.CreationTime == expected); // act var folder = driver.GetDirectory(@"c:\parent\subfolder\folder"); folder.Delete(); // Assert Assert.IsTrue(parent.LastAccessTime == expected); Assert.IsTrue(parent.LastWriteTime == expected); Assert.IsTrue(parent.CreationTime == expected); } }
public void Delete_ForDirectory_Recurse_DirectoryNotEmpty_CanDelete() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\folder\subfolder\file.txt"); driver.CreateOrGetFile(@"c:\folder\file.txt"); driver.CreateOrGetFile(@"c:\other_folder\file.txt"); // act var folder = driver.GetDirectory(@"c:\folder"); folder.Delete(true); // assert folder.Refresh(); Assert.IsFalse(folder.Exists); Assert.IsFalse(driver.GetDirectory(@"c:\folder\subfolder").Exists); Assert.IsFalse(driver.GetFile(@"c:\folder\subfolder\file.txt").Exists); var c = driver.GetDirectory(@"c:\"); var filesAfterDelete = c.GetFiles("*", SearchOption.AllDirectories); Assert.AreEqual(1, filesAfterDelete.Length); Assert.AreEqual(@"c:\other_folder\file.txt", filesAfterDelete[0].FullName); var directoriesAfterDelete = c.GetDirectories("*", SearchOption.AllDirectories); Assert.AreEqual(1, directoriesAfterDelete.Length); Assert.AreEqual(@"c:\other_folder", directoriesAfterDelete[0].FullName); } }
public void Move_CanUpdateStubs() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_1\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_2\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_2\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_1\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_2\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_2\file_2.txt"); driver.CreateOrGetDirectory(@"c:\targ"); var folder_1 = driver.GetDirectory(@"c:\src\folder_1"); // act folder_1.MoveTo(@"c:\targ\folder_1"); // assert var fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_1\file_1.txt"); Assert.AreEqual(@"c:\targ\folder_1\subfolder_1\file_1.txt", fileStub.FullName); fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_1\file_2.txt"); Assert.AreEqual(@"c:\targ\folder_1\subfolder_1\file_2.txt", fileStub.FullName); fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_2\file_1.txt"); Assert.AreEqual(@"c:\targ\folder_1\subfolder_2\file_1.txt", fileStub.FullName); fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_2\file_2.txt"); Assert.AreEqual(@"c:\targ\folder_1\subfolder_2\file_2.txt", fileStub.FullName); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_1\file_1.txt"); Assert.AreEqual(@"c:\src\folder_2\subfolder_1\file_1.txt", fileStub.FullName); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_1\file_2.txt"); Assert.AreEqual(@"c:\src\folder_2\subfolder_1\file_2.txt", fileStub.FullName); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_2\file_1.txt"); Assert.AreEqual(@"c:\src\folder_2\subfolder_2\file_1.txt", fileStub.FullName); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_2\file_2.txt"); Assert.AreEqual(@"c:\src\folder_2\subfolder_2\file_2.txt", fileStub.FullName); var dirStub = driver.GetDirectory(@"c:\targ"); Assert.AreEqual(@"c:\targ", dirStub.FullName); dirStub = driver.GetDirectory(@"c:\targ\folder_1"); Assert.AreEqual(@"c:\targ\folder_1", dirStub.FullName); dirStub = driver.GetDirectory(@"c:\targ\folder_1\subfolder_1"); Assert.AreEqual(@"c:\targ\folder_1\subfolder_1", dirStub.FullName); dirStub = driver.GetDirectory(@"c:\targ\folder_1\subfolder_2"); Assert.AreEqual(@"c:\targ\folder_1\subfolder_2", dirStub.FullName); dirStub = driver.GetDirectory(@"c:\src"); Assert.AreEqual(@"c:\src", dirStub.FullName); dirStub = driver.GetDirectory(@"c:\src\folder_2"); Assert.AreEqual(@"c:\src\folder_2", dirStub.FullName); dirStub = driver.GetDirectory(@"c:\src\folder_2\subfolder_1"); Assert.AreEqual(@"c:\src\folder_2\subfolder_1", dirStub.FullName); dirStub = driver.GetDirectory(@"c:\src\folder_2\subfolder_2"); Assert.AreEqual(@"c:\src\folder_2\subfolder_2", dirStub.FullName); } }
public void Timestamps_DeleteDirectory_UpdateTimestamps() { // arrange using (var driver = new DiskDriver()) { var subdir = driver.CreateOrGetDirectory(@"c:\folder\subdir"); var folder = driver.GetDirectory(@"c:\folder"); var beforeDelete = DateTime.Now; var old = beforeDelete.AddMinutes(-5); folder.LastAccessTime = folder.LastWriteTime = folder.CreationTime = old; Assert.IsTrue(folder.LastAccessTime == old); Assert.IsTrue(folder.LastWriteTime == old); Assert.IsTrue(folder.CreationTime == old); // act subdir.Delete(); folder.Refresh(); // Assert Assert.IsTrue(folder.LastAccessTime >= beforeDelete); Assert.IsTrue(folder.LastWriteTime >= beforeDelete); Assert.IsTrue(folder.CreationTime == old); } }
public void Timestamps_DeleteFile_GrandparentDirectoryIsntUpdated() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\parent\folder\file.txt"); var parent = driver.GetDirectory(@"c:\parent"); var beforeDelete = DateTime.Now; var old = beforeDelete.AddMinutes(-5); parent.LastAccessTime = parent.LastWriteTime = parent.CreationTime = old; Assert.IsTrue(parent.LastAccessTime == old); Assert.IsTrue(parent.LastWriteTime == old); Assert.IsTrue(parent.CreationTime == old); // act var file = driver.GetFile(@"c:\parent\folder\file.txt"); file.Delete(); parent.Refresh(); // Assert Assert.IsTrue(parent.LastAccessTime == old); Assert.IsTrue(parent.LastWriteTime == old); Assert.IsTrue(parent.CreationTime == old); } }
public void GetDirectories_Recurse_Wilchars_CanFind() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder_1"); driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder_2"); driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder1"); // to check if they are excluded from result driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder1"); // to check if they are excluded from result driver.CreateOrGetDirectory(@"c:\root\folder_2\subfolder_3"); driver.CreateOrGetDirectory(@"c:\root\folder_2\subfolder_4"); driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder3"); // to check if they are excluded from result driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder4"); // to check if they are excluded from result var root = driver.GetDirectory(@"c:\root"); // act var result = root.GetDirectories(@"subfolder_*", SearchOption.AllDirectories); // assert Assert.AreEqual(4, result.Length); Assert.AreEqual(1, result.Where(i => i.FullName == @"c:\root\folder_1\subfolder_1").Count()); Assert.AreEqual(1, result.Where(i => i.FullName == @"c:\root\folder_1\subfolder_2").Count()); Assert.AreEqual(1, result.Where(i => i.FullName == @"c:\root\folder_2\subfolder_3").Count()); Assert.AreEqual(1, result.Where(i => i.FullName == @"c:\root\folder_2\subfolder_4").Count()); } }
public void Move_CanMoveOwnership() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_1\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_2\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_2\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_1\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_2\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_2\file_2.txt"); driver.CreateOrGetDirectory(@"c:\targ"); var folder_1 = driver.GetDirectory(@"c:\src\folder_1"); // act folder_1.MoveTo(@"c:\targ\folder_1"); // assert var c = driver.GetDirectory(@"c:\"); var resultFile = c.GetFiles("*", SearchOption.AllDirectories); Assert.AreEqual(8, resultFile.Length); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\targ\folder_1\subfolder_1\file_1.txt")).Count()); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\targ\folder_1\subfolder_1\file_2.txt")).Count()); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\targ\folder_1\subfolder_2\file_1.txt")).Count()); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\targ\folder_1\subfolder_2\file_2.txt")).Count()); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\src\folder_2\subfolder_1\file_1.txt")).Count()); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\src\folder_2\subfolder_1\file_2.txt")).Count()); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\src\folder_2\subfolder_2\file_1.txt")).Count()); Assert.AreEqual(1, resultFile.Where(i => i.FullName.Equals(@"c:\src\folder_2\subfolder_2\file_2.txt")).Count()); var resultDir = c.GetDirectories("*", SearchOption.AllDirectories); Assert.AreEqual(8, resultDir.Length); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\targ")).Count()); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\targ\folder_1")).Count()); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\targ\folder_1\subfolder_1")).Count()); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\targ\folder_1\subfolder_2")).Count()); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\src")).Count()); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\src\folder_2")).Count()); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\src\folder_2\subfolder_1")).Count()); Assert.AreEqual(1, resultDir.Where(i => i.FullName.Equals(@"c:\src\folder_2\subfolder_2")).Count()); } }
public void SetAttributes_DirectoryDoesntExist_Throws() { // arrange using (var driver = new DiskDriver()) { var folder = driver.GetDirectory(@"c:\folder"); // act/assert Assert.ThrowsException <DirectoryNotFoundException>(() => folder.Attributes = FileAttributes.Hidden); } }
public void Delete_ForDirectory_DirectoryDoesntExist_Throws() { // arrange using (var driver = new DiskDriver()) { var folder = driver.GetDirectory(@"c:\folder"); // act/assert Assert.ThrowsException <DirectoryNotFoundException>(() => folder.Delete(true)); } }
public void Move_SourceDoesntExists_Throws() { // arrange using (var driver = new DiskDriver()) { var dir = driver.GetDirectory(@"c:\dir"); // act/assert Assert.ThrowsException <DirectoryNotFoundException>(() => dir.MoveTo(@"c:\temp\dir")); } }
public void GetFiles_DirectoryDoesntExist_Throws() { // arrange using (var driver = new DiskDriver()) { var root = driver.GetDirectory(@"c:\root"); // act/assert Assert.ThrowsException <DirectoryNotFoundException>(() => root.GetFiles(@"file.txt", SearchOption.AllDirectories)); } }
public void Create_FileWithTheSameNameAlreadyExists_Throws() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\folder"); var folder = driver.GetDirectory(@"c:\folder"); // act/assert Assert.ThrowsException <IOException>(() => folder.Create()); } }
public void GetFiles_ExplicitSearchPath_PartOfPathNotExists_Throws() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\root\folder_1\file_1.txt"); var root = driver.GetDirectory(@"c:\root"); // act/assert Assert.ThrowsException <DirectoryNotFoundException>(() => root.GetFiles(@"folder_2\subfolder_*", SearchOption.AllDirectories)); } }
public void TimeStamps_NonexistingFile_ReturnsMinValue() { // arrange using (var driver = new DiskDriver()) { var expected = DateTime.MinValue; var f = driver.GetDirectory(@"c:\folder"); // Assert Assert.IsTrue(f.LastAccessTime == expected); Assert.IsTrue(f.LastWriteTime == expected); Assert.IsTrue(f.CreationTime == expected); } }
public void Create_CanCreate() { // arrange using (var driver = new DiskDriver()) { var f = driver.GetDirectory(@"c:\temp"); // act f.Create(); // assert f.Refresh(); Assert.IsTrue(f.Exists); } }
public void GetFiles_ExplicitSearchPath_IllegalWildchar_Throws() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\root\folder_1\subfolder_1"); driver.CreateOrGetFile(@"c:\root\folder_1\subfolder_2"); driver.CreateOrGetFile(@"c:\root\folder_2\subfolder_3"); driver.CreateOrGetFile(@"c:\root\folder_2\subfolder_4"); var root = driver.GetDirectory(@"c:\root"); // act/assert Assert.ThrowsException <ArgumentException>(() => root.GetFiles(@"folder_*\file_*.txt", SearchOption.AllDirectories)); } }
public void GetFiles_TopDirOnly_NoWildchars_CanFind() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\root\folder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\root\file_1.txt"); var root = driver.GetDirectory(@"c:\root"); // act var result = root.GetFiles(@"file_1.txt", SearchOption.TopDirectoryOnly); // assert Assert.AreEqual(1, result.Length); Assert.AreEqual(@"c:\root\file_1.txt", result[0].FullName); } }
public void GetDirectories_Recurse_NoWilchars_CanFind() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder_1"); driver.CreateOrGetDirectory(@"c:\root\folder_1\subfolder_2"); driver.CreateOrGetDirectory(@"c:\root\folder_2\subfolder_3"); driver.CreateOrGetDirectory(@"c:\root\folder_2\subfolder_4"); var root = driver.GetDirectory(@"c:\root"); // act var result = root.GetDirectories(@"subfolder_4", SearchOption.AllDirectories); // assert Assert.AreEqual(1, result.Length); Assert.AreEqual(@"c:\root\folder_2\subfolder_4", result[0].FullName); } }
public void GetFiles_ExplicitSearchPath_CanFind() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\root\folder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\root\folder_1\file_2.txt"); driver.CreateOrGetFile(@"c:\root\folder_2\file_1.txt"); driver.CreateOrGetFile(@"c:\root\folder_2\file_2.txt"); var root = driver.GetDirectory(@"c:\root"); // act var result = root.GetFiles(@"folder_1\file_*.txt", SearchOption.AllDirectories); // assert Assert.AreEqual(2, result.Length); Assert.AreEqual(1, result.Where(i => i.FullName == @"c:\root\folder_1\file_1.txt").Count()); Assert.AreEqual(1, result.Where(i => i.FullName == @"c:\root\folder_1\file_2.txt").Count()); } }
public void Delete_ForDirectory_Flatten_CanRemoveEmptyDir() { // arrange using (var driver = new DiskDriver()) { var folder_1 = driver.CreateOrGetDirectory(@"c:\folder_1"); driver.CreateOrGetDirectory(@"c:\folder_2"); // act folder_1.Delete(false); // assert folder_1.Refresh(); Assert.IsFalse(folder_1.Exists); var root = driver.GetDirectory(@"c:\"); var folders = root.GetDirectories(); Assert.AreEqual(1, folders.Length); Assert.AreEqual(@"c:\folder_2", folders[0].FullName); } }
public void Move_CanUpdateControlBlockCollections() { // arrange using (var driver = new DiskDriver()) { driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_1\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_2\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_1\subfolder_2\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_1\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_1\file_2.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_2\file_1.txt"); driver.CreateOrGetFile(@"c:\src\folder_2\subfolder_2\file_2.txt"); driver.CreateOrGetDirectory(@"c:\targ"); var folder_1 = driver.GetDirectory(@"c:\src\folder_1"); // act folder_1.MoveTo(@"c:\targ\folder_1"); // assert var fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_1\file_1.txt"); Assert.IsTrue(fileStub.Exists); fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_1\file_2.txt"); Assert.IsTrue(fileStub.Exists); fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_2\file_1.txt"); Assert.IsTrue(fileStub.Exists); fileStub = driver.GetFile(@"c:\targ\folder_1\subfolder_2\file_2.txt"); Assert.IsTrue(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_1\subfolder_1\file_1.txt"); Assert.IsFalse(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_1\subfolder_1\file_2.txt"); Assert.IsFalse(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_1\subfolder_2\file_1.txt"); Assert.IsFalse(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_1\subfolder_2\file_2.txt"); Assert.IsFalse(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_1\file_1.txt"); Assert.IsTrue(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_1\file_2.txt"); Assert.IsTrue(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_2\file_1.txt"); Assert.IsTrue(fileStub.Exists); fileStub = driver.GetFile(@"c:\src\folder_2\subfolder_2\file_2.txt"); Assert.IsTrue(fileStub.Exists); var dirStub = driver.GetDirectory(@"c:\targ"); Assert.IsTrue(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\targ\folder_1"); Assert.IsTrue(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\targ\folder_1\subfolder_1"); Assert.IsTrue(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\targ\folder_1\subfolder_2"); Assert.IsTrue(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\src\folder_1"); Assert.IsFalse(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\src\folder_1\subfolder_1"); Assert.IsFalse(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\src\folder_1\subfolder_2"); Assert.IsFalse(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\src"); Assert.IsTrue(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\src\folder_2"); Assert.IsTrue(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\src\folder_2\subfolder_1"); Assert.IsTrue(dirStub.Exists); dirStub = driver.GetDirectory(@"c:\src\folder_2\subfolder_2"); Assert.IsTrue(dirStub.Exists); } }