1
- using Microsoft . VisualStudio . TestTools . UnitTesting ;
2
- using Renci . SshNet . Common ;
3
- using Renci . SshNet . Tests . Properties ;
4
- using System . IO ;
5
- using System . Linq ;
6
- using System . Threading . Tasks ;
7
-
8
- namespace Renci . SshNet . Tests . Classes
9
- {
10
- /// <summary>
11
- /// Provides SCP client functionality.
12
- /// </summary>
13
- public partial class ScpClientTest
14
- {
15
- [ TestMethod ]
16
- [ TestCategory ( "Scp" ) ]
17
- public void Test_Scp_File_20_Parallel_Upload_Download ( )
18
- {
19
- using ( var scp = new ScpClient ( Resources . HOST , Resources . USERNAME , Resources . PASSWORD ) )
20
- {
21
- scp . Connect ( ) ;
22
-
23
- var uploadFilenames = new string [ 20 ] ;
24
- for ( int i = 0 ; i < uploadFilenames . Length ; i ++ )
25
- {
26
- uploadFilenames [ i ] = Path . GetTempFileName ( ) ;
27
- this . CreateTestFile ( uploadFilenames [ i ] , 1 ) ;
28
- }
29
-
30
- Parallel . ForEach ( uploadFilenames ,
31
- ( filename ) =>
32
- {
33
- scp . Upload ( new FileInfo ( filename ) , Path . GetFileName ( filename ) ) ;
34
- } ) ;
35
-
36
- Parallel . ForEach ( uploadFilenames ,
37
- ( filename ) =>
38
- {
39
- scp . Download ( Path . GetFileName ( filename ) , new FileInfo ( string . Format ( "{0}.down" , filename ) ) ) ;
40
- } ) ;
41
-
42
- var result = from file in uploadFilenames
43
- where
44
- CalculateMD5 ( file ) == CalculateMD5 ( string . Format ( "{0}.down" , file ) )
45
- select file ;
46
-
47
- scp . Disconnect ( ) ;
48
-
49
- Assert . IsTrue ( result . Count ( ) == uploadFilenames . Length ) ;
50
- }
51
- }
52
-
53
- [ TestMethod ]
54
- [ TestCategory ( "Scp" ) ]
55
- public void Test_Scp_File_Upload_Download_Events ( )
56
- {
57
- using ( var scp = new ScpClient ( Resources . HOST , Resources . USERNAME , Resources . PASSWORD ) )
58
- {
59
- scp . Connect ( ) ;
60
-
61
- var uploadFilenames = new string [ 10 ] ;
62
-
63
- for ( int i = 0 ; i < uploadFilenames . Length ; i ++ )
64
- {
65
- uploadFilenames [ i ] = Path . GetTempFileName ( ) ;
66
- this . CreateTestFile ( uploadFilenames [ i ] , 1 ) ;
67
- }
68
-
69
- var uploadedFiles = uploadFilenames . ToDictionary ( ( filename ) => Path . GetFileName ( filename ) , ( filename ) => 0L ) ;
70
- var downloadedFiles = uploadFilenames . ToDictionary ( ( filename ) => string . Format ( "{0}.down" , Path . GetFileName ( filename ) ) , ( filename ) => 0L ) ;
71
-
72
- scp . Uploading += delegate ( object sender , ScpUploadEventArgs e )
73
- {
74
- uploadedFiles [ e . Filename ] = e . Uploaded ;
75
- } ;
76
-
77
- scp . Downloading += delegate ( object sender , ScpDownloadEventArgs e )
78
- {
79
- downloadedFiles [ string . Format ( "{0}.down" , e . Filename ) ] = e . Downloaded ;
80
- } ;
81
-
82
- Parallel . ForEach ( uploadFilenames ,
83
- ( filename ) =>
84
- {
85
- scp . Upload ( new FileInfo ( filename ) , Path . GetFileName ( filename ) ) ;
86
- } ) ;
87
-
88
- Parallel . ForEach ( uploadFilenames ,
89
- ( filename ) =>
90
- {
91
- scp . Download ( Path . GetFileName ( filename ) , new FileInfo ( string . Format ( "{0}.down" , filename ) ) ) ;
92
- } ) ;
93
-
94
- var result = from uf in uploadedFiles
95
- from df in downloadedFiles
96
- where
97
- string . Format ( "{0}.down" , uf . Key ) == df . Key
98
- && uf . Value == df . Value
99
- select uf ;
100
-
101
- scp . Disconnect ( ) ;
102
-
103
- Assert . IsTrue ( result . Count ( ) == uploadFilenames . Length && uploadFilenames . Length == uploadedFiles . Count && uploadedFiles . Count == downloadedFiles . Count ) ;
104
- }
105
- }
106
- }
1
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2
+ using Renci . SshNet . Common ;
3
+ using Renci . SshNet . Tests . Properties ;
4
+ using System . IO ;
5
+ using System . Linq ;
6
+ using System . Threading . Tasks ;
7
+
8
+ namespace Renci . SshNet . Tests . Classes
9
+ {
10
+ /// <summary>
11
+ /// Provides SCP client functionality.
12
+ /// </summary>
13
+ public partial class ScpClientTest
14
+ {
15
+ [ TestMethod ]
16
+ [ TestCategory ( "Scp" ) ]
17
+ [ TestCategory ( "integration" ) ]
18
+ public void Test_Scp_File_20_Parallel_Upload_Download ( )
19
+ {
20
+ using ( var scp = new ScpClient ( Resources . HOST , Resources . USERNAME , Resources . PASSWORD ) )
21
+ {
22
+ scp . Connect ( ) ;
23
+
24
+ var uploadFilenames = new string [ 20 ] ;
25
+ for ( int i = 0 ; i < uploadFilenames . Length ; i ++ )
26
+ {
27
+ uploadFilenames [ i ] = Path . GetTempFileName ( ) ;
28
+ this . CreateTestFile ( uploadFilenames [ i ] , 1 ) ;
29
+ }
30
+
31
+ Parallel . ForEach ( uploadFilenames ,
32
+ ( filename ) =>
33
+ {
34
+ scp . Upload ( new FileInfo ( filename ) , Path . GetFileName ( filename ) ) ;
35
+ } ) ;
36
+
37
+ Parallel . ForEach ( uploadFilenames ,
38
+ ( filename ) =>
39
+ {
40
+ scp . Download ( Path . GetFileName ( filename ) , new FileInfo ( string . Format ( "{0}.down" , filename ) ) ) ;
41
+ } ) ;
42
+
43
+ var result = from file in uploadFilenames
44
+ where
45
+ CalculateMD5 ( file ) == CalculateMD5 ( string . Format ( "{0}.down" , file ) )
46
+ select file ;
47
+
48
+ scp . Disconnect ( ) ;
49
+
50
+ Assert . IsTrue ( result . Count ( ) == uploadFilenames . Length ) ;
51
+ }
52
+ }
53
+
54
+ [ TestMethod ]
55
+ [ TestCategory ( "Scp" ) ]
56
+ [ TestCategory ( "integration" ) ]
57
+ public void Test_Scp_File_Upload_Download_Events ( )
58
+ {
59
+ using ( var scp = new ScpClient ( Resources . HOST , Resources . USERNAME , Resources . PASSWORD ) )
60
+ {
61
+ scp . Connect ( ) ;
62
+
63
+ var uploadFilenames = new string [ 10 ] ;
64
+
65
+ for ( int i = 0 ; i < uploadFilenames . Length ; i ++ )
66
+ {
67
+ uploadFilenames [ i ] = Path . GetTempFileName ( ) ;
68
+ this . CreateTestFile ( uploadFilenames [ i ] , 1 ) ;
69
+ }
70
+
71
+ var uploadedFiles = uploadFilenames . ToDictionary ( ( filename ) => Path . GetFileName ( filename ) , ( filename ) => 0L ) ;
72
+ var downloadedFiles = uploadFilenames . ToDictionary ( ( filename ) => string . Format ( "{0}.down" , Path . GetFileName ( filename ) ) , ( filename ) => 0L ) ;
73
+
74
+ scp . Uploading += delegate ( object sender , ScpUploadEventArgs e )
75
+ {
76
+ uploadedFiles [ e . Filename ] = e . Uploaded ;
77
+ } ;
78
+
79
+ scp . Downloading += delegate ( object sender , ScpDownloadEventArgs e )
80
+ {
81
+ downloadedFiles [ string . Format ( "{0}.down" , e . Filename ) ] = e . Downloaded ;
82
+ } ;
83
+
84
+ Parallel . ForEach ( uploadFilenames ,
85
+ ( filename ) =>
86
+ {
87
+ scp . Upload ( new FileInfo ( filename ) , Path . GetFileName ( filename ) ) ;
88
+ } ) ;
89
+
90
+ Parallel . ForEach ( uploadFilenames ,
91
+ ( filename ) =>
92
+ {
93
+ scp . Download ( Path . GetFileName ( filename ) , new FileInfo ( string . Format ( "{0}.down" , filename ) ) ) ;
94
+ } ) ;
95
+
96
+ var result = from uf in uploadedFiles
97
+ from df in downloadedFiles
98
+ where
99
+ string . Format ( "{0}.down" , uf . Key ) == df . Key
100
+ && uf . Value == df . Value
101
+ select uf ;
102
+
103
+ scp . Disconnect ( ) ;
104
+
105
+ Assert . IsTrue ( result . Count ( ) == uploadFilenames . Length && uploadFilenames . Length == uploadedFiles . Count && uploadedFiles . Count == downloadedFiles . Count ) ;
106
+ }
107
+ }
108
+ }
107
109
}
0 commit comments