-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathDefaultDownloadOrchestratorTests.cs
More file actions
108 lines (99 loc) · 3.7 KB
/
Copy pathDefaultDownloadOrchestratorTests.cs
File metadata and controls
108 lines (99 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.Download.Models;
using GeneralUpdate.Core.Download.Orchestrators;
using GeneralUpdate.Core.Download.Policy;
namespace CoreTest.Download;
public class DefaultDownloadOrchestratorTests
{
[Fact]
public void Ctor_HttpClientNull_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>(() =>
new DefaultDownloadOrchestrator(null));
}
[Fact]
public void Ctor_WithValidClient_CreatesInstance()
{
var client = new HttpClient();
var orchestrator = new DefaultDownloadOrchestrator(client);
Assert.NotNull(orchestrator);
}
[Fact]
public void Ctor_WithCustomOptions_UsesProvidedOptions()
{
var client = new HttpClient();
var options = new DownloadOrchestratorOptions
{
MaxConcurrency = 2,
EnableResume = false,
RetryCount = 1,
VerifyChecksum = false,
DiffMode = DiffMode.Serial
};
var orchestrator = new DefaultDownloadOrchestrator(client, options);
Assert.NotNull(orchestrator);
}
[Fact]
public void Ctor_WithCustomPolicy_UsesProvidedPolicy()
{
var client = new HttpClient();
var policy = new DefaultRetryPolicy(5, TimeSpan.FromSeconds(2));
var orchestrator = new DefaultDownloadOrchestrator(client, null, policy);
Assert.NotNull(orchestrator);
}
[Fact]
public async Task ExecuteAsync_PlanNull_ReturnsEmptyReport()
{
var client = new HttpClient();
var orchestrator = new DefaultDownloadOrchestrator(client);
var dest = Path.Combine(Path.GetTempPath(), $"dl_{Guid.NewGuid():N}");
try
{
var report = await orchestrator.ExecuteAsync(null, dest);
Assert.Equal(0, report.SuccessCount);
Assert.Equal(0, report.FailedCount);
}
finally { if (Directory.Exists(dest)) Directory.Delete(dest, true); }
}
[Fact]
public async Task ExecuteAsync_PlanHasNoAssets_ReturnsEmptyReport()
{
var client = new HttpClient();
var orchestrator = new DefaultDownloadOrchestrator(client);
var plan = new DownloadPlan(Array.Empty<DownloadAsset>(), false);
var dest = Path.Combine(Path.GetTempPath(), $"dl_{Guid.NewGuid():N}");
try
{
var report = await orchestrator.ExecuteAsync(plan, dest);
Assert.Equal(0, report.SuccessCount);
Assert.Equal(0, report.FailedCount);
}
finally { if (Directory.Exists(dest)) Directory.Delete(dest, true); }
}
[Fact]
public async Task ExecuteAsync_DestinationDirectoryCreated()
{
var client = new HttpClient();
var orchestrator = new DefaultDownloadOrchestrator(client);
var plan = new DownloadPlan(
new[] { new DownloadAsset("test", "http://example.com/f", 100, null, "1.0") }, false);
var dest = Path.Combine(Path.GetTempPath(), $"dl_{Guid.NewGuid():N}");
Directory.CreateDirectory(dest);
try
{
var report = await orchestrator.ExecuteAsync(plan, dest);
Assert.NotNull(report);
}
finally { if (Directory.Exists(dest)) Directory.Delete(dest, true); }
}
[Fact]
public async Task ExecuteAsync_GetFileName_ExtractsFromUri()
{
var client = new HttpClient();
var orchestrator = new DefaultDownloadOrchestrator(client);
// Asset with a proper URL should have file name extracted from URI path
var asset = new DownloadAsset("test", "http://example.com/path/to/update.zip", 100, null, "1.0");
Assert.NotNull(asset.Url);
Assert.Contains("update.zip", asset.Url);
}
}