@@ -12,9 +12,6 @@ namespace IntegrationTests.Download
12
12
[ TestFixture ]
13
13
class DownloadTaskTests : BaseTaskManagerTest
14
14
{
15
- private const string TestDownload = "http://ipv4.download.thinkbroadband.com/5MB.zip" ;
16
- private const string TestDownloadMD5 = "b3215c06647bc550406a9c8ccc378756" ;
17
-
18
15
public override void OnSetup ( )
19
16
{
20
17
base . OnSetup ( ) ;
@@ -28,35 +25,37 @@ public async Task TestDownloadTask()
28
25
29
26
var fileSystem = Environment . FileSystem ;
30
27
31
- var downloadPath = TestBasePath . Combine ( "5MB .zip") ;
32
- var downloadHalfPath = TestBasePath . Combine ( "5MB-split. zip") ;
28
+ var gitLfs = new UriString ( "https://ghfvs-installer.github.com/unity/portable_git/git-lfs .zip") ;
29
+ var gitLfsMd5 = new UriString ( "https://ghfvs-installer.github.com/unity/portable_git/git-lfs. zip.MD5.txt?cb=1 ") ;
33
30
34
- var downloadTask = new DownloadTask ( TaskManager . Token , fileSystem , TestDownload , TestBasePath ) ;
35
- await downloadTask . StartAwait ( ) ;
31
+ var md5 = await new DownloadTextTask ( TaskManager . Token , fileSystem , gitLfsMd5 , TestBasePath )
32
+ . StartAwait ( ) ;
36
33
37
- var downloadPathBytes = fileSystem . ReadAllBytes ( downloadPath ) ;
38
- Logger . Trace ( "File size {0} bytes" , downloadPathBytes . Length ) ;
34
+ var downloadPath = await new DownloadTask ( TaskManager . Token , fileSystem , gitLfs , TestBasePath )
35
+ . StartAwait ( ) ;
39
36
40
37
var md5Sum = fileSystem . CalculateFileMD5 ( downloadPath ) ;
41
- md5Sum . Should ( ) . Be ( TestDownloadMD5 ) ;
38
+ md5Sum . Should ( ) . BeEquivalentTo ( md5 ) ;
39
+
40
+ var downloadPathBytes = fileSystem . ReadAllBytes ( downloadPath ) ;
41
+ Logger . Trace ( "File size {0} bytes" , downloadPathBytes . Length ) ;
42
42
43
43
var random = new Random ( ) ;
44
44
var takeCount = random . Next ( downloadPathBytes . Length ) ;
45
45
46
46
Logger . Trace ( "Cutting the first {0} Bytes" , downloadPathBytes . Length - takeCount ) ;
47
47
48
48
var cutDownloadPathBytes = downloadPathBytes . Take ( takeCount ) . ToArray ( ) ;
49
- fileSystem . WriteAllBytes ( downloadHalfPath , cutDownloadPathBytes ) ;
49
+ fileSystem . WriteAllBytes ( downloadPath , cutDownloadPathBytes ) ;
50
50
51
- downloadTask = new DownloadTask ( TaskManager . Token , fileSystem , TestDownload ,
52
- TestBasePath , validationHash : TestDownloadMD5 ) ;
53
- await downloadTask . StartAwait ( ) ;
51
+ downloadPath = await new DownloadTask ( TaskManager . Token , fileSystem , gitLfs , TestBasePath )
52
+ . StartAwait ( ) ;
54
53
55
- var downloadHalfPathBytes = fileSystem . ReadAllBytes ( downloadHalfPath ) ;
54
+ var downloadHalfPathBytes = fileSystem . ReadAllBytes ( downloadPath ) ;
56
55
Logger . Trace ( "File size {0} Bytes" , downloadHalfPathBytes . Length ) ;
57
56
58
57
md5Sum = fileSystem . CalculateFileMD5 ( downloadPath ) ;
59
- md5Sum . Should ( ) . Be ( TestDownloadMD5 ) ;
58
+ md5Sum . Should ( ) . BeEquivalentTo ( md5 ) ;
60
59
}
61
60
62
61
[ Test ]
@@ -134,38 +133,21 @@ public void TestDownloadFileAndHash()
134
133
135
134
var fileSystem = Environment . FileSystem ;
136
135
137
- var gitArchivePath = TestBasePath . Combine ( "git.zip" ) ;
138
- var gitLfsArchivePath = TestBasePath . Combine ( "git-lfs.zip" ) ;
139
-
140
- var downloadGitMd5Task = new DownloadTextTask ( TaskManager . Token , fileSystem ,
141
- "https://ghfvs-installer.github.com/unity/portable_git/git.zip.MD5.txt?cb=1" ,
142
- TestBasePath ) ;
143
-
144
- var downloadGitTask = new DownloadTask ( TaskManager . Token , fileSystem ,
145
- "https://ghfvs-installer.github.com/unity/portable_git/git.zip" ,
146
- TestBasePath ) ;
136
+ var gitLfs = new UriString ( "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip" ) ;
137
+ var gitLfsMd5 = new UriString ( "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt?cb=1" ) ;
147
138
148
139
var downloadGitLfsMd5Task = new DownloadTextTask ( TaskManager . Token , fileSystem ,
149
- "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt?cb=1" ,
150
- TestBasePath ) ;
151
-
140
+ gitLfsMd5 , TestBasePath ) ;
152
141
153
142
var downloadGitLfsTask = new DownloadTask ( TaskManager . Token , fileSystem ,
154
- "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip" ,
155
- TestBasePath ) ;
143
+ gitLfs , TestBasePath ) ;
156
144
157
145
var result = true ;
158
146
Exception exception = null ;
159
147
160
148
var autoResetEvent = new AutoResetEvent ( false ) ;
161
149
162
- downloadGitMd5Task
163
- . Then ( ( b , s ) =>
164
- {
165
- downloadGitTask . ValidationHash = s ;
166
- } )
167
- . Then ( downloadGitTask )
168
- . Then ( downloadGitLfsMd5Task )
150
+ downloadGitLfsMd5Task
169
151
. Then ( ( b , s ) =>
170
152
{
171
153
downloadGitLfsTask . ValidationHash = s ;
@@ -214,8 +196,7 @@ public void TestDownloadShutdownTimeWhenInterrupted()
214
196
} )
215
197
. Progress ( p =>
216
198
{
217
- if ( p . Percentage > 0.2 )
218
- evtStop . Set ( ) ;
199
+ evtStop . Set ( ) ;
219
200
} ) ;
220
201
221
202
downloadGitTask . Start ( ) ;
0 commit comments