Skip to content

Commit 05e82b1

Browse files
committed
Added tests for remote path transformations.
Added tests for PosixPath.
1 parent f4b0bb2 commit 05e82b1

11 files changed

+2469
-26
lines changed

src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@
971971
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
972972
<ProjectExtensions>
973973
<VisualStudio>
974-
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
974+
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
975975
</VisualStudio>
976976
</ProjectExtensions>
977977
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@
327327
<Compile Include="..\Renci.SshNet.Tests\Classes\Common\PortForwardEventArgsTest.cs">
328328
<Link>Classes\Common\PortForwardEventArgsTest.cs</Link>
329329
</Compile>
330+
<Compile Include="..\Renci.SshNet.Tests\Classes\Common\PosixPathTest_GetFileName.cs">
331+
<Link>Classes\Common\PosixPathTest_GetFileName.cs</Link>
332+
</Compile>
330333
<Compile Include="..\Renci.SshNet.Tests\Classes\Common\ProxyExceptionTest.cs">
331334
<Link>Classes\Common\ProxyExceptionTest.cs</Link>
332335
</Compile>
@@ -765,6 +768,12 @@
765768
<Compile Include="..\Renci.SshNet.Tests\Classes\PrivateKeyFileTest.cs">
766769
<Link>Classes\PrivateKeyFileTest.cs</Link>
767770
</Compile>
771+
<Compile Include="..\Renci.SshNet.Tests\Classes\RemotePathDoubleQuoteTransformationTest.cs">
772+
<Link>Classes\RemotePathDoubleQuoteTransformationTest.cs</Link>
773+
</Compile>
774+
<Compile Include="..\Renci.SshNet.Tests\Classes\RemotePathShellQuoteTransformationTest.cs">
775+
<Link>Classes\RemotePathShellQuoteTransformationTest.cs</Link>
776+
</Compile>
768777
<Compile Include="..\Renci.SshNet.Tests\Classes\ScpClientTest.cs">
769778
<Link>Classes\ScpClientTest.cs</Link>
770779
</Compile>
@@ -1587,7 +1596,7 @@
15871596
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
15881597
<ProjectExtensions>
15891598
<VisualStudio>
1590-
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="c45379b9-17b1-4e89-bc2e-6d41726413e8" />
1599+
<UserProperties ProjectLinkReference="c45379b9-17b1-4e89-bc2e-6d41726413e8" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
15911600
</VisualStudio>
15921601
</ProjectExtensions>
15931602
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Renci.SshNet.Common;
4+
5+
namespace Renci.SshNet.Tests.Classes.Common
6+
{
7+
[TestClass]
8+
public class PosixPathTest_GetFileName
9+
{
10+
[TestMethod]
11+
public void Path_Null()
12+
{
13+
const string path = null;
14+
15+
try
16+
{
17+
PosixPath.GetFileName(path);
18+
Assert.Fail();
19+
}
20+
catch (NullReferenceException)
21+
{
22+
}
23+
}
24+
25+
[TestMethod]
26+
public void Path_Empty()
27+
{
28+
var path = string.Empty;
29+
30+
var actual = PosixPath.GetFileName(path);
31+
32+
Assert.IsNotNull(actual);
33+
Assert.AreSame(path, actual);
34+
}
35+
36+
[TestMethod]
37+
public void Path_TrailingForwardSlash()
38+
{
39+
var path = "/abc/";
40+
41+
var actual = PosixPath.GetFileName(path);
42+
43+
Assert.IsNotNull(actual);
44+
Assert.AreEqual(string.Empty, actual);
45+
}
46+
47+
[TestMethod]
48+
public void Path_FileWithoutNoDirectory()
49+
{
50+
var path = "abc.log";
51+
52+
var actual = PosixPath.GetFileName(path);
53+
54+
Assert.IsNotNull(actual);
55+
Assert.AreSame(path, actual);
56+
}
57+
58+
[TestMethod]
59+
public void Path_FileInRootDirectory()
60+
{
61+
var path = "/abc.log";
62+
63+
var actual = PosixPath.GetFileName(path);
64+
65+
Assert.IsNotNull(actual);
66+
Assert.AreEqual("abc.log", actual);
67+
}
68+
69+
[TestMethod]
70+
public void Path_RootDirectoryOnly()
71+
{
72+
var path = "/";
73+
74+
var actual = PosixPath.GetFileName(path);
75+
76+
Assert.IsNotNull(actual);
77+
Assert.AreEqual(string.Empty, actual);
78+
}
79+
80+
[TestMethod]
81+
public void Path_FileInNonRootDirectory()
82+
{
83+
var path = "/home/sshnet/xyz";
84+
85+
var actual = PosixPath.GetFileName(path);
86+
87+
Assert.IsNotNull(actual);
88+
Assert.AreEqual("xyz", actual);
89+
}
90+
91+
[TestMethod]
92+
public void Path_BackslashIsNotConsideredDirectorySeparator()
93+
{
94+
var path = "/home\\abc.log";
95+
96+
var actual = PosixPath.GetFileName(path);
97+
98+
Assert.IsNotNull(actual);
99+
Assert.AreEqual("home\\abc.log", actual);
100+
}
101+
102+
[TestMethod]
103+
public void Path_ColonIsNotConsideredPathSeparator()
104+
{
105+
var path = "/home:abc.log";
106+
107+
var actual = PosixPath.GetFileName(path);
108+
109+
Assert.IsNotNull(actual);
110+
Assert.AreEqual("home:abc.log", actual);
111+
}
112+
113+
[TestMethod]
114+
public void Path_LeadingWhitespace()
115+
{
116+
var path = " / \tabc";
117+
118+
var actual = PosixPath.GetFileName(path);
119+
120+
Assert.IsNotNull(actual);
121+
Assert.AreEqual(" \tabc", actual);
122+
}
123+
124+
[TestMethod]
125+
public void Path_TrailingWhitespace()
126+
{
127+
var path = "/abc \t ";
128+
129+
var actual = PosixPath.GetFileName(path);
130+
131+
Assert.IsNotNull(actual);
132+
Assert.AreEqual("abc \t ", actual);
133+
}
134+
135+
[TestMethod]
136+
public void Path_OnlyWhitespace()
137+
{
138+
var path = " ";
139+
140+
var actual = PosixPath.GetFileName(path);
141+
142+
Assert.IsNotNull(actual);
143+
Assert.AreEqual(" ", actual);
144+
}
145+
146+
[TestMethod]
147+
public void Path_FileNameOnlyWhitespace()
148+
{
149+
var path = "/home/\t ";
150+
151+
var actual = PosixPath.GetFileName(path);
152+
153+
Assert.IsNotNull(actual);
154+
Assert.AreEqual("\t ", actual);
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)