Skip to content

Commit 5ec8dad

Browse files
committed
Switch xplat path strategy to simple slash replacement
1 parent f5007a7 commit 5ec8dad

5 files changed

Lines changed: 51 additions & 84 deletions

File tree

TestHelpers.Tests/MockDirectoryInfoTests.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void MockDirectoryInfo_GetExtension_ShouldReturnEmptyString()
1111
{
1212
// Arrange
1313
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
14-
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.ForWin(@"c:\temp").ForUnix("/temp"));
14+
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp"));
1515

1616
// Act
1717
var result = directoryInfo.Extension;
@@ -25,7 +25,7 @@ public void MockDirectoryInfo_GetExtensionWithTrailingSlash_ShouldReturnEmptyStr
2525
{
2626
// Arrange
2727
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
28-
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.ForWin(@"c:\temp\").ForUnix("/temp/"));
28+
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\"));
2929

3030
// Act
3131
var result = directoryInfo.Extension;
@@ -38,8 +38,8 @@ public static IEnumerable<object[]> MockDirectoryInfo_Exists_Cases
3838
{
3939
get
4040
{
41-
yield return new object[]{ XFS.ForWin(@"c:\temp\folder").ForUnix("/temp/folder"), true };
42-
yield return new object[]{ XFS.ForWin(@"c:\temp\folder\notExistant").ForUnix("/temp/folder/notExistant"), false };
41+
yield return new object[]{ XFS.Path(@"c:\temp\folder"), true };
42+
yield return new object[]{ XFS.Path(@"c:\temp\folder\notExistant"), false };
4343
}
4444
}
4545

@@ -48,7 +48,7 @@ public void MockDirectoryInfo_Exists(string path, bool expected)
4848
{
4949
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
5050
{
51-
{XFS.ForWin(@"c:\temp\folder\file.txt").ForUnix("/temp/folder/file.txt"), new MockFileData("Hello World")}
51+
{XFS.Path(@"c:\temp\folder\file.txt"), new MockFileData("Hello World")}
5252
});
5353
var directoryInfo = new MockDirectoryInfo(fileSystem, path);
5454

@@ -63,27 +63,27 @@ public void MockDirectoryInfo_FullName_ShouldReturnFullNameWithoutIncludingTrail
6363
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
6464
{
6565
{
66-
XFS.ForWin(@"c:\temp\folder\file.txt").ForUnix("/temp/folder/file.txt"),
66+
XFS.Path(@"c:\temp\folder\file.txt"),
6767
new MockFileData("Hello World")
6868
}
6969
});
70-
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.ForWin(@"c:\temp\folder").ForUnix("/temp/folder"));
70+
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\folder"));
7171

7272
var result = directoryInfo.FullName;
7373

74-
Assert.That(result, Is.EqualTo(XFS.ForWin(@"c:\temp\folder").ForUnix("/temp/folder")));
74+
Assert.That(result, Is.EqualTo(XFS.Path(@"c:\temp\folder")));
7575
}
7676

7777
[Test]
7878
public void MockDirectoryInfo_GetFileSystemInfos_ShouldReturnBothDirectoriesAndFiles()
7979
{
8080
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
8181
{
82-
{ XFS.ForWin(@"c:\temp\folder\file.txt").ForUnix("/temp/folder/file.txt"), new MockFileData("Hello World") },
83-
{ XFS.ForWin(@"c:\temp\folder\folder").ForUnix("/temp/folder/folder"), new MockDirectoryData() }
82+
{ XFS.Path(@"c:\temp\folder\file.txt"), new MockFileData("Hello World") },
83+
{ XFS.Path(@"c:\temp\folder\folder"), new MockDirectoryData() }
8484
});
8585

86-
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.ForWin(@"c:\temp\folder").ForUnix("/temp/folder"));
86+
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\folder"));
8787
var result = directoryInfo.GetFileSystemInfos();
8888

8989
Assert.That(result.Length, Is.EqualTo(2));
@@ -94,12 +94,12 @@ public void MockDirectoryInfo_GetFileSystemInfos_ShouldReturnDirectoriesAndNames
9494
{
9595
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
9696
{
97-
{ XFS.ForWin(@"c:\temp\folder\file.txt").ForUnix("/temp/folder/file.txt"), new MockFileData("Hello World") },
98-
{ XFS.ForWin(@"c:\temp\folder\folder").ForUnix("/temp/folder/folder"), new MockDirectoryData() },
99-
{ XFS.ForWin(@"c:\temp\folder\older").ForUnix("/temp/folder/older"), new MockDirectoryData() }
97+
{ XFS.Path(@"c:\temp\folder\file.txt"), new MockFileData("Hello World") },
98+
{ XFS.Path(@"c:\temp\folder\folder"), new MockDirectoryData() },
99+
{ XFS.Path(@"c:\temp\folder\older"), new MockDirectoryData() }
100100
});
101101

102-
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.ForWin(@"c:\temp\folder").ForUnix("/temp/folder"));
102+
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\folder"));
103103
var result = directoryInfo.GetFileSystemInfos("f*");
104104

