Skip to content

Commit

Permalink
Fix MockFileInfo reset own path on MoveTo to match functionality for …
Browse files Browse the repository at this point in the history
…FileInfo with Windows filesystem (not sure whether this reflects functionality for Unix/Linux filesystem).
  • Loading branch information
ghendley committed Oct 13, 2016
1 parent a0c4771 commit cc35e09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions TestHelpers.Tests/MockFileInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,23 @@ public void MockFileInfo_OpenText_ShouldReturnStringContentOfFile()

Assert.AreEqual(@"line 1\r\nline 2", result);
}

[Test]
public void MockFileInfo_MoveTo_ShouldUpdateFileInfoDirectoryAndFullName()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(XFS.Path(@"c:\temp\file.txt"), new MockFileData(@"line 1\r\nline 2"));
var fileInfo = fileSystem.FileInfo.FromFileName(XFS.Path(@"c:\temp\file.txt"));

// Act
string destinationFolder = XFS.Path(@"c:\temp2");
string destination = XFS.Path(destinationFolder + @"\file.txt");
fileSystem.AddDirectory(destination);
fileInfo.MoveTo(destination);

Assert.AreEqual(fileInfo.DirectoryName, destinationFolder);
Assert.AreEqual(fileInfo.FullName, destination);
}
}
}
5 changes: 3 additions & 2 deletions TestingHelpers/MockFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace System.IO.Abstractions.TestingHelpers
public class MockFileInfo : FileInfoBase
{
private readonly IMockFileDataAccessor mockFileSystem;
private readonly string path;
private string path;

public MockFileInfo(IMockFileDataAccessor mockFileSystem, string path)
{
Expand Down Expand Up @@ -209,8 +209,9 @@ public override FileSecurity GetAccessControl(AccessControlSections includeSecti

public override void MoveTo(string destFileName)
{
CopyTo(destFileName);
var movedFileInfo = CopyTo(destFileName);
Delete();
path = movedFileInfo.FullName;
}

public override Stream Open(FileMode mode)
Expand Down

0 comments on commit cc35e09

Please sign in to comment.