private void When_increasing_file_size_using_Seek_followed_by_write_it_must_fail() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(512)) .IncludingBinaryFile(path, BufferFactory.Create(32)) .Build(); using (IFileStream stream = fileSystem.File.OpenWrite(path)) { byte[] buffer = BufferFactory.Create(64); stream.Write(buffer, 0, buffer.Length); stream.Seek(1280, SeekOrigin.Begin); // Act // ReSharper disable once AccessToDisposedClosure Action action = () => stream.WriteByte(0x33); // Assert action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk."); AssertFreeSpaceOnDrive(fileSystem, "C:", 448); } AssertFileSize(fileSystem, path, 64); }
private void When_creating_local_file_it_must_succeed() { // Arrange const string path = @"C:\some\file.txt"; DateTime creationTimeUtc = 9.September(2016); var clock = new SystemClock { UtcNow = () => creationTimeUtc }; IFileSystem fileSystem = new FakeFileSystemBuilder(clock) .IncludingDirectory(@"C:\some") .Build(); // Act using (IFileStream stream = fileSystem.File.Create(path)) { stream.WriteByte(0xFF); } // Assert IFileInfo info = fileSystem.ConstructFileInfo(path); info.Exists.Should().BeTrue(); info.CreationTimeUtc.Should().Be(creationTimeUtc); info.LastAccessTimeUtc.Should().Be(creationTimeUtc); info.LastWriteTimeUtc.Should().Be(creationTimeUtc); info.Attributes.Should().Be(FileAttributes.Archive); }
private void When_creating_local_file_it_must_succeed() { // Arrange const string path = @"C:\some\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingDirectory(@"C:\some") .Build(); // Act using (IFileStream stream = fileSystem.File.Create(path)) { stream.WriteByte(0xFF); } // Assert IFileInfo info = fileSystem.ConstructFileInfo(path); info.Exists.Should().BeTrue(); info.Attributes.Should().Be(FileAttributes.Archive); }
private void When_writing_to_existing_file_it_must_update_properties_only_after_closing() { // Arrange const string path = @"C:\file.txt"; DateTime createTimeUtc = 2.January(2017).At(22, 14); var clock = new SystemClock { UtcNow = () => createTimeUtc }; IFileSystem fileSystem = new FakeFileSystemBuilder(clock) .IncludingEmptyFile(path) .Build(); IFileInfo fileInfo = fileSystem.ConstructFileInfo(path); DateTime writeTimeUtc = 3.January(2017).At(23, 11); // Act using (IFileStream stream = fileSystem.File.Open(path, FileMode.Open)) { clock.UtcNow = () => writeTimeUtc; stream.WriteByte(0x20); // Assert fileSystem.File.GetCreationTimeUtc(path).Should().Be(createTimeUtc); fileSystem.File.GetLastWriteTimeUtc(path).Should().Be(createTimeUtc); fileSystem.File.GetLastAccessTimeUtc(path).Should().Be(createTimeUtc); fileInfo.Length.Should().Be(0); } fileSystem.File.GetCreationTimeUtc(path).Should().Be(createTimeUtc); fileSystem.File.GetLastWriteTimeUtc(path).Should().Be(writeTimeUtc); fileSystem.File.GetLastAccessTimeUtc(path).Should().Be(writeTimeUtc); fileInfo.Refresh(); fileInfo.Length.Should().Be(1); }
private void When_opening_existing_local_file_in_Truncate_mode_it_must_succeed() { // Arrange const string path = @"C:\some\file.txt"; DateTime creationTimeUtc = 9.September(2016); var clock = new SystemClock { UtcNow = () => creationTimeUtc }; IFileSystem fileSystem = new FakeFileSystemBuilder(clock) .IncludingTextFile(path, DefaultContents) .Build(); DateTime lastWriteTimeUtc = 12.September(2016); clock.UtcNow = () => lastWriteTimeUtc; // Act using (IFileStream stream = fileSystem.File.Open(path, FileMode.Truncate)) { stream.WriteByte(0x20); } // Assert IFileInfo info = fileSystem.ConstructFileInfo(path); info.Exists.Should().BeTrue(); info.Length.Should().Be(1); info.CreationTimeUtc.Should().Be(creationTimeUtc); info.LastAccessTimeUtc.Should().Be(lastWriteTimeUtc); info.LastWriteTimeUtc.Should().Be(lastWriteTimeUtc); fileSystem.File.ReadAllText(path).Should().Be(" "); }
private void When_increasing_file_size_using_Position_followed_by_write_it_must_succeed() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(path, BufferFactory.Create(1024)) .Build(); using (IFileStream stream = fileSystem.File.OpenWrite(path)) { // Act stream.Position = 1280; stream.WriteByte(0x33); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(2815); } }
private void When_opening_existing_local_file_in_Truncate_mode_it_must_succeed() { // Arrange const string path = @"C:\some\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingTextFile(path, DefaultContents) .Build(); // Act using (IFileStream stream = fileSystem.File.Open(path, FileMode.Truncate)) { stream.WriteByte(0x20); } // Assert IFileInfo info = fileSystem.ConstructFileInfo(path); info.Exists.Should().BeTrue(); info.Length.Should().Be(1); fileSystem.File.ReadAllText(path).Should().Be(" "); }