@@ -9,10 +9,145 @@ public class PathHelperTests
9
9
[ TestMethod ]
10
10
public void TestCombineWithRelativePathAndDuplicateDirectoryName ( )
11
11
{
12
- PathHelper pathHelper = new PathHelper ( ) ;
12
+ PathHelper pathHelper = new ( ) ;
13
13
string result = pathHelper . Combine ( @"C:\One\Two\Three\Two" , "../Four" ) ;
14
14
Assert . AreEqual ( @"C:\One\Two\Three\Four" , result ) ;
15
15
}
16
-
16
+
17
+ [ TestMethod ]
18
+ public void TestRelativeToWithTwoRelativePaths ( )
19
+ {
20
+ PathHelper pathHelper = new ( ) ;
21
+ string result = pathHelper . RelativeTo ( "./" , "./one" ) ;
22
+ Assert . AreEqual ( @".." , result ) ;
23
+ }
24
+
25
+ [ TestMethod ]
26
+ public void TestRelativeToWithTwoRelativePaths1 ( )
27
+ {
28
+ PathHelper pathHelper = new ( ) ;
29
+ string result = pathHelper . RelativeTo ( "./" , "./one/two" ) ;
30
+ Assert . AreEqual ( @"..\.." , result ) ;
31
+ }
32
+
33
+ [ TestMethod ]
34
+ public void TestRelativeToWithTwoRelativePaths2 ( )
35
+ {
36
+ PathHelper pathHelper = new ( ) ;
37
+ string result = pathHelper . RelativeTo ( "./one" , "./" ) ;
38
+ Assert . AreEqual ( @"one" , result ) ;
39
+ }
40
+
41
+ [ TestMethod ]
42
+ public void TestRelativeToWithTwoRelativePaths3 ( )
43
+ {
44
+ PathHelper pathHelper = new ( ) ;
45
+ string result = pathHelper . RelativeTo ( "./one/two" , "./" ) ;
46
+ Assert . AreEqual ( @"one\two" , result ) ;
47
+ }
48
+
49
+ [ TestMethod ]
50
+ public void TestRelativeToWithTwoRelativePaths4 ( )
51
+ {
52
+ PathHelper pathHelper = new ( ) ;
53
+ string result = pathHelper . RelativeTo ( "./one" , "./two" ) ;
54
+ Assert . AreEqual ( @"..\one" , result ) ;
55
+ }
56
+
57
+ [ TestMethod ]
58
+ public void TestRelativeToWithTwoRelativePaths5 ( )
59
+ {
60
+ PathHelper pathHelper = new ( ) ;
61
+ string result = pathHelper . RelativeTo ( "./relative/one" , "./relative/two" ) ;
62
+ Assert . AreEqual ( @"..\one" , result ) ;
63
+ }
64
+
65
+ [ TestMethod ]
66
+ public void TestRelativeToWithTwoRelativePaths6 ( )
67
+ {
68
+ PathHelper pathHelper = new ( ) ;
69
+ string result = pathHelper . RelativeTo ( "./relativeA/one" , "./relativeB/two" ) ;
70
+ Assert . AreEqual ( @"..\..\relativeA\one" , result ) ;
71
+ }
72
+
73
+ [ TestMethod ]
74
+ public void TestRelativeToWithRelativeAndAbsolutePath ( )
75
+ {
76
+ PathHelper pathHelper = new ( @"C:\some\Absolute\path" ) ;
77
+ string result = pathHelper . RelativeTo ( "./relative" , @"C:\some\Absolute\path" ) ;
78
+ Assert . AreEqual ( @"relative" , result ) ;
79
+ }
80
+
81
+ [ TestMethod ]
82
+ public void TestRelativeToWithAbsoluteAndRelativePath ( )
83
+ {
84
+ PathHelper pathHelper = new ( @"C:\some\Absolute\path" ) ;
85
+ string result = pathHelper . RelativeTo ( @"C:\some\Absolute\path" , "./relative" ) ;
86
+ Assert . AreEqual ( @".." , result ) ;
87
+ }
88
+
89
+ [ TestMethod ]
90
+ public void TestRelativeToWithAbsoluteAndRelativePath2 ( )
91
+ {
92
+ PathHelper pathHelper = new ( @"C:\some\Absolute\path" ) ;
93
+ string result = pathHelper . RelativeTo ( @"C:\some\other\path" , "./relative" ) ;
94
+ Assert . AreEqual ( @"..\..\..\other\path" , result ) ;
95
+ }
96
+
97
+ [ TestMethod ]
98
+ public void TestRelativeToWithRelativeParentAndAbsolutePath ( )
99
+ {
100
+ PathHelper pathHelper = new ( @"C:\some\Absolute\path" ) ;
101
+ string result = pathHelper . RelativeTo ( "../relative" , @"C:\some\Absolute\path" ) ;
102
+ Assert . AreEqual ( @"..\relative" , result ) ;
103
+ }
104
+
105
+ [ TestMethod ]
106
+ public void TestRelativeToWithRelativeParentAndAbsolutePath2 ( )
107
+ {
108
+ PathHelper pathHelper = new ( @"C:\some\Absolute\path" ) ;
109
+ string result = pathHelper . RelativeTo ( "../relative" , @"C:\some\other\path" ) ;
110
+ Assert . AreEqual ( @"..\..\Absolute\relative" , result ) ;
111
+ }
112
+
113
+ [ TestMethod ]
114
+ public void TestRelativeToWithAbsoluteAndRelativeParentPath ( )
115
+ {
116
+ PathHelper pathHelper = new ( @"C:\some\Absolute\path" ) ;
117
+ string result = pathHelper . RelativeTo ( @"C:\some\Absolute\path" , "../relative" ) ;
118
+ Assert . AreEqual ( @"..\path" , result ) ;
119
+ }
120
+
121
+ [ TestMethod ]
122
+ public void TestRelativeToWithAbsoluteAndRelativeParentPath2 ( )
123
+ {
124
+ PathHelper pathHelper = new ( @"C:\some\Absolute\path" ) ;
125
+ string result = pathHelper . RelativeTo ( @"C:\some\other\path" , "../relative" ) ;
126
+ Assert . AreEqual ( @"..\..\other\path" , result ) ;
127
+ }
128
+
129
+ [ TestMethod ]
130
+ public void TestRelativeToWithTwoAbsolutePaths ( )
131
+ {
132
+ PathHelper pathHelper = new ( ) ;
133
+ string result = pathHelper . RelativeTo ( @"C:\some\Absolute\path\one" , @"C:\some\Absolute\path\two" ) ;
134
+ Assert . AreEqual ( @"..\one" , result ) ;
135
+ }
136
+
137
+ [ TestMethod ]
138
+ public void TestRelativeToWithTwoAbsolutePaths2 ( )
139
+ {
140
+ PathHelper pathHelper = new ( ) ;
141
+ string result = pathHelper . RelativeTo ( @"C:\some\Absolute\path\one" , @"C:\some\Absolute\path\two\three" ) ;
142
+ Assert . AreEqual ( @"..\..\one" , result ) ;
143
+ }
144
+
145
+ [ TestMethod ]
146
+ public void TestRelativeToWithTwoAbsolutePaths3 ( )
147
+ {
148
+ PathHelper pathHelper = new ( ) ;
149
+ string result = pathHelper . RelativeTo ( @"C:\some\Absolute\path\one\three" , @"C:\some\Absolute\path\two" ) ;
150
+ Assert . AreEqual ( @"..\one\three" , result ) ;
151
+ }
17
152
}
18
- }
153
+ }
0 commit comments