105105
Assert.That(result.Length, Is.EqualTo(2));
@@ -110,14 +110,14 @@ public void MockDirectoryInfo_GetParent_ShouldReturnDirectoriesAndNamesWithSearc
110110
{
111111
// Arrange
112112
var fileSystem = new MockFileSystem();
113-
fileSystem.AddDirectory(XFS.ForWin(@"c:\a\b\c").ForUnix("/a/b/c"));
114-
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.ForWin(@"c:\a\b\c").ForUnix("/a/b/c"));
113+
fileSystem.AddDirectory(XFS.Path(@"c:\a\b\c"));
114+
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\a\b\c"));
115115

116116
// Act
117117
var result = directoryInfo.Parent;
118118

119119
// Assert
120-
Assert.AreEqual(XFS.ForWin(@"c:\a\b").ForUnix("/a/b"), result.FullName);
120+
Assert.AreEqual(XFS.Path(@"c:\a\b"), result.FullName);
121121
}
122122
}
123123
}

TestHelpers.Tests/MockFileSystemTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void Is_Serializable()
9797
public void MockFileSystem_AddDirectory_ShouldCreateDirectory()
9898
{
9999
// Arrange
100-
const string baseDirectory = @"C:\Test";
100+
string baseDirectory = XFS.Path(@"C:\Test");
101101
var fileSystem = new MockFileSystem();
102102

103103
// Act

TestHelpers.Tests/MockPathTests.cs

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests
55
{
66
public class MockPathTests
77
{
8-
static readonly string TestPath = XFS
9-
.ForWin("C:\\test\\test.bmp")
10-
.ForUnix("/test/test.bmp");
8+
static readonly string TestPath = XFS.Path("C:\\test\\test.bmp");
119

1210
private MockPath SetupMockPath()
1311
{
@@ -24,10 +22,7 @@ public void ChangeExtension_ExtensionNoPeriod_PeriodAdded()
2422
var result = mockPath.ChangeExtension(TestPath, "doc");
2523

2624
//Assert
27-
Assert.AreEqual(XFS
28-
.ForWin("C:\\test\\test.doc")
29-
.ForUnix("/test/test.doc")
30-
, result);
25+
Assert.AreEqual(XFS.Path("C:\\test\\test.doc"), result);
3126
}
3227

3328
[Test]
@@ -37,16 +32,10 @@ public void Combine_SentTwoPaths_Combines()
3732
var mockPath = new MockPath(new MockFileSystem());
3833

3934
//Act
40-
var result = mockPath.Combine(XFS
41-
.ForWin("C:\\test")
42-
.ForUnix("/test")
43-
, "test.bmp");
35+
var result = mockPath.Combine(XFS.Path("C:\\test"), "test.bmp");
4436

4537
//Assert
46-
Assert.AreEqual(XFS
47-
.ForWin("C:\\test\\test.bmp")
48-
.ForUnix("/test/test.bmp")
49-
, result);
38+
Assert.AreEqual(XFS.Path("C:\\test\\test.bmp"), result);
5039
}
5140

5241
[Test]
@@ -59,10 +48,7 @@ public void GetDirectoryName_SentPath_ReturnsDirectory()
5948
var result = mockPath.GetDirectoryName(TestPath);
6049

6150
//Assert
62-
Assert.AreEqual(XFS
63-
.ForWin("C:\\test")
64-
.ForUnix("/test")
65-
, result);
51+
Assert.AreEqual(XFS.Path("C:\\test"), result);
6652
}
6753

6854
[Test]
@@ -121,13 +107,13 @@ public static IEnumerable<string[]> GetFullPath_RelativePaths_Cases
121107
{
122108
get
123109
{
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/") };
110+
yield return new [] { XFS.Path(@"c:\a"), "b", XFS.Path(@"c:\a\b") };
111+
yield return new [] { XFS.Path(@"c:\a\b"), "c", XFS.Path(@"c:\a\b\c") };
112+
yield return new [] { XFS.Path(@"c:\a\b"), XFS.Path(@"c\"), XFS.Path(@"c:\a\b\c\") };
113+
yield return new [] { XFS.Path(@"c:\a\b"), XFS.Path(@"..\c"), XFS.Path(@"c:\a\c") };
114+
yield return new [] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\c\..\"), XFS.Path(@"c:\a\b\") };
115+
yield return new [] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\..\..\..\..\d"), XFS.Path(@"c:\d") };
116+
yield return new [] { XFS.Path(@"c:\a\b\c"), XFS.Path(@"..\..\..\..\..\d\"), XFS.Path(@"c:\d\") };
131117
}
132118
}
133119

@@ -150,11 +136,11 @@ public static IEnumerable<string[]> GetFullPath_RootedPathWithRelativeSegments_C
150136
{
151137
get
152138
{
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") };
139+
yield return new [] { XFS.Path(@"c:\a\b\..\c"), XFS.Path(@"c:\a\c") };
140+
yield return new [] { XFS.Path(@"c:\a\b\.\.\..\.\c"), XFS.Path(@"c:\a\c") };
141+
yield return new [] { XFS.Path(@"c:\a\b\.\c"), XFS.Path(@"c:\a\b\c") };
142+
yield return new [] { XFS.Path(@"c:\a\b\.\.\.\.\c"), XFS.Path(@"c:\a\b\c") };
143+
yield return new [] { XFS.Path(@"c:\a\..\..\c"), XFS.Path(@"c:\c") };
158144
}
159145
}
160146

@@ -176,14 +162,14 @@ public static IEnumerable<string[]> GetFullPath_AbsolutePaths_Cases
176162
{
177163
get
178164
{
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") };
165+
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"/b"), XFS.Path(@"c:\b") };
166+
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"/b\"), XFS.Path(@"c:\b\") };
167+
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"\b"), XFS.Path(@"c:\b") };
168+
yield return new [] { XFS.Path(@"c:\a"), XFS.Path(@"\b\..\c"), XFS.Path(@"c:\c") };
169+
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\b\..\c"), XFS.Path(@"z:\c") };
170+
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c"), XFS.Path(@"\\computer\share\c") };
171+
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c\..\d"), XFS.Path(@"\\computer\share\d") };
172+
yield return new [] { XFS.Path(@"z:\a"), XFS.Path(@"\\computer\share\c\..\..\d"), XFS.Path(@"\\computer\share\d") };
187173
}
188174
}
189175

@@ -210,7 +196,7 @@ public void GetFullPath_InvalidUNCPaths_ShouldThrowArgumentException()
210196
var mockPath = new MockPath(mockFileSystem);
211197

212198
//Act
213-
TestDelegate action = () => mockPath.GetFullPath(XFS.ForWin(@"\\shareZ").ForUnix(@"//shareZ"));
199+
TestDelegate action = () => mockPath.GetFullPath(XFS.Path(@"\\shareZ"));
214200

215201
//Assert
216202
Assert.Throws<ArgumentException>(action);
@@ -280,10 +266,7 @@ public void GetPathRoot_SendInPath_ReturnsRoot()
280266
var result = mockPath.GetPathRoot(TestPath);
281267

282268
//Assert
283-
Assert.AreEqual(XFS
284-
.ForWin("C:\\")
285-
.ForUnix("/")
286-
, result);
269+
Assert.AreEqual(XFS.Path("C:\\"), result);
287270
}
288271

