|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.IO;
|
| 7 | +using System.IO.Compression; |
7 | 8 | using System.Linq;
|
8 | 9 | using System.Reflection;
|
9 | 10 | using System.Reflection.Metadata;
|
10 | 11 | using System.Reflection.PortableExecutable;
|
| 12 | +using System.Xml.Linq; |
11 | 13 | using Newtonsoft.Json.Linq;
|
12 | 14 | using Xunit;
|
13 | 15 | using Xunit.Abstractions;
|
@@ -209,5 +211,105 @@ public void ItContainsVersionFile()
|
209 | 211 | Assert.Equal(TestData.GetRepositoryCommit(), lines[0]);
|
210 | 212 | Assert.Equal(TestData.GetTestDataValue("RuntimePackageVersion"), lines[1]);
|
211 | 213 | }
|
| 214 | + |
| 215 | + [Fact] |
| 216 | + public void RuntimeListListsContainsCorrectEntries() |
| 217 | + { |
| 218 | + var runtimeListPath = Path.Combine(_sharedFxRoot, "RuntimeList.xml"); |
| 219 | + var expectedAssemblies = TestData.GetSharedFxDependencies() |
| 220 | + .Split(';', StringSplitOptions.RemoveEmptyEntries) |
| 221 | + .ToHashSet(); |
| 222 | + |
| 223 | + AssertEx.FileExists(runtimeListPath); |
| 224 | + |
| 225 | + var runtimeListDoc = XDocument.Load(runtimeListPath); |
| 226 | + var runtimeListEntries = runtimeListDoc.Root.Descendants(); |
| 227 | + |
| 228 | + _output.WriteLine("==== file contents ===="); |
| 229 | + _output.WriteLine(string.Join('\n', runtimeListEntries.Select(i => i.Attribute("Path").Value).OrderBy(i => i))); |
| 230 | + _output.WriteLine("==== expected assemblies ===="); |
| 231 | + _output.WriteLine(string.Join('\n', expectedAssemblies.OrderBy(i => i))); |
| 232 | + |
| 233 | + var actualAssemblies = runtimeListEntries |
| 234 | + .Select(i => |
| 235 | + { |
| 236 | + var filePath = i.Attribute("Path").Value; |
| 237 | + var fileParts = filePath.Split('/'); |
| 238 | + var fileName = fileParts[fileParts.Length - 1]; |
| 239 | + return fileName.EndsWith(".dll", StringComparison.Ordinal) |
| 240 | + ? fileName.Substring(0, fileName.Length - 4) |
| 241 | + : fileName; |
| 242 | + }) |
| 243 | + .ToHashSet(); |
| 244 | + |
| 245 | + var missing = expectedAssemblies.Except(actualAssemblies); |
| 246 | + var unexpected = actualAssemblies.Except(expectedAssemblies); |
| 247 | + |
| 248 | + _output.WriteLine("==== missing assemblies from the runtime list ===="); |
| 249 | + _output.WriteLine(string.Join('\n', missing)); |
| 250 | + _output.WriteLine("==== unexpected assemblies in the runtime list ===="); |
| 251 | + _output.WriteLine(string.Join('\n', unexpected)); |
| 252 | + |
| 253 | + Assert.Empty(missing); |
| 254 | + Assert.Empty(unexpected); |
| 255 | + |
| 256 | + Assert.All(runtimeListEntries, i => |
| 257 | + { |
| 258 | + var assemblyType = i.Attribute("Type").Value; |
| 259 | + var assemblyPath = i.Attribute("Path").Value; |
| 260 | + var fileVersion = i.Attribute("FileVersion").Value; |
| 261 | + |
| 262 | + if (assemblyType.Equals("Managed")) |
| 263 | + { |
| 264 | + var assemblyVersion = i.Attribute("AssemblyVersion").Value; |
| 265 | + Assert.True(Version.TryParse(assemblyVersion, out _), $"{assemblyPath} has assembly version {assemblyVersion}. Assembly version must be convertable to System.Version"); |
| 266 | + } |
| 267 | + |
| 268 | + Assert.True(Version.TryParse(fileVersion, out _), $"{assemblyPath} has file version {fileVersion}. File version must be convertable to System.Version"); |
| 269 | + }); |
| 270 | + } |
| 271 | + |
| 272 | + [Fact] |
| 273 | + public void RuntimeListListsContainsCorrectPaths() |
| 274 | + { |
| 275 | + var runtimePath = Environment.GetEnvironmentVariable("ASPNET_RUNTIME_PATH"); |
| 276 | + if (string.IsNullOrEmpty(runtimePath)) |
| 277 | + { |
| 278 | + return; |
| 279 | + } |
| 280 | + |
| 281 | + var runtimeListPath = Path.Combine(_sharedFxRoot, "RuntimeList.xml"); |
| 282 | + |
| 283 | + AssertEx.FileExists(runtimeListPath); |
| 284 | + |
| 285 | + var runtimeListDoc = XDocument.Load(runtimeListPath); |
| 286 | + var runtimeListEntries = runtimeListDoc.Root.Descendants(); |
| 287 | + |
| 288 | + var sharedFxPath = Path.Combine(Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"), ("Microsoft.AspNetCore.App.Runtime.win-x64." + TestData.GetSharedFxVersion() + ".nupkg")); |
| 289 | + |
| 290 | + ZipArchive archive = ZipFile.OpenRead(sharedFxPath); |
| 291 | + |
| 292 | + var actualPaths = archive.Entries |
| 293 | + .Where(i => i.FullName.EndsWith(".dll")) |
| 294 | + .Select(i => i.FullName).ToHashSet(); |
| 295 | + |
| 296 | + var expectedPaths = runtimeListEntries.Select(i => i.Attribute("Path").Value).ToHashSet(); |
| 297 | + |
| 298 | + _output.WriteLine("==== package contents ===="); |
| 299 | + _output.WriteLine(string.Join('\n', actualPaths.OrderBy(i => i))); |
| 300 | + _output.WriteLine("==== expected assemblies ===="); |
| 301 | + _output.WriteLine(string.Join('\n', expectedPaths.OrderBy(i => i))); |
| 302 | + |
| 303 | + var missing = expectedPaths.Except(actualPaths); |
| 304 | + var unexpected = actualPaths.Except(expectedPaths); |
| 305 | + |
| 306 | + _output.WriteLine("==== missing assemblies from the runtime list ===="); |
| 307 | + _output.WriteLine(string.Join('\n', missing)); |
| 308 | + _output.WriteLine("==== unexpected assemblies in the runtime list ===="); |
| 309 | + _output.WriteLine(string.Join('\n', unexpected)); |
| 310 | + |
| 311 | + Assert.Empty(missing); |
| 312 | + Assert.Empty(unexpected); |
| 313 | + } |
212 | 314 | }
|
213 | 315 | }
|
0 commit comments