Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 3c1f6a7

Browse files
Returning successful result
1 parent 117a44d commit 3c1f6a7

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/GitHub.Api/Tasks/DownloadTask.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static WebResponse GetResponseWithoutException(this WebRequest request)
9090
}
9191
}
9292

93-
class DownloadTask : TaskBase
93+
class DownloadTask : TaskBase<bool>
9494
{
9595
private IFileSystem fileSystem;
9696
private long bytes;
@@ -108,22 +108,16 @@ public DownloadTask(CancellationToken token, IFileSystem fileSystem, string url,
108108
Name = "DownloadTask";
109109
}
110110

111-
protected override void Run(bool success)
111+
protected override bool RunWithReturn(bool success)
112112
{
113-
base.Run(success);
113+
base.RunWithReturn(success);
114114

115115
RaiseOnStart();
116116

117-
var downloadResult = new DownloadResult
118-
{
119-
Url = Url,
120-
Destination = Destination
121-
};
122-
117+
var result = false;
123118
try
124119
{
125-
downloadResult.Success = Download();
126-
downloadResult.MD5Sum = fileSystem.CalculateMD5(Destination);
120+
result = Download();
127121
}
128122
catch (Exception ex)
129123
{
@@ -133,8 +127,10 @@ protected override void Run(bool success)
133127
}
134128
finally
135129
{
136-
RaiseOnEnd();
130+
RaiseOnEnd(result);
137131
}
132+
133+
return result;
138134
}
139135

140136
protected virtual void UpdateProgress(float progress)
@@ -144,7 +140,7 @@ protected virtual void UpdateProgress(float progress)
144140

145141
public bool Download()
146142
{
147-
FileInfo fileInfo = new FileInfo(Destination);
143+
var fileInfo = new FileInfo(Destination);
148144
if (fileSystem.FileExists(Destination))
149145
{
150146
var fileLength = fileSystem.FileLength(Destination);

src/tests/IntegrationTests/Download/DownloadTaskTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public async Task TestDownloadTask()
2626
var downloadHalfPath = TestBasePath.Combine("5MB-split.zip");
2727

2828
var downloadTask = new DownloadTask(CancellationToken.None, fileSystem, TestDownload, downloadPath);
29-
await downloadTask.StartAwait();
29+
var downloadResult = await downloadTask.StartAwait();
30+
31+
downloadResult.Should().BeTrue();
3032

3133
var downloadPathBytes = fileSystem.ReadAllBytes(downloadPath);
3234
Logger.Trace("File size {0} bytes", downloadPathBytes.Length);
@@ -43,7 +45,9 @@ public async Task TestDownloadTask()
4345
fileSystem.WriteAllBytes(downloadHalfPath, cutDownloadPathBytes);
4446

4547
downloadTask = new DownloadTask(CancellationToken.None, fileSystem, TestDownload, downloadHalfPath);
46-
await downloadTask.StartAwait();
48+
downloadResult = await downloadTask.StartAwait();
49+
50+
downloadResult.Should().BeTrue();
4751

4852
var downloadHalfPathBytes = fileSystem.ReadAllBytes(downloadHalfPath);
4953
Logger.Trace("File size {0} Bytes", downloadHalfPathBytes.Length);

src/tests/IntegrationTests/SetUpFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Setup()
1414

1515
Logging.LogAdapter = new MultipleLogAdapter(
1616
new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log")
17-
//, new ConsoleLogAdapter()
17+
, new ConsoleLogAdapter()
1818
);
1919
}
2020
}

0 commit comments

Comments
 (0)