Repository navigation
Expand file tree
/
Copy pathReleasePackageTests.cs
More file actions
310 lines (245 loc) · 12.6 KB
/
Copy pathReleasePackageTests.cs
File metadata and controls
310 lines (245 loc) · 12.6 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
using System.Runtime.Versioning;
using MarkdownSharp;
using NuGet;
using Squirrel;
using Squirrel.Tests.TestHelpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using Squirrel.SimpleSplat;
using Xunit;
namespace Squirrel.Tests.Core
{
public class CreateReleasePackageTests : IEnableLogger
{
[Fact]
public void SemanticVersionDoesWhatIWant()
{
var sv = new SemanticVersion("1.2.3.4");
var dontcare = default(SemanticVersion);
Assert.False(SemanticVersion.TryParseStrict(sv.ToString(), out dontcare));
}
[Fact]
public void ReleasePackageIntegrationTest()
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var outputPackage = Path.GetTempFileName() + ".nupkg";
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
var fixture = new ReleasePackage(inputPackage);
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
try {
fixture.CreateReleasePackage(outputPackage, sourceDir);
this.Log().Info("Resulting package is at {0}", outputPackage);
var pkg = new ZipPackage(outputPackage);
int refs = pkg.FrameworkAssemblies.Count();
this.Log().Info("Found {0} refs", refs);
refs.ShouldEqual(0);
this.Log().Info("Files in release package:");
List<IPackageFile> files = pkg.GetFiles().ToList();
files.ForEach(x => this.Log().Info(x.Path));
List<string> nonDesktopPaths = new[] {"sl", "winrt", "netcore", "win8", "windows8", "MonoAndroid", "MonoTouch", "MonoMac", "wp", }
.Select(x => @"lib\" + x)
.ToList();
files.Any(x => nonDesktopPaths.Any(y => x.Path.ToLowerInvariant().Contains(y.ToLowerInvariant()))).ShouldBeFalse();
files.Any(x => x.Path.ToLowerInvariant().EndsWith(@".xml")).ShouldBeFalse();
} finally {
File.Delete(outputPackage);
}
}
[Fact]
public void FindPackageInOurLocalPackageList()
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg");
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
var fixture = ExposedObject.From(new ReleasePackage(inputPackage));
IPackage result = fixture.matchPackage(new LocalPackageRepository(sourceDir), "xunit", VersionUtility.ParseVersionSpec("[1.0,2.0]"));
result.Id.ShouldEqual("xunit");
result.Version.Version.Major.ShouldEqual(2);
result.Version.Version.Minor.ShouldEqual(0);
}
[Fact]
public void FindDependentPackagesForDummyPackage()
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var fixture = new ReleasePackage(inputPackage);
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
IEnumerable<IPackage> results = fixture.findAllDependentPackages(default(IPackage), (IPackageRepository)new LocalPackageRepository(sourceDir), default(HashSet<string>), default(FrameworkName));
results.Count().ShouldBeGreaterThan(0);
}
[Fact]
public void CanLoadPackageWhichHasNoDependencies()
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.NoDependencies.1.0.0.0.nupkg");
var outputPackage = Path.GetTempFileName() + ".nupkg";
var fixture = new ReleasePackage(inputPackage);
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
try {
fixture.CreateReleasePackage(outputPackage, sourceDir);
}
finally {
File.Delete(outputPackage);
}
}
[Fact]
public void CanResolveMultipleLevelsOfDependencies()
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var outputPackage = Path.GetTempFileName() + ".nupkg";
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
var fixture = new ReleasePackage(inputPackage);
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
try {
fixture.CreateReleasePackage(outputPackage, sourceDir);
this.Log().Info("Resulting package is at {0}", outputPackage);
var pkg = new ZipPackage(outputPackage);
int refs = pkg.FrameworkAssemblies.Count();
this.Log().Info("Found {0} refs", refs);
refs.ShouldEqual(0);
this.Log().Info("Files in release package:");
pkg.GetFiles().ForEach(x => this.Log().Info(x.Path));
var filesToLookFor = new[] {
"xunit.assert.dll", // Tests => Xunit => Xunit.Assert
"NuGet.Core.dll", // Tests => NuGet
"Squirrel.Tests.dll",
};
filesToLookFor.ForEach(name => {
this.Log().Info("Looking for {0}", name);
pkg.GetFiles().Any(y => y.Path.ToLowerInvariant().Contains(name.ToLowerInvariant())).ShouldBeTrue();
});
} finally {
File.Delete(outputPackage);
}
}
[Fact]
public void SpecFileMarkdownRenderingTest()
{
var dontcare = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
var inputSpec = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nuspec");
var fixture = new ReleasePackage(dontcare);
var targetFile = Path.GetTempFileName();
File.Copy(inputSpec, targetFile, true);
try {
var processor = new Func<string, string>(input =>
(new Markdown()).Transform(input));
// NB: For No Reason At All, renderReleaseNotesMarkdown is
// invulnerable to ExposedObject. Whyyyyyyyyy
var renderMinfo = fixture.GetType().GetMethod("renderReleaseNotesMarkdown",
BindingFlags.NonPublic | BindingFlags.Instance);
renderMinfo.Invoke(fixture, new object[] {targetFile, processor});
var doc = XDocument.Load(targetFile);
XNamespace ns = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd";
var relNotesElement = doc.Descendants(ns + "releaseNotes").First();
var htmlText = relNotesElement.Value;
this.Log().Info("HTML Text:\n{0}", htmlText);
htmlText.Contains("## Release Notes").ShouldBeFalse();
} finally {
File.Delete(targetFile);
}
}
[Fact]
public void UsesTheRightVersionOfADependencyWhenMultipleAreInPackages()
{
var outputPackage = Path.GetTempFileName() + ".nupkg";
string outputFile = null;
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "CaliburnMicroDemo.1.0.0.nupkg");
var wrongPackage = "Caliburn.Micro.1.4.1.nupkg";
var wrongPackagePath = IntegrationTestHelper.GetPath("fixtures", wrongPackage);
var rightPackage = "Caliburn.Micro.1.5.2.nupkg";
var rightPackagePath = IntegrationTestHelper.GetPath("fixtures", rightPackage);
try {
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
File.Copy(wrongPackagePath, Path.Combine(sourceDir, wrongPackage), true);
File.Copy(rightPackagePath, Path.Combine(sourceDir, rightPackage), true);
var package = new ReleasePackage(inputPackage);
var outputFileName = package.CreateReleasePackage(outputPackage, sourceDir);
var zipPackage = new ZipPackage(outputFileName);
var fileName = "Caliburn.Micro.dll";
var dependency = zipPackage.GetLibFiles()
.Where(f => f.Path.EndsWith(fileName))
.Single(f => f.TargetFramework == FrameworkTargetVersion.Net40);
outputFile = new FileInfo(Path.Combine(sourceDir, fileName)).FullName;
using (var of = File.Create(outputFile))
{
dependency.GetStream().CopyTo(of);
}
var assemblyName = AssemblyName.GetAssemblyName(outputFile);
Assert.Equal(1, assemblyName.Version.Major);
Assert.Equal(5, assemblyName.Version.Minor);
} finally {
File.Delete(outputPackage);
File.Delete(outputFile);
}
}
[Fact]
public void DependentPackageNotFoundAndThrowsError()
{
string packagesDir;
// use empty packages folder
using (Utility.WithTempDirectory(out packagesDir)) {
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectDependsOnJsonDotNet.1.0.nupkg");
var outputPackage = Path.GetTempFileName() + ".nupkg";
try {
var package = new ReleasePackage(inputPackage);
Assert.Throws<Exception>(() =>
package.CreateReleasePackage(outputPackage, packagesDir));
} finally {
File.Delete(outputPackage);
}
}
}
[Fact]
public void ContentFilesAreIncludedInCreatedPackage()
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectWithContent.1.0.0.0-beta.nupkg");
var outputPackage = Path.GetTempFileName() + ".zip";
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
var fixture = new ReleasePackage(inputPackage);
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
try {
fixture.CreateReleasePackage(outputPackage, sourceDir);
this.Log().Info("Resulting package is at {0}", outputPackage);
var pkg = new ZipPackage(outputPackage);
int refs = pkg.FrameworkAssemblies.Count();
this.Log().Info("Found {0} refs", refs);
refs.ShouldEqual(0);
this.Log().Info("Files in release package:");
var contentFiles = pkg.GetContentFiles();
Assert.Equal(2, contentFiles.Count());
var contentFilePaths = contentFiles.Select(f => f.EffectivePath);
Assert.Contains("some-words.txt", contentFilePaths);
Assert.Contains("dir\\item-in-subdirectory.txt", contentFilePaths);
Assert.Equal(1, pkg.GetLibFiles().Count());
} finally {
File.Delete(outputPackage);
}
}
[Fact]
public void WhenAProjectContainsNet45BinariesItContainsTheNecessaryDependency()
{
var outputPackage = Path.GetTempFileName() + ".nupkg";
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ThisShouldBeANet45Project.1.0.nupkg");
var rightPackage = "Caliburn.Micro.1.5.2.nupkg";
var rightPackagePath = IntegrationTestHelper.GetPath("fixtures", rightPackage);
try {
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
File.Copy(rightPackagePath, Path.Combine(sourceDir, rightPackage), true);
var package = new ReleasePackage(inputPackage);
var outputFileName = package.CreateReleasePackage(outputPackage, sourceDir);
var zipPackage = new ZipPackage(outputFileName);
var dependency = zipPackage.GetLibFiles()
.Where(f => f.Path.EndsWith("Caliburn.Micro.dll"))
.FirstOrDefault(f => f.TargetFramework == FrameworkTargetVersion.Net45);
Assert.NotNull(dependency);
} finally {
File.Delete(outputPackage);
}
}
}
}