Skip to content

IFileInfo.ToString() should have same result as FileInfo.ToString() #553

@iouris

Description

@iouris

Hi Guys,

Following unit test

        [Fact]
        public void FileInfoToStringShouldResultInFilePathProvidedInConstructor()
        {
            var fileSystem = new FileSystem();
            var fileInfo = fileSystem.FileInfo.FromFileName(@"c:folder-a\file-a.txt");
            fileInfo.ToString().Should().Be(@"c:folder-a\file-a.txt");
        }

fails with:

Message:
Expected fileInfo.ToString() to be
"c:folder-a\file-a.txt" with a length of 21, but
"System.IO.Abstractions.FileInfoWrapper" has a length of 38, differs near "Sys" (index 0).
Stack Trace:
XUnit2TestFramework.Throw(String message)
TestFrameworkProvider.Throw(String message)
DefaultAssertionStrategy.HandleFailure(String message)
AssertionScope.FailWith(Func1 failReasonFunc) AssertionScope.FailWith(Func1 failReasonFunc)
StringEqualityValidator.ValidateAgainstLengthDifferences()
StringValidator.Validate()
StringAssertions.Be(String expected, String because, Object[] becauseArgs)
FileInfoExtensionsTests.FileInfoToStringShouldResultInFilePathProvidedInConstructor() line 47

What makes it worse is that the following behaves correctly and therefore produces false positive:

        [Fact]
        public void MockFileInfoToStringShouldResultInFilePathProvidedInConstructor()
        {
            var fileSystem = new MockFileSystem();
            var fileInfo = fileSystem.FileInfo.FromFileName(@"c:folder-a\file-a.txt");
            fileInfo.ToString().Should().Be(@"c:folder-a\file-a.txt");
        }

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues that address the core abstractions & the wrappersstate: 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