File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
System.IO.Abstractions.TestingHelpers.Tests
System.IO.Abstractions.TestingHelpers Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -536,6 +536,35 @@ public void MockFileInfo_ToString_ShouldReturnOriginalFilePath(string path)
536536 Assert . AreEqual ( filePath , mockFileInfo . ToString ( ) ) ;
537537 }
538538
539+
540+ /// <summary>
541+ /// Normalize, tested with Path.GetFullPath and new FileInfo().FullName;
542+ /// </summary>
543+ [ TestCaseSource ( nameof ( FromFileName_Paths_NormalizePaths_Cases ) ) ]
544+ public void FromFileName_Paths_NormalizePaths ( string input , string expected )
545+ {
546+ // Arrange
547+ var mockFs = new MockFileSystem ( ) ;
548+
549+ // Act
550+ var mockFileInfo = mockFs . FileInfo . FromFileName ( input ) ;
551+ var result = mockFileInfo . FullName ;
552+
553+ // Assert
554+ Assert . AreEqual ( expected , result ) ;
555+ }
556+
557+ public static IEnumerable < string [ ] > FromFileName_Paths_NormalizePaths_Cases
558+ {
559+ get
560+ {
561+ yield return new [ ] { XFS . Path ( @"c:\top\..\most\file" ) , XFS . Path ( @"c:\most\file" ) } ;
562+ yield return new [ ] { XFS . Path ( @"c:\top\..\most\..\dir\file" ) , XFS . Path ( @"c:\dir\file" ) } ;
563+ yield return new [ ] { XFS . Path ( @"\file" ) , XFS . Path ( @"C:\file" ) } ;
564+ yield return new [ ] { XFS . Path ( @"c:\top\../..\most\file" ) , XFS . Path ( @"c:\most\file" ) } ;
565+ }
566+ }
567+
539568#if NET40
540569 [ Test ]
541570 public void MockFileInfo_Replace_ShouldReplaceFileContents ( )
Original file line number Diff line number Diff line change @@ -7,11 +7,14 @@ public class MockFileInfo : FileInfoBase
77 {
88 private readonly IMockFileDataAccessor mockFileSystem ;
99 private string path ;
10+ private string originalPath ;
1011
1112 public MockFileInfo ( IMockFileDataAccessor mockFileSystem , string path ) : base ( mockFileSystem ? . FileSystem )
1213 {
1314 this . mockFileSystem = mockFileSystem ?? throw new ArgumentNullException ( nameof ( mockFileSystem ) ) ;
14- this . path = path ?? throw new ArgumentNullException ( nameof ( path ) ) ;
15+ this . originalPath = path ?? throw new ArgumentNullException ( nameof ( path ) ) ;
16+ this . path = mockFileSystem . Path . GetFullPath ( path ) ;
17+
1518 }
1619
1720 MockFileData MockFileData
@@ -314,7 +317,7 @@ public override long Length
314317
315318 public override string ToString ( )
316319 {
317- return path ;
320+ return originalPath ;
318321 }
319322 }
320323}
You can’t perform that action at this time.
0 commit comments