forked from clowd/Clowd.Squirrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownloadReleasesTests.cs
194 lines (156 loc) · 7.67 KB
/
DownloadReleasesTests.cs
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Squirrel.SimpleSplat;
using Squirrel.Tests.TestHelpers;
using Xunit;
namespace Squirrel.Tests
{
public class DownloadReleasesTests
{
[Fact(Skip = "Rewrite this to be an integration test")]
public void ChecksumShouldFailIfFilesAreMissing()
{
Assert.False(true, "Rewrite this to be an integration test");
/*
var filename = "Squirrel.Core.1.0.0.0.nupkg";
var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
var fs = new Mock<IFileSystemFactory>();
var urlDownloader = new Mock<IUrlDownloader>();
ReleaseEntry entry;
using (var f = File.OpenRead(nuGetPkg)) {
entry = ReleaseEntry.GenerateFromFile(f, filename);
}
var fileInfo = new Mock<FileInfoBase>();
fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg));
fileInfo.Setup(x => x.Exists).Returns(false);
fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
var fixture = ExposedObject.From(
new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
bool shouldDie = true;
try {
// NB: We can't use Assert.Throws here because the binder
// will try to pick the wrong method
fixture.checksumPackage(entry);
} catch (Exception) {
shouldDie = false;
}
shouldDie.ShouldBeFalse();
*/
}
[Fact(Skip = "Rewrite this to be an integration test")]
public void ChecksumShouldFailIfFilesAreBogus()
{
Assert.False(true, "Rewrite this to be an integration test");
/*
var filename = "Squirrel.Core.1.0.0.0.nupkg";
var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
var fs = new Mock<IFileSystemFactory>();
var urlDownloader = new Mock<IUrlDownloader>();
ReleaseEntry entry;
using (var f = File.OpenRead(nuGetPkg)) {
entry = ReleaseEntry.GenerateFromFile(f, filename);
}
var fileInfo = new Mock<FileInfoBase>();
fileInfo.Setup(x => x.OpenRead()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("Lol broken")));
fileInfo.Setup(x => x.Exists).Returns(true);
fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length);
fileInfo.Setup(x => x.Delete()).Verifiable();
fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
var fixture = ExposedObject.From(
new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
bool shouldDie = true;
try {
fixture.checksumPackage(entry);
} catch (Exception ex) {
this.Log().InfoException("Checksum failure", ex);
shouldDie = false;
}
shouldDie.ShouldBeFalse();
fileInfo.Verify(x => x.Delete(), Times.Once());
*/
}
[Fact(Skip = "Rewrite this to be an integration test")]
public async Task DownloadReleasesFromHttpServerIntegrationTest()
{
Assert.False(true, "Rewrite this to not use the SampleUpdatingApp");
/*
string tempDir = null;
var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
IDisposable disp;
try {
var httpServer = new StaticHttpServer(30405, updateDir.FullName);
disp = httpServer.Start();
} catch (HttpListenerException) {
Assert.False(true, @"Windows sucks, go run 'netsh http add urlacl url=http://+:30405/ user=MYMACHINE\MyUser");
return;
}
var entriesToDownload = updateDir.GetFiles("*.nupkg")
.Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
.ToArray();
entriesToDownload.Count().ShouldBeGreaterThan(0);
using (disp)
using (Utility.WithTempDirectory(out tempDir)) {
// NB: This is normally done by CheckForUpdates, but since
// we're skipping that in the test we have to do it ourselves
Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
var fixture = new UpdateManager("http://localhost:30405", "SampleUpdatingApp", tempDir);
using (fixture) {
var progress = new List<int>();
await fixture.DownloadReleases(entriesToDownload, progress.Add);
progress
.Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
.ShouldEqual(100);
}
entriesToDownload.ForEach(x => {
this.Log().Info("Looking for {0}", x.Filename);
var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
File.Exists(actualFile).ShouldBeTrue();
var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
actualEntry.SHA1.ShouldEqual(x.SHA1);
actualEntry.Version.ShouldEqual(x.Version);
});
}
*/
}
[Fact(Skip = "Rewrite this to be an integration test")]
public async Task DownloadReleasesFromFileDirectoryIntegrationTest()
{
Assert.False(true, "Rewrite this to not use the SampleUpdatingApp");
/*
string tempDir = null;
var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
var entriesToDownload = updateDir.GetFiles("*.nupkg")
.Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
.ToArray();
entriesToDownload.Count().ShouldBeGreaterThan(0);
using (Utility.WithTempDirectory(out tempDir)) {
// NB: This is normally done by CheckForUpdates, but since
// we're skipping that in the test we have to do it ourselves
Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
var fixture = new UpdateManager(updateDir.FullName, "SampleUpdatingApp", tempDir);
using (fixture) {
var progress = new List<int>();
await fixture.DownloadReleases(entriesToDownload, progress.Add);
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
progress
.Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
.ShouldEqual(100);
}
entriesToDownload.ForEach(x => {
this.Log().Info("Looking for {0}", x.Filename);
var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
File.Exists(actualFile).ShouldBeTrue();
var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
actualEntry.SHA1.ShouldEqual(x.SHA1);
actualEntry.Version.ShouldEqual(x.Version);
});
}
*/
}
}
}