You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FileInfo.MoveTo() shouldn't throw exceptions when moving a mocked file to itself #181
I'm in the process of binding System.IO.Abstractions into an existing project. One of my tests just started failing, namely one in which a file is moved to itself. It turns out that Microsoft's FileInfo allows a file to move to itself, even though the documentation appears to suggest this is illegal. System.IO.Abstraction's MockFile, however, checks to see if the file exists, and always throws an exception if it does.
I think it's more important to match mscorlib's actual implementation than their documentation; as such, I'd like MockFileInfo.MoveTo() to call CopyTo() with the overwrite flag set to true.
changed the title [-]Should FileInfo.MoveTo() throw exceptions when moving a mocked file to itself?[/-][+]FileInfo.MoveTo() shouldn't throw exceptions when moving a mocked file to itself[/+]on Nov 21, 2016
Another difference between the Mock implementation and mscorlib is that the mock implementation doesn't throw an exception when trying to move or copy a nonexistent file. I'll add that to the PR as well I guess.
Activity
TestableIO#181: MockFileInfo and MockFile no longer throw exceptions …
AlexanderPruss commentedon Nov 21, 2016
#183
[-]Should FileInfo.MoveTo() throw exceptions when moving a mocked file to itself?[/-][+]FileInfo.MoveTo() shouldn't throw exceptions when moving a mocked file to itself[/+]AlexanderPruss commentedon Nov 21, 2016
Another difference between the Mock implementation and mscorlib is that the mock implementation doesn't throw an exception when trying to move or copy a nonexistent file. I'll add that to the PR as well I guess.
TestableIO#181: Moved existence and same target-source check further …
Merge remote-tracking branch 'refs/remotes/origin/TestableIO#181--Mov…
Merge remote-tracking branch 'refs/remotes/origin/TestableIO#181--Mov…
ericnewton76 commentedon Dec 5, 2016
Regarding a file is moved to itself issue, you're 100% correct in that MockFileSystem should mimic mscorlib behavior.
And that's a great catch that the MockSystem wasn't throwing an exception for a file that didnt already exist.
AlexanderPruss commentedon Dec 6, 2016
I'm going through and converting loads of legacy C# IO test code to use this library, so I'm finding lots of edge cases :)
jpreese commentedon Jul 7, 2018
#299 will resolve this.
Correct Exceptions for Moving and Copying Files (#299)