289272
[Test]
@@ -365,4 +348,4 @@ public void IsPathRooted_PathSentIn_DeterminesPathExists()
365348
Assert.AreEqual(true, result);
366349
}
367350
}
368-
}
351+
}

TestHelpers.Tests/TestHelpers.Tests.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>9.0.30729</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
86
<ProjectGuid>{20B02738-952A-40F5-9C10-E2F83013E9FC}</ProjectGuid>
97
<OutputType>Library</OutputType>
108
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -43,7 +41,6 @@
4341
<ErrorReport>prompt</ErrorReport>
4442
<WarningLevel>4</WarningLevel>
4543
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
46-
<SignAssembly>false</SignAssembly>
4744
</PropertyGroup>
4845
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4946
<DebugType>pdbonly</DebugType>
@@ -59,14 +56,13 @@
5956
<AssemblyOriginatorKeyFile>..\StrongName.pfx</AssemblyOriginatorKeyFile>
6057
</PropertyGroup>
6158
<ItemGroup>
62-
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
63-
<SpecificVersion>False</SpecificVersion>
64-
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
65-
</Reference>
6659
<Reference Include="System" />
6760
<Reference Include="System.Core">
6861
<RequiredTargetFramework>3.5</RequiredTargetFramework>
6962
</Reference>
63+
<Reference Include="nunit.framework">
64+
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
65+
</Reference>
7066
</ItemGroup>
7167
<ItemGroup>
7268
<Compile Include="FileSystemTests.cs" />
@@ -79,6 +75,7 @@
7975
<Compile Include="MockFileTests.cs" />
8076
<Compile Include="MockPathTests.cs" />
8177
<Compile Include="Properties\AssemblyInfo.cs" />
78+
<Compile Include="CrossPlatformExtensionsTests.cs" />
8279
</ItemGroup>
8380
<ItemGroup>
8481
<ProjectReference Include="..\System.IO.Abstractions\System.IO.Abstractions.csproj">

TestingHelpers/CrossPlatformExtensions.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@ namespace System.IO.Abstractions.TestingHelpers
55
{
66
public static class XFS
77
{
8-
public static string ForWin(string path)
9-
{
10-
return path;
11-
}
12-
13-
public static string ForUnix(this string path, string unixPath)
14-
{
15-
int p = (int) Environment.OSVersion.Platform;
16-
bool isUnix = (p == 4) || (p == 6) || (p == 128);
17-
18-
return isUnix ? unixPath : path;
19-
}
20-
218
public static string Path(string path, Func<bool> isUnixF = null)
229
{
2310
if (isUnixF == null)

0 commit comments

Comments
 (0)