5
5
using Microsoft . VisualStudio . TestTools . UnitTesting ;
6
6
using Renci . SshNet . Common ;
7
7
using Renci . SshNet . Tests . Common ;
8
+ using Renci . SshNet . Connection ;
8
9
9
10
namespace Renci . SshNet . Tests . Classes
10
11
{
@@ -21,8 +22,15 @@ public void ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainS
21
22
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "Whatever\r \n " ) ) ;
22
23
proxyStub . Start ( ) ;
23
24
24
- using ( var session = new Session ( CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , "anon" ) , _serviceFactoryMock . Object ) )
25
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , "anon" ) ;
26
+
27
+ using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
25
28
{
29
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
30
+ . Returns ( _connectorMock . Object ) ;
31
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
32
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
33
+
26
34
try
27
35
{
28
36
session . Connect ( ) ;
@@ -48,8 +56,15 @@ public void ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherT
48
56
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "HTTP/1.0 501 Custom\r \n " ) ) ;
49
57
proxyStub . Start ( ) ;
50
58
51
- using ( var session = new Session ( CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , "anon" ) , _serviceFactoryMock . Object ) )
59
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , "anon" ) ;
60
+
61
+ using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
52
62
{
63
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
64
+ . Returns ( _connectorMock . Object ) ;
65
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
66
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
67
+
53
68
try
54
69
{
55
70
session . Connect ( ) ;
@@ -78,8 +93,15 @@ public void ConnectShouldSkipHeadersWhenHttpProxyReturnsHttpStatus200()
78
93
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "SSH-666-SshStub" ) ) ;
79
94
proxyStub . Start ( ) ;
80
95
81
- using ( var session = new Session ( CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , "anon" ) , _serviceFactoryMock . Object ) )
96
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , "anon" ) ;
97
+
98
+ using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
82
99
{
100
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
101
+ . Returns ( _connectorMock . Object ) ;
102
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
103
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
104
+
83
105
try
84
106
{
85
107
session . Connect ( ) ;
@@ -110,8 +132,15 @@ public void ConnectShouldSkipContentWhenHttpProxyReturnsHttpStatus200()
110
132
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "SSH-666-SshStub" ) ) ;
111
133
proxyStub . Start ( ) ;
112
134
113
- using ( var session = new Session ( CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , "anon" ) , _serviceFactoryMock . Object ) )
135
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , "anon" ) ;
136
+
137
+ using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
114
138
{
139
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
140
+ . Returns ( _connectorMock . Object ) ;
141
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
142
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
143
+
115
144
try
116
145
{
117
146
session . Connect ( ) ;
@@ -137,8 +166,15 @@ public void ConnectShouldWriteConnectMethodToHttpProxy()
137
166
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "HTTP/1.0 501 Custom\r \n " ) ) ;
138
167
proxyStub . Start ( ) ;
139
168
140
- using ( var session = new Session ( CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , "anon" ) , _serviceFactoryMock . Object ) )
169
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , "anon" ) ;
170
+
171
+ using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
141
172
{
173
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
174
+ . Returns ( _connectorMock . Object ) ;
175
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
176
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
177
+
142
178
try
143
179
{
144
180
session . Connect ( ) ;
@@ -164,9 +200,15 @@ public void ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNo
164
200
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "HTTP/1.0 501 Custom\r \n " ) ) ;
165
201
proxyStub . Start ( ) ;
166
202
167
- var connectionInfo = CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , "anon" ) ;
203
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , "anon" ) ;
204
+
168
205
using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
169
206
{
207
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
208
+ . Returns ( _connectorMock . Object ) ;
209
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
210
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
211
+
170
212
try
171
213
{
172
214
session . Connect ( ) ;
@@ -193,9 +235,15 @@ public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameI
193
235
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "HTTP/1.0 501 Custom\r \n " ) ) ;
194
236
proxyStub . Start ( ) ;
195
237
196
- var connectionInfo = CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , string . Empty ) ;
238
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , string . Empty ) ;
239
+
197
240
using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
198
241
{
242
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
243
+ . Returns ( _connectorMock . Object ) ;
244
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
245
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
246
+
199
247
try
200
248
{
201
249
session . Connect ( ) ;
@@ -221,9 +269,14 @@ public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameI
221
269
proxyStub . Responses . Add ( Encoding . ASCII . GetBytes ( "HTTP/1.0 501 Custom\r \n " ) ) ;
222
270
proxyStub . Start ( ) ;
223
271
224
- var connectionInfo = CreateConnectionInfoWithProxy ( proxyEndPoint , serverEndPoint , null ) ;
272
+ var connectionInfo = CreateConnectionInfoWithHttpProxy ( proxyEndPoint , serverEndPoint , null ) ;
225
273
using ( var session = new Session ( connectionInfo , _serviceFactoryMock . Object ) )
226
274
{
275
+ _serviceFactoryMock . Setup ( p => p . CreateConnector ( connectionInfo ) )
276
+ . Returns ( _connectorMock . Object ) ;
277
+ _connectorMock . Setup ( p => p . Connect ( connectionInfo ) )
278
+ . Returns < IConnectionInfo > ( c => new HttpConnector ( ) . Connect ( c ) ) ;
279
+
227
280
try
228
281
{
229
282
session . Connect ( ) ;
@@ -238,7 +291,7 @@ public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameI
238
291
}
239
292
}
240
293
241
- private static ConnectionInfo CreateConnectionInfoWithProxy ( IPEndPoint proxyEndPoint , IPEndPoint serverEndPoint , string proxyUserName )
294
+ private static ConnectionInfo CreateConnectionInfoWithHttpProxy ( IPEndPoint proxyEndPoint , IPEndPoint serverEndPoint , string proxyUserName )
242
295
{
243
296
return new ConnectionInfo (
244
297
serverEndPoint . Address . ToString ( ) ,
0 commit comments