public void MakeSureDeletingAFileFreesSpaceForSure() // был такой баг. { var collaborators = TestCollaboratorsFactory.CreateAllCollaborators(50000, false); VirtualFileSystem fileSystem = collaborators.VirtualFileSystem; int freeSpaceBeforeAnything = fileSystem.FreeSpaceInBytes; byte[] interestingData = ByteBufferFactory.BuildSomeGuidsIntoByteArray(10000); using (var dataStream = fileSystem.CreateAndOpenFileForWriting(@"\hey")) { for (int i = 0; i < 50; i++) { dataStream.Write(interestingData, 0, interestingData.Length); } } fileSystem.DeleteFile(@"\hey"); Assert.AreEqual(freeSpaceBeforeAnything, fileSystem.FreeSpaceInBytes); fileSystem = TestCollaboratorsFactory.CreateFileSystemFromExistingStream(collaborators.Stream); Assert.AreEqual(freeSpaceBeforeAnything, fileSystem.FreeSpaceInBytes); }
public void TryCopyingANonEmptyFileComparingTheContentsOfBothCopiesAfterwards() { VirtualFileSystem fileSystem = VirtualFileSystemFactory.CreateDefaultFileSystem(); byte[] interestingData = ByteBufferFactory.BuildSomeGuidsIntoByteArray(10000); var greatGatsby = fileSystem.CreateFile(@"\TheGreatGatsbyEncoded.bin"); using (var stream = fileSystem.OpenFileForWriting(greatGatsby.FullPath)) { stream.Write(interestingData, 0, interestingData.Length); } var folderInfo = fileSystem.CreateFolder(@"\AifdjgodfjgodfjglidflgjalglkrelgkrelllerlnlrklgnLKGLKREL"); fileSystem.CopyFile(greatGatsby.FullPath, fileSystem.PathBuilder.CombinePaths(folderInfo.FullPath, "HiThereSport.txt")); var interestingDataAsReadFromFile = new byte[interestingData.Length]; using (var stream = fileSystem.OpenFileForReading(fileSystem.PathBuilder.CombinePaths(folderInfo.FullPath, "HiThereSport.txt"))) { stream.Read(interestingDataAsReadFromFile, 0, stream.Length); } CollectionAssert.AreEqual(interestingData, interestingDataAsReadFromFile); }
public void TryWritingABigFileReadingItAfterSystemReload() { var testCollaborators = TestCollaboratorsFactory.CreateAllCollaborators(50000, false); byte[] interestingBytes = ByteBufferFactory.BuildSomeGuidsIntoByteArray(5000); int streamLength; const int numberOfGuidPortionsToReadAndWrite = 500; using (DataStreamReadableWritable stream = testCollaborators.VirtualFileSystem.CreateAndOpenFileForWriting(@"\hey")) { for (int i = 0; i < numberOfGuidPortionsToReadAndWrite; i++) { stream.Write(interestingBytes, 0, interestingBytes.Length); } streamLength = stream.Length; } VirtualFileSystem fileSystemReloaded = TestCollaboratorsFactory.CreateFileSystemFromExistingStream(testCollaborators.Stream); using (DataStreamReadable stream = fileSystemReloaded.OpenFileForReading(@"\hey")) { Assert.AreEqual(streamLength, stream.Length); var bytesRead = new byte[interestingBytes.Length]; for (int i = 0; i < numberOfGuidPortionsToReadAndWrite; i++) { int numberOfBytesRead = stream.Read(bytesRead, 0, interestingBytes.Length); CollectionAssert.AreEqual(interestingBytes, bytesRead); } } }