public void MakeSureEnumeratorThrowsAfterFolderItEnumeratesOrAnySubfolderUnderItChanges() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); fileSystem.CreateFolder(@"\folder1"); fileSystem.CreateFolder(@"\folder22"); fileSystem.CreateFolder(@"\folder22\subfolder1"); fileSystem.CreateFile(@"\folder22\file1"); fileSystem.CreateFile(@"\folder22\file2"); fileSystem.CreateFile(@"\folder1\file1"); IEnumerator <FileInfo> fileEnumerator = fileSystem.EnumerateFilesUnderFolder(VirtualFileSystem.Root, "*"); fileEnumerator.MoveNext(); fileSystem.CreateFile(@"\folder22\file22"); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidOperationException>( delegate { fileEnumerator.MoveNext(); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidOperationException>( delegate { fileEnumerator.MoveNext(); }); }
public void MakeSureMovingAFolderInvalidatesAllEnumeratorsUnderIt() { Stream stream; VirtualFileSystem fileSystem = TestCollaboratorsFactory.CreateFileSystem(out stream); var folderA = fileSystem.CreateFolder(@"\A"); var folderB = fileSystem.CreateFolder(@"\A\B"); var folderC = fileSystem.CreateFolder(@"\A\B\C"); var folderBUnderRoot = fileSystem.CreateFolder(@"\B"); var enumeratorA = fileSystem.EnumerateFilesUnderFolder(folderA.FullPath, "*"); var enumeratorB = fileSystem.EnumerateFilesUnderFolder(folderB.FullPath, "*"); var enumeratorC = fileSystem.EnumerateFilesUnderFolder(folderC.FullPath, "*"); fileSystem.MoveFolder(folderA.FullPath, folderBUnderRoot.FullPath); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidOperationException>( delegate { enumeratorA.MoveNext(); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidOperationException>( delegate { enumeratorB.MoveNext(); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidOperationException>( delegate { enumeratorC.MoveNext(); }); }
public void TestPathBuilderWithDataSuite1() { PathBuilder pathBuilder = PathBuilder.Default; ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { pathBuilder.CombinePaths(null, "newFile"); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { pathBuilder.CombinePaths(VirtualFileSystem.Root, VirtualFileSystem.Root); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { pathBuilder.CombinePaths("folder1", "newFile.txt"); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { pathBuilder.CombinePaths(@" jkfkjdnvkjklvblks\folder", "newFile.txt"); }); Assert.AreEqual(VirtualFileSystem.Root, pathBuilder.CombinePaths(@"\", "")); Assert.AreEqual(VirtualFileSystem.Root, pathBuilder.CombinePaths(VirtualFileSystem.Root, null)); Assert.AreEqual(VirtualFileSystem.Root + "newFile.txt", pathBuilder.CombinePaths(VirtualFileSystem.Root, "newFile.txt")); Assert.AreEqual(@"\folder1\newFile.txt", pathBuilder.CombinePaths(@"\folder1", "newFile.txt")); Assert.AreEqual(VirtualFileSystem.Root + @"folder1\newFile.txt", pathBuilder.CombinePaths(VirtualFileSystem.Root, @"folder1\newFile.txt")); }
public void CheckValidatorOnDataSuite1() { var validator = new FileSystemArtifactNamesValidator(new char[] { ',', '.', '!' }, 255); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidNameException>( delegate { validator.Validate("dfngsfdjgliulirhliuhrelt!eriih4u3jjoj43o"); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidNameException>( delegate { validator.Validate("......................."); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidNameException>( delegate { validator.Validate(",';'';';';';';''"); }); validator.Validate("12435"); validator.Validate("kfmlksmklgmelglemlgmel"); validator.Validate("@$#@%$@#^#%$^&$%&%^*%&^"); }
public void MakeSureYouCannotMoveAFolderWhileItOrItsSubfoldersIsLocked() { Stream stream; VirtualFileSystem fileSystem = TestCollaboratorsFactory.CreateFileSystem(out stream); fileSystem.CreateFolder(@"\Books"); var literacyFolder = fileSystem.CreateFolder(@"\Books\Literacy"); var tolstoysFolder = fileSystem.CreateFolder(@"\books\literacy\tolstoj"); var warAndPeace = fileSystem.CreateFile(fileSystem.PathBuilder.CombinePaths(tolstoysFolder.FullPath, "WarAndPeace.txt")); using (var dataStream = fileSystem.OpenFileForReading(warAndPeace.FullPath)) { ExceptionAssert.MakeSureExceptionIsRaisedBy <FolderLockedException>( delegate { fileSystem.MoveFolder(literacyFolder.FullPath, VirtualFileSystem.Root); fileSystem.MoveFolder(tolstoysFolder.FullPath, VirtualFileSystem.Root); }); } using (var dataStream = fileSystem.OpenFileForWriting(warAndPeace.FullPath)) { ExceptionAssert.MakeSureExceptionIsRaisedBy <FolderLockedException>( delegate { fileSystem.MoveFolder(literacyFolder.FullPath, VirtualFileSystem.Root); fileSystem.MoveFolder(tolstoysFolder.FullPath, VirtualFileSystem.Root); }); } fileSystem.MoveFolder(literacyFolder.FullPath, VirtualFileSystem.Root); }
public void MakeSureYouCanConstructAnArrayOnlyWithSaneParameters() { byte[] bytes = new byte[4096]; const int numberOfIntegers = 10; ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { new IntegerListConstrained(bytes, -1, numberOfIntegers + 1); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { new IntegerListConstrained(null, 1, 2); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { new IntegerListConstrained(bytes, 0, -4); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { new IntegerListConstrained(bytes, 1234567, 1234567); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { new IntegerListConstrained(bytes, 12, 0); }); }
public void TestJaggedNumberWithThreeDimensionalSystemJaggedForReal() { int[] dimensions = new[] { 512, 512, 2048 }; CompositeIndex number = new CompositeIndex(67045, dimensions); List <int> expectedIndexes = new List <int> { 0, 32, 1509 }; // 0 (из 512) -> 32 (из 512) -> 1509 (из 2048). CollectionAssert.AreEqual(expectedIndexes, number.CompositeValue); Assert.AreEqual(67045, number.Value); number = new CompositeIndex(67045000, dimensions); expectedIndexes = new List <int> { 63, 480, 1672 }; // 63 (из 512) -> 480 (из 512) -> 1672 (из 2048). Assert.AreEqual(67045000, number.Value); CollectionAssert.AreEqual(expectedIndexes, number.CompositeValue); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { new CompositeIndex(int.MaxValue, dimensions); }); }
public void TryRenamingAFile() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); var folder1Node = fileSystem.CreateFolder(@"\folder1"); fileSystem.CreateFile(@"\folder1\file1"); var file2Info = fileSystem.CreateFile(@"\folder1\file2"); fileSystem.CreateFile(@"\folder1\file3"); CollectionAssert.AreEquivalent(new[] { "file1", "file2", "file3" }, fileSystem.GetNamesOfAllFilesFrom(folder1Node.FullPath)); fileSystem.RenameFile(@"\folder1\file1", "file150"); CollectionAssert.AreEquivalent(new[] { "file150", "file2", "file3" }, fileSystem.GetNamesOfAllFilesFrom(folder1Node.FullPath)); ExceptionAssert.MakeSureExceptionIsRaisedBy <FileNotFoundException>( delegate { fileSystem.RenameFile(@"\folder1\" + Guid.NewGuid().ToString("N"), "file150"); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <FileAlreadyExistsException>( delegate { fileSystem.RenameFile(@"\folder1\file150", "file2"); // файл с именем file2 уже есть в той папке. }); }
public void MakeSureYouCannotMoveAFileWhileItIsLocked() { Stream stream; VirtualFileSystem fileSystem = TestCollaboratorsFactory.CreateFileSystem(out stream); var newFile = fileSystem.CreateFile(@"\WarAndPeace.txt"); var newFolder = fileSystem.CreateFolder(@"\Books"); using (var dataStream = fileSystem.OpenFileForReading(newFile.FullPath)) { ExceptionAssert.MakeSureExceptionIsRaisedBy <FileLockedException>( delegate { fileSystem.MoveFile(newFile.FullPath, newFolder.FullPath); }); } using (var dataStream = fileSystem.OpenFileForWriting(newFile.FullPath)) { ExceptionAssert.MakeSureExceptionIsRaisedBy <FileLockedException>( delegate { fileSystem.MoveFile(newFile.FullPath, newFolder.FullPath); }); } fileSystem.MoveFile(newFile.FullPath, newFolder.FullPath); }
public void MakeSureYouCannotOpenFilePassingNullOrEmptyStringAsFilePath() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { fileSystem.OpenFileForReading(null); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { fileSystem.OpenFileForReading(String.Empty); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { fileSystem.OpenFileForWriting(null); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { fileSystem.OpenFileForWriting(String.Empty); }); }
public void MakeSureYouCannotReadTooMuchDataFromDisk() { VirtualDisk virtualDisk = VirtualDiskTestFactory.ConstructDefaultTestDisk(); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate() { virtualDisk.ReadBytesFromBlock(0, 0, virtualDisk.BlockSizeInBytes + 1); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate() { virtualDisk.ReadBytesFromBlock(0, 3, virtualDisk.BlockSizeInBytes - 2); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate() { virtualDisk.ReadBytesFromBlock(0, int.MaxValue, 0); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate() { virtualDisk.ReadBytesFromBlock(0, 0, int.MaxValue); }); }
public void TryRemovingAFileFromFolder() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); var folder1Node = fileSystem.CreateFolder(@"\folder1"); fileSystem.CreateFile(@"\folder1\file1"); var file2Info = fileSystem.CreateFile(@"\folder1\file2"); fileSystem.CreateFile(@"\folder1\file3"); CollectionAssert.AreEquivalent(new[] { "file1", "file2", "file3" }, fileSystem.GetNamesOfAllFilesFrom(folder1Node.FullPath)); fileSystem.DeleteFile(file2Info.FullPath); fileSystem.CreateFile(@"\hey"); fileSystem.CreateFile(@"\heyThere"); fileSystem.CreateFile(@"\GoodMorningIndeed"); ExceptionAssert.MakeSureExceptionIsRaisedBy <FileNotFoundException>( delegate { fileSystem.DeleteFile(VirtualFileSystem.Root + Guid.NewGuid().ToString("N")); }); }
public void MakeSureYouCannotDoAThingWithAFileThatIsLocked() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); FolderInfo folder1Node = fileSystem.CreateFolder(@"\folder1"); FileInfo newFile = fileSystem.CreateFile(@"\folder1\file1"); using (DataStreamReadable dataStream = fileSystem.OpenFileForReading(newFile.FullPath)) { ExceptionAssert.MakeSureExceptionIsRaisedBy <FileLockedException>( delegate { fileSystem.OpenFileForWriting(newFile.FullPath); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <FileLockedException>( delegate { fileSystem.DeleteFile(newFile.FullPath); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <FileLockedException>( delegate { fileSystem.RenameFile(newFile.FullPath, "newFile.txt"); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <FolderLockedException>( delegate { fileSystem.RenameFolder(folder1Node.FullPath, "Untitled"); }); } }
public void MakeSureTheBlockChecksArgumentsBeforeWritingAnything() { var virtualDisk = VirtualDiskTestFactory.ConstructDefaultTestDisk(); DiskBlock block = new DiskBlock(virtualDisk, 10, 0, 0); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { block.WriteBytes(null, 10, 11); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { block.WriteBytes(new byte[2], 10, 11); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { block.WriteBytes(new byte[2], -10, 11); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { block.WriteBytes(new byte[2], 10, -1); }); }
public void MakeSureYouCannotPutNegativeNumbersInTheBlock() { byte[] bytes = new byte[4096]; const int numberOfIntegers = 10; var block = new IntegerListConstrained(bytes, 2, numberOfIntegers + 1); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { block[0] = -1; }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { block.AddInteger(-2); }); MemoryStream stream = new MemoryStream(bytes, true); BinaryWriter writer = new BinaryWriter(stream); writer.Write((int)-56); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { new IntegerListConstrained(bytes, 2, numberOfIntegers + 1); }); }
public void TryRenamingAFolderSeveralTimes() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); fileSystem.CreateFolder(@"\folder1"); fileSystem.CreateFolder(@"\folder2"); fileSystem.CreateFolder(@"\folder3"); CollectionAssert.AreEquivalent(new[] { "folder1", "folder2", "folder3" }, fileSystem.GetAllFoldersFrom(VirtualFileSystem.Root).Select(folder => folder.Name).ToList()); fileSystem.RenameFolder(@"\folder1", "0xFF"); fileSystem.RenameFolder(@"\0xff", "DearJohn,"); var folders = fileSystem.GetAllFoldersFrom(VirtualFileSystem.Root); CollectionAssert.AreEquivalent(new[] { "DearJohn,", "folder2", "folder3" }, folders.Select(folder => folder.Name).ToList()); ExceptionAssert.MakeSureExceptionIsRaisedBy <FolderNotFoundException>( delegate { fileSystem.RenameFolder(@"\folder10", "file150"); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <FolderAlreadyExistsException>( delegate { fileSystem.RenameFolder(@"\folder3", "dearjohn,"); }); }
public void EnsureDistributorThrowsIfFirstBucketIsSaidToContainMoreThanBucketCapacity() { ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { ItemDistributor.Distribute(100, 100000, 1000); }); }
public void MakeSureYouCannotGiveNullAsFileBeingLockedAndGetAwayWithIt() { ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { new FileLockable(null, FakeNodesFactory.CreateFakeFolderNodes(1)); }); }
public void MakeSureYouCannotInitializeAValidatorPassingNullAsListOfIllegalCharacters() { ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { new FileSystemArtifactNamesValidator(null, 255); }); }
public void MakeSureYouCannotConstructAValidatorWithInvalidCharacterAsDirectorySeparator() { ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { new PathValidator("root", new char[] { '1', '2' }, MockRepository.GenerateStub <IFileSystemArtifactNamesValidator>(), '2'); }); }
public void MakeSureYouCanCreateVirtualDiskOnlyOfSizeAlignedWithDiskBlockSize() { MemoryStream testStream = new MemoryStream(); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>(delegate() { VirtualDisk.CreateFormattingTheStream(testStream, 2048, 77777); }); }
public void MakeSureRenamingRootFolderFails() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); ExceptionAssert.MakeSureExceptionIsRaisedBy <InvalidPathException>( delegate { fileSystem.DeleteFolder(VirtualFileSystem.Root); }); }
public void MakeSureYouCannotCopyAFileThatDoesNotExist() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); ExceptionAssert.MakeSureExceptionIsRaisedBy <FileNotFoundException>( delegate { fileSystem.CopyFile(@"\TheGreatGatsbyEncoded.bin", @"\lkfmldgkdmglfklmgldlgm"); }); }
public void MakeSureYouCannotProvideNullAsFileResolvingResultWhenTryingToLock() { var manager = new FileSystemObjectLockingManager(); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { manager.AcquireLock(null, LockKind.Write); }); }
public void MakeSureJaggedNumberThrowsOnBigOrders() { int[] dimensions = new[] { int.MaxValue / 2, 4, 3 }; ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { new CompositeIndex(67045, dimensions); }); }
private static void MakeSureRenamingFoldersFails(VirtualFileSystem fileSystem, IEnumerable <FolderInfo> folders) { foreach (FolderInfo folder in folders) { ExceptionAssert.MakeSureExceptionIsRaisedBy <FolderLockedException>( delegate { fileSystem.RenameFolder(folder.FullPath, "newFolder"); }); } }
public void MakeSureYouCannotCreateVirtualDiskFromGarbage() { MemoryStream testStream = new MemoryStream(); testStream.Write(new byte[2048], 0, 2048); ExceptionAssert.MakeSureExceptionIsRaisedBy <VirtualDiskCreationFailedException>(delegate() { VirtualDisk.CreateFromStream(testStream); }); }
public void MakeSureYouCannotCopyAFileToNonExistingFolder() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); var file1 = fileSystem.CreateFile(@"\file1"); ExceptionAssert.MakeSureExceptionIsRaisedBy <FolderNotFoundException>( delegate { fileSystem.CopyFile(file1.FullPath, @"\A\B\C\ldfmsdkmflsmd"); }); }
public void MakeSureYouCannotAddressIntegeresOutsideOfInitializedSpace() { byte[] bytes = new byte[4096]; IntegerListConstrained integersList = new IntegerListConstrained(bytes, 0, 24); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate() { integersList[1] = 25; }); }
public void MakeSureYouCannotWriteTooMuchDataIntoDiskBlock() { VirtualDisk virtualDisk = VirtualDiskTestFactory.ConstructDefaultTestDisk(); byte[] bytesToWrite = new byte[virtualDisk.BlockSizeInBytes * 2]; ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate() { virtualDisk.WriteBytesToBlock(0, bytesToWrite); }); }