private void When_copying_file_overwriting_existing_file_it_must_allocate_initial_size() { // Arrange const string sourcePath = @"c:\file.txt"; const string destinationPath = @"c:\copy.txt"; var copyWaitIndicator = new WaitIndicator(); IFileSystem fileSystem = new FakeFileSystemBuilder() .WithCopyWaitIndicator(copyWaitIndicator) .IncludingTextFile(sourcePath, "ABCDE") .IncludingEmptyFile(destinationPath) .Build(); // Act var copyThread = new Thread(() => { fileSystem.File.Copy(sourcePath, destinationPath, true); }); copyThread.Start(); copyWaitIndicator.WaitForStart(); try { // Assert IFileInfo destinationInfo = fileSystem.ConstructFileInfo(destinationPath); destinationInfo.Exists.Should().BeTrue(); destinationInfo.Length.Should().Be(5); } finally { copyWaitIndicator.SetCompleted(); copyThread.Join(); } }
private void When_copying_file_to_overwrite_it_must_allocate_initial_size_and_update_timings() { // Arrange const string sourcePath = @"c:\file.txt"; const string destinationPath = @"c:\copy.txt"; var copyWaitIndicator = new WaitIndicator(); DateTime creationTimeUtc = 4.January(2017).At(7, 52, 01); var clock = new SystemClock { UtcNow = () => creationTimeUtc }; IFileSystem fileSystem = new FakeFileSystemBuilder(clock) .WithCopyWaitIndicator(copyWaitIndicator) .IncludingEmptyFile(sourcePath) .IncludingEmptyFile(destinationPath) .Build(); DateTime sourceLastWriteTimeUtc = 10.January(2017).At(3, 12, 34); clock.UtcNow = () => sourceLastWriteTimeUtc; fileSystem.File.WriteAllText(sourcePath, "ABCDE"); DateTime destinationLastWriteTimeUtc = 12.January(2017).At(11, 23, 45); clock.UtcNow = () => destinationLastWriteTimeUtc; // Act var copyThread = new Thread(() => { fileSystem.File.Copy(sourcePath, destinationPath, true); }); copyThread.Start(); copyWaitIndicator.WaitForStart(); try { // Assert IFileInfo destinationInfo = fileSystem.ConstructFileInfo(destinationPath); destinationInfo.Exists.Should().BeTrue(); destinationInfo.Length.Should().Be(5); destinationInfo.CreationTimeUtc.Should().Be(creationTimeUtc); destinationInfo.LastAccessTimeUtc.Should().Be(destinationLastWriteTimeUtc); destinationInfo.LastWriteTimeUtc.Should().Be(sourceLastWriteTimeUtc); DateTime destinationCompletedTimeUtc = 10.January(2017).At(11, 27, 36); clock.UtcNow = () => destinationCompletedTimeUtc; copyWaitIndicator.SetCompleted(); copyThread.Join(); destinationInfo.Refresh(); destinationInfo.CreationTimeUtc.Should().Be(creationTimeUtc); destinationInfo.LastAccessTimeUtc.Should().Be(destinationCompletedTimeUtc); destinationInfo.LastWriteTimeUtc.Should().Be(sourceLastWriteTimeUtc); IFileInfo sourceInfo = fileSystem.ConstructFileInfo(sourcePath); sourceInfo.CreationTimeUtc.Should().Be(creationTimeUtc); sourceInfo.LastAccessTimeUtc.Should().Be(destinationCompletedTimeUtc); sourceInfo.LastWriteTimeUtc.Should().Be(sourceLastWriteTimeUtc); } finally { copyWaitIndicator.SetCompleted(); copyThread.Join(); } }
private void When_copying_file_overwriting_existing_file_it_must_update_file_timings() { // Arrange const string sourcePath = @"c:\file.txt"; const string destinationPath = @"c:\copy.txt"; var copyWaitIndicator = new WaitIndicator(); DateTime creationTimeUtc = 4.January(2017).At(7, 52, 01).AsUtc(); var clock = new SystemClock(() => creationTimeUtc); IFileSystem fileSystem = new FakeFileSystemBuilder(clock) .WithCopyWaitIndicator(copyWaitIndicator) .IncludingEmptyFile(sourcePath) .IncludingEmptyFile(destinationPath) .Build(); DateTime sourceLastWriteTimeUtc = 10.January(2017).At(3, 12, 34).AsUtc(); clock.UtcNow = () => sourceLastWriteTimeUtc; fileSystem.File.WriteAllText(sourcePath, DefaultContents); DateTime destinationLastWriteTimeUtc = 12.January(2017).At(11, 23, 45).AsUtc(); clock.UtcNow = () => destinationLastWriteTimeUtc; fileSystem.File.WriteAllText(destinationPath, DefaultContents); DateTime copyStartTimeUtc = 14.January(2017).At(11, 23, 45).AsUtc(); clock.UtcNow = () => copyStartTimeUtc; // Act var copyThread = new Thread(() => { fileSystem.File.Copy(sourcePath, destinationPath, true); }); copyThread.Start(); copyWaitIndicator.WaitForStart(); try { // Assert (copy started) fileSystem.File.GetCreationTimeUtc(destinationPath).Should().Be(creationTimeUtc); fileSystem.File.GetLastWriteTimeUtc(destinationPath).Should().Be(copyStartTimeUtc); fileSystem.File.GetLastAccessTimeUtc(destinationPath).Should().Be(copyStartTimeUtc); DateTime copyFinishTimeUtc = 12.January(2017).At(11, 27, 36).AsUtc(); clock.UtcNow = () => copyFinishTimeUtc; copyWaitIndicator.SetCompleted(); copyThread.Join(); // Assert (copy completed) fileSystem.File.GetCreationTimeUtc(destinationPath).Should().Be(creationTimeUtc); fileSystem.File.GetLastWriteTimeUtc(destinationPath).Should().Be(destinationLastWriteTimeUtc); fileSystem.File.GetLastAccessTimeUtc(destinationPath).Should().Be(copyFinishTimeUtc); fileSystem.File.GetCreationTimeUtc(sourcePath).Should().Be(creationTimeUtc); fileSystem.File.GetLastWriteTimeUtc(sourcePath).Should().Be(sourceLastWriteTimeUtc); fileSystem.File.GetLastAccessTimeUtc(sourcePath).Should().Be(copyFinishTimeUtc); } finally { copyWaitIndicator.SetCompleted(); copyThread.Join(); } }