Skip to content

MockFile.Move does not preserve file metadata when moving a file #557

@tullo-x86

Description

@tullo-x86

MockFile.Move does not preserve file metadata when moving a file — instead, it simply creates a file with the same content in a new location, discarding file metadata such as created/modified timestamp.

Expected: A moved file's modification date is preserved
Actual: A moved file's modification date is always set to 2010-01-04 00:00:00 +0400

Repro

using System;
using System.IO.Abstractions.TestingHelpers;
using Xunit;

namespace Bug
{
	public class Repro
	{
		[Fact]
		public void WhenMovingFile_ShouldCopyMetadata()
		{
			// Arrange
			MockFileSystem sut = new MockFileSystem();

			DateTime writeTime = new DateTime(2020, 01, 01);
			sut.AddFile("file1.txt", new MockFileData("Test file contents") { LastWriteTime = writeTime });

			// Act
			sut.File.Move("file1.txt", "file2.txt");

			// Assert
			var destInfo = sut.FileInfo.FromFileName("file2.txt");
			Assert.Equal(writeTime, destInfo.LastWriteTime);
		}
	}
}
Output
Bug.Repro.WhenMovingFile_ShouldCopyMetadata

Assert.Equal() Failure
Expected: 2020-01-01T00:00:00.0000000
Actual:   2010-01-04T00:00:00.0000000
   at Bug.Repro.WhenMovingFile_ShouldCopyMetadata() in C:\Dev\MockFileSystemBug\Repro.cs:line 23

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked ontype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions