11using NUnit . Framework ;
2+ using System . Collections . Generic ;
23
34namespace System . IO . Abstractions . TestingHelpers . Tests
45{
56 public class MockPathTests
67 {
7- const string TestPath = "C:\\ test\\ test.bmp" ;
8+ static readonly string TestPath = XFS
9+ . ForWin ( "C:\\ test\\ test.bmp" )
10+ . ForUnix ( "/test/test.bmp" ) ;
811
912 private MockPath SetupMockPath ( )
1013 {
@@ -21,7 +24,10 @@ public void ChangeExtension_ExtensionNoPeriod_PeriodAdded()
2124 var result = mockPath . ChangeExtension ( TestPath , "doc" ) ;
2225
2326 //Assert
24- Assert . AreEqual ( "C:\\ test\\ test.doc" , result ) ;
27+ Assert . AreEqual ( XFS
28+ . ForWin ( "C:\\ test\\ test.doc" )
29+ . ForUnix ( "/test/test.doc" )
30+ , result ) ;
2531 }
2632
2733 [ Test ]
@@ -31,10 +37,16 @@ public void Combine_SentTwoPaths_Combines()
3137 var mockPath = new MockPath ( new MockFileSystem ( ) ) ;
3238
3339 //Act
34- var result = mockPath . Combine ( "C:\\ test" , "test.bmp" ) ;
40+ var result = mockPath . Combine ( XFS
41+ . ForWin ( "C:\\ test" )
42+ . ForUnix ( "/test" )
43+ , "test.bmp" ) ;
3544
3645 //Assert
37- Assert . AreEqual ( "C:\\ test\\ test.bmp" , result ) ;
46+ Assert . AreEqual ( XFS
47+ . ForWin ( "C:\\ test\\ test.bmp" )
48+ . ForUnix ( "/test/test.bmp" )
49+ , result ) ;
3850 }
3951
4052 [ Test ]
@@ -47,7 +59,10 @@ public void GetDirectoryName_SentPath_ReturnsDirectory()
4759 var result = mockPath . GetDirectoryName ( TestPath ) ;
4860
4961 //Assert
50- Assert . AreEqual ( "C:\\ test" , result ) ;
62+ Assert . AreEqual ( XFS
63+ . ForWin ( "C:\\ test" )
64+ . ForUnix ( "/test" )
65+ , result ) ;
5166 }
5267
5368 [ Test ]
@@ -102,14 +117,21 @@ public void GetFullPath_SendInPath_ReturnsFullPath()
102117 Assert . AreEqual ( TestPath , result ) ;
103118 }
104119
105- [ TestCase ( @"c:\a" , @"b" , @"c:\a\b" ) ]
106- [ TestCase ( @"c:\a\b" , @"c" , @"c:\a\b\c" ) ]
107- [ TestCase ( @"c:\a\b" , @"c\" , @"c:\a\b\c\" ) ]
108- [ TestCase ( @"c:\a\b" , @".\c\" , @"c:\a\b\c\" ) ]
109- [ TestCase ( @"c:\a\b" , @"..\c" , @"c:\a\c" ) ]
110- [ TestCase ( @"c:\a\b\c" , @"..\c\..\" , @"c:\a\b\" ) ]
111- [ TestCase ( @"c:\a\b\c" , @"..\..\..\..\..\d" , @"c:\d" ) ]
112- [ TestCase ( @"c:\a\b\c\" , @"..\..\..\..\..\d\" , @"c:\d\" ) ]
120+ public static IEnumerable < string [ ] > GetFullPath_RelativePaths_Cases
121+ {
122+ get
123+ {
124+ yield return new [ ] { XFS . ForWin ( @"c:\a" ) . ForUnix ( "/a" ) , "b" , XFS . ForWin ( @"c:\a\b" ) . ForUnix ( "/a/b" ) } ;
125+ yield return new [ ] { XFS . ForWin ( @"c:\a\b" ) . ForUnix ( "/a/b" ) , "c" , XFS . ForWin ( @"c:\a\b\c" ) . ForUnix ( "/a/b/c" ) } ;
126+ yield return new [ ] { XFS . ForWin ( @"c:\a\b" ) . ForUnix ( "/a/b" ) , XFS . ForWin ( @"c\" ) . ForUnix ( "c/" ) , XFS . ForWin ( @"c:\a\b\c\" ) . ForUnix ( "/a/b/c/" ) } ;
127+ yield return new [ ] { XFS . ForWin ( @"c:\a\b" ) . ForUnix ( "/a/b" ) , XFS . ForWin ( @"..\c" ) . ForUnix ( "../c" ) , XFS . ForWin ( @"c:\a\c" ) . ForUnix ( "/a/c" ) } ;
128+ yield return new [ ] { XFS . ForWin ( @"c:\a\b\c" ) . ForUnix ( "/a/b/c" ) , XFS . ForWin ( @"..\c\..\" ) . ForUnix ( "../c/../" ) , XFS . ForWin ( @"c:\a\b\" ) . ForUnix ( "/a/b/" ) } ;
129+ yield return new [ ] { XFS . ForWin ( @"c:\a\b\c" ) . ForUnix ( "/a/b/c" ) , XFS . ForWin ( @"..\..\..\..\..\d" ) . ForUnix ( "../../../../../d" ) , XFS . ForWin ( @"c:\d" ) . ForUnix ( "/d" ) } ;
130+ yield return new [ ] { XFS . ForWin ( @"c:\a\b\c" ) . ForUnix ( "/a/b/c" ) , XFS . ForWin ( @"..\..\..\..\..\d\" ) . ForUnix ( "../../../../../d/" ) , XFS . ForWin ( @"c:\d\" ) . ForUnix ( "/d/" ) } ;
131+ }
132+ }
133+
134+ [ TestCaseSource ( "GetFullPath_RelativePaths_Cases" ) ]
113135 public void GetFullPath_RelativePaths_ShouldReturnTheAbsolutePathWithCurrentDirectory ( string currentDir , string relativePath , string expectedResult )
114136 {
115137 //Arrange
@@ -124,11 +146,19 @@ public void GetFullPath_RelativePaths_ShouldReturnTheAbsolutePathWithCurrentDire
124146 Assert . AreEqual ( expectedResult , actualResult ) ;
125147 }
126148
127- [ TestCase ( @"c:\a\b\..\c" , @"c:\a\c" ) ]
128- [ TestCase ( @"c:\a\b\.\.\..\.\c" , @"c:\a\c" ) ]
129- [ TestCase ( @"c:\a\b\.\c" , @"c:\a\b\c" ) ]
130- [ TestCase ( @"c:\a\b\.\.\.\.\c" , @"c:\a\b\c" ) ]
131- [ TestCase ( @"c:\a\..\..\c" , @"c:\c" ) ]
149+ public static IEnumerable < string [ ] > GetFullPath_RootedPathWithRelativeSegments_Cases
150+ {
151+ get
152+ {
153+ yield return new [ ] { XFS . ForWin ( @"c:\a\b\..\c" ) . ForUnix ( "/a/b/../c" ) , XFS . ForWin ( @"c:\a\c" ) . ForUnix ( "/a/c" ) } ;
154+ yield return new [ ] { XFS . ForWin ( @"c:\a\b\.\.\..\.\c" ) . ForUnix ( "/a/b/././.././c" ) , XFS . ForWin ( @"c:\a\c" ) . ForUnix ( "/a/c" ) } ;
155+ yield return new [ ] { XFS . ForWin ( @"c:\a\b\.\c" ) . ForUnix ( "/a/b/./c" ) , XFS . ForWin ( @"c:\a\b\c" ) . ForUnix ( "/a/b/c" ) } ;
156+ yield return new [ ] { XFS . ForWin ( @"c:\a\b\.\.\.\.\c" ) . ForUnix ( "/a/b/././././c" ) , XFS . ForWin ( @"c:\a\b\c" ) . ForUnix ( "/a/b/c" ) } ;
157+ yield return new [ ] { XFS . ForWin ( @"c:\a\..\..\c" ) . ForUnix ( "/a/../../c" ) , XFS . ForWin ( @"c:\c" ) . ForUnix ( "/c" ) } ;
158+ }
159+ }
160+
161+ [ TestCaseSource ( "GetFullPath_RootedPathWithRelativeSegments_Cases" ) ]
132162 public void GetFullPath_RootedPathWithRelativeSegments_ShouldReturnAnRootedAbsolutePath ( string rootedPath , string expectedResult )
133163 {
134164 //Arrange
@@ -142,15 +172,22 @@ public void GetFullPath_RootedPathWithRelativeSegments_ShouldReturnAnRootedAbsol
142172 Assert . AreEqual ( expectedResult , actualResult ) ;
143173 }
144174
145- [ TestCase ( @"c:\a" , @"/b" , @"c:\b" ) ]
146- [ TestCase ( @"c:\a" , @"/b\" , @"c:\b\" ) ]
147- [ TestCase ( @"c:\a" , @"\b" , @"c:\b" ) ]
148- [ TestCase ( @"c:\a" , @"\b\..\c" , @"c:\c" ) ]
149- [ TestCase ( @"z:\a" , @"\b\..\c" , @"z:\c" ) ]
150- [ TestCase ( @"z:\a" , @"\b\..\c" , @"z:\c" ) ]
151- [ TestCase ( @"z:\a" , @"\\computer\share\c" , @"\\computer\share\c" ) ]
152- [ TestCase ( @"z:\a" , @"\\computer\share\c\..\d" , @"\\computer\share\d" ) ]
153- [ TestCase ( @"z:\a" , @"\\computer\share\c\..\..\d" , @"\\computer\share\d" ) ]
175+ public static IEnumerable < string [ ] > GetFullPath_AbsolutePaths_Cases
176+ {
177+ get
178+ {
179+ yield return new [ ] { XFS . ForWin ( @"c:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"/b" ) . ForUnix ( @"/b" ) , XFS . ForWin ( @"c:\b" ) . ForUnix ( "/b" ) } ;
180+ yield return new [ ] { XFS . ForWin ( @"c:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"/b\" ) . ForUnix ( @"/b/" ) , XFS . ForWin ( @"c:\b\" ) . ForUnix ( "/b/" ) } ;
181+ yield return new [ ] { XFS . ForWin ( @"c:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"\b" ) . ForUnix ( @"/b" ) , XFS . ForWin ( @"c:\b" ) . ForUnix ( "/b" ) } ;
182+ yield return new [ ] { XFS . ForWin ( @"c:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"\b\..c" ) . ForUnix ( @"/b/../c" ) , XFS . ForWin ( @"c:\c" ) . ForUnix ( "/c" ) } ;
183+ yield return new [ ] { XFS . ForWin ( @"z:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"\b\..c" ) . ForUnix ( @"/b/../c" ) , XFS . ForWin ( @"z:\c" ) . ForUnix ( "/c" ) } ;
184+ yield return new [ ] { XFS . ForWin ( @"z:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"\\computer\share\c" ) . ForUnix ( @"//computer/share/c" ) , XFS . ForWin ( @"\\computer\share\c" ) . ForUnix ( "//computer/share/c" ) } ;
185+ yield return new [ ] { XFS . ForWin ( @"z:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"\\computer\share\c\..\d" ) . ForUnix ( @"//computer/share/c/../d" ) , XFS . ForWin ( @"\\computer\share\d" ) . ForUnix ( "//computer/share/d" ) } ;
186+ yield return new [ ] { XFS . ForWin ( @"z:\a" ) . ForUnix ( "/a" ) , XFS . ForWin ( @"\\computer\share\c\..\..\d" ) . ForUnix ( @"//computer/share/c/../../d" ) , XFS . ForWin ( @"\\computer\share\d" ) . ForUnix ( "//computer/share/d" ) } ;
187+ }
188+ }
189+
190+ [ TestCaseSource ( "GetFullPath_AbsolutePaths_Cases" ) ]
154191 public void GetFullPath_AbsolutePaths_ShouldReturnThePathWithTheRoot_Or_Unc ( string currentDir , string absolutePath , string expectedResult )
155192 {
156193 //Arrange
@@ -173,7 +210,7 @@ public void GetFullPath_InvalidUNCPaths_ShouldThrowArgumentException()
173210 var mockPath = new MockPath ( mockFileSystem ) ;
174211
175212 //Act
176- TestDelegate action = ( ) => mockPath . GetFullPath ( @"\\shareZ" ) ;
213+ TestDelegate action = ( ) => mockPath . GetFullPath ( XFS . ForWin ( @"\\shareZ" ) . ForUnix ( @"//shareZ" ) ) ;
177214
178215 //Assert
179216 Assert . Throws < ArgumentException > ( action ) ;
@@ -243,7 +280,10 @@ public void GetPathRoot_SendInPath_ReturnsRoot()
243280 var result = mockPath . GetPathRoot ( TestPath ) ;
244281
245282 //Assert
246- Assert . AreEqual ( "C:\\ " , result ) ;
283+ Assert . AreEqual ( XFS
284+ . ForWin ( "C:\\ " )
285+ . ForUnix ( "/" )
286+ , result ) ;
247287 }
248288
249289 [ Test ]
0 commit comments