Skip to content

FileInfo.MoveTo() shouldn't throw exceptions when moving a mocked file to itself #181

Closed

Description

@AlexanderPruss

See the discussion here: http://stackoverflow.com/questions/40722205/should-mscorlibs-fileinfo-moveto-throw-an-exception-if-trying-to-move-a-file

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.

Activity

  1. added a commit that references this issue on Nov 21, 2016
  2. AlexanderPruss commented on Nov 21, 2016

    @AlexanderPruss
    Author
  3. 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
  4. AlexanderPruss commented on Nov 21, 2016

    @AlexanderPruss
    Author

    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.

  5. ericnewton76 commented on Dec 5, 2016

    @ericnewton76
    Contributor

    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.

  6. AlexanderPruss commented on Dec 6, 2016

    @AlexanderPruss
    Author

    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 :)

  7. jpreese commented on Jul 7, 2018

    @jpreese
    Member

    #299 will resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions