Skip to content

Commit c83fd89

Browse files
author
John Luo
authored
Add sharedfx and targeting pack tests (#23045)
* Add test for assembly versions * Add test for framework list * Add some hardcoded lists for sharedfx and targeting pack content
1 parent 45e6571 commit c83fd89

File tree

4 files changed

+406
-6
lines changed

4 files changed

+406
-6
lines changed

src/Framework/test/Microsoft.AspNetCore.App.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<ItemGroup>
8888
<AssemblyAttribute Include="Microsoft.AspNetCore.TestData">
8989
<_Parameter1>TargetingPackDependencies</_Parameter1>
90-
<_Parameter2>@(_TargetingPackDependencies)</_Parameter2>
90+
<_Parameter2>@(_TargetingPackDependencies->'%(FileName)')</_Parameter2>
9191
</AssemblyAttribute>
9292

9393
<AspNetCoreTargetingPackDependencies

src/Framework/test/SharedFxTests.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.IO;
76
using System.Linq;
87
using Newtonsoft.Json.Linq;
@@ -25,11 +24,35 @@ public SharedFxTests(ITestOutputHelper output)
2524
_expectedTfm = "net" + TestData.GetSharedFxVersion().Substring(0, 3);
2625
_expectedRid = TestData.GetSharedFxRuntimeIdentifier();
2726
_sharedFxRoot = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNET_RUNTIME_PATH"))
28-
? Path.Combine(TestData.GetTestDataValue("SharedFrameworkLayoutRoot"), "shared", TestData.GetTestDataValue("RuntimePackageVersion"))
27+
? Path.Combine(TestData.GetTestDataValue("SharedFrameworkLayoutRoot"), "shared", "Microsoft.AspNetCore.App", TestData.GetTestDataValue("RuntimePackageVersion"))
2928
: Environment.GetEnvironmentVariable("ASPNET_RUNTIME_PATH");
3029
_expectedVersionFileName = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNET_RUNTIME_PATH")) ? ".version" : "Microsoft.AspNetCore.App.versions.txt";
3130
}
3231

32+
[Fact]
33+
public void SharedFrameworkContainsListedAssemblies()
34+
{
35+
var actualAssemblies = Directory.GetFiles(_sharedFxRoot, "*.dll")
36+
.Select(Path.GetFileNameWithoutExtension)
37+
.ToHashSet();
38+
39+
_output.WriteLine("==== actual assemblies ====");
40+
_output.WriteLine(string.Join('\n', actualAssemblies.OrderBy(i => i)));
41+
_output.WriteLine("==== expected assemblies ====");
42+
_output.WriteLine(string.Join('\n', TestData.ListedSharedFxAssemblies.OrderBy(i => i)));
43+
44+
var missing = TestData.ListedSharedFxAssemblies.Except(actualAssemblies);
45+
var unexpected = actualAssemblies.Except(TestData.ListedSharedFxAssemblies);
46+
47+
_output.WriteLine("==== missing assemblies from the framework ====");
48+
_output.WriteLine(string.Join('\n', missing));
49+
_output.WriteLine("==== unexpected assemblies in the framework ====");
50+
_output.WriteLine(string.Join('\n', unexpected));
51+
52+
Assert.Empty(missing);
53+
Assert.Empty(unexpected);
54+
}
55+
3356
[Fact]
3457
public void SharedFrameworkContainsExpectedFiles()
3558
{

src/Framework/test/TargetingPackTests.cs

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Reflection.Metadata;
1010
using System.Reflection.PortableExecutable;
1111
using System.Runtime.CompilerServices;
12-
using Newtonsoft.Json.Linq;
12+
using System.Xml.Linq;
1313
using Xunit;
1414
using Xunit.Abstractions;
1515

@@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore
1818
public class TargetingPackTests
1919
{
2020
private readonly string _expectedRid;
21+
private readonly string _targetingPackTfm;
2122
private readonly string _targetingPackRoot;
2223
private readonly ITestOutputHelper _output;
2324
private readonly bool _isTargetingPackBuilding;
@@ -26,12 +27,62 @@ public TargetingPackTests(ITestOutputHelper output)
2627
{
2728
_output = output;
2829
_expectedRid = TestData.GetSharedFxRuntimeIdentifier();
29-
_targetingPackRoot = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix"))
30+
_targetingPackTfm = "net" + TestData.GetSharedFxVersion().Substring(0, 3);
31+
_targetingPackRoot = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix"))
3032
? Path.Combine(TestData.GetTestDataValue("TargetingPackLayoutRoot"), "packs", "Microsoft.AspNetCore.App.Ref", TestData.GetTestDataValue("TargetingPackVersion"))
3133
: Path.Combine(Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"), "Microsoft.AspNetCore.App.Ref");
3234
_isTargetingPackBuilding = bool.Parse(TestData.GetTestDataValue("IsTargetingPackBuilding"));
3335
}
3436

37+
[Fact]
38+
public void TargetingPackContainsListedAssemblies()
39+
{
40+
var actualAssemblies = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll")
41+
.Select(Path.GetFileNameWithoutExtension)
42+
.ToHashSet();
43+
44+
_output.WriteLine("==== actual assemblies ====");
45+
_output.WriteLine(string.Join('\n', actualAssemblies.OrderBy(i => i)));
46+
_output.WriteLine("==== expected assemblies ====");
47+
_output.WriteLine(string.Join('\n', TestData.ListedTargetingPackAssemblies.OrderBy(i => i)));
48+
49+
var missing = TestData.ListedTargetingPackAssemblies.Except(actualAssemblies);
50+
var unexpected = actualAssemblies.Except(TestData.ListedTargetingPackAssemblies);
51+
52+
_output.WriteLine("==== missing assemblies from the framework ====");
53+
_output.WriteLine(string.Join('\n', missing));
54+
_output.WriteLine("==== unexpected assemblies in the framework ====");
55+
_output.WriteLine(string.Join('\n', unexpected));
56+
57+
Assert.Empty(missing);
58+
Assert.Empty(unexpected);
59+
}
60+
61+
[Fact]
62+
public void AssembliesHavePatchVersion0()
63+
{
64+
if (!_isTargetingPackBuilding)
65+
{
66+
return;
67+
}
68+
69+
IEnumerable<string> dlls = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll", SearchOption.AllDirectories);
70+
Assert.NotEmpty(dlls);
71+
72+
Assert.All(dlls, path =>
73+
{
74+
var assemblyName = AssemblyName.GetAssemblyName(path);
75+
using var fileStream = File.OpenRead(path);
76+
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
77+
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
78+
var assemblyDefinition = reader.GetAssemblyDefinition();
79+
80+
Assert.True(
81+
assemblyDefinition.Version.Revision == 0 && assemblyDefinition.Version.Build == 0,
82+
$"{path} has version {assemblyDefinition.Version} should have a 0.0 revision number and build number version, e.g. major.minor.0.0");
83+
});
84+
}
85+
3586
[Fact]
3687
public void PackageOverridesContainsCorrectEntries()
3788
{
@@ -75,7 +126,6 @@ public void PackageOverridesContainsCorrectEntries()
75126
}
76127
}
77128

78-
79129
[Fact]
80130
public void AssembliesAreReferenceAssemblies()
81131
{
@@ -177,5 +227,61 @@ public void PlatformManifestListsAllFiles()
177227
Assert.True(Version.TryParse(parts[3], out _), "File version must be convertable to System.Version");
178228
});
179229
}
230+
231+
[Fact]
232+
public void FrameworkListListsContainsCorrectEntries()
233+
{
234+
if (!_isTargetingPackBuilding)
235+
{
236+
return;
237+
}
238+
239+
var frameworkListPath = Path.Combine(_targetingPackRoot, "data", "FrameworkList.xml");
240+
var expectedAssemblies = TestData.GetTargetingPackDependencies()
241+
.Split(';', StringSplitOptions.RemoveEmptyEntries)
242+
.ToHashSet();
243+
expectedAssemblies.Remove("aspnetcorev2_inprocess");
244+
245+
AssertEx.FileExists(frameworkListPath);
246+
247+
var frameworkListDoc = XDocument.Load(frameworkListPath);
248+
var frameworkListEntries = frameworkListDoc.Root.Descendants();
249+
250+
_output.WriteLine("==== file contents ====");
251+
_output.WriteLine(string.Join('\n', frameworkListEntries.Select(i => i.Attribute("Path").Value).OrderBy(i => i)));
252+
_output.WriteLine("==== expected assemblies ====");
253+
_output.WriteLine(string.Join('\n', expectedAssemblies.OrderBy(i => i)));
254+
255+
var actualAssemblies = frameworkListEntries
256+
.Select(i =>
257+
{
258+
var fileName = i.Attribute("Path").Value;
259+
return fileName.EndsWith(".dll", StringComparison.Ordinal)
260+
? fileName.Substring(0, fileName.Length - 4)
261+
: fileName;
262+
})
263+
.ToHashSet();
264+
265+
var missing = expectedAssemblies.Except(actualAssemblies);
266+
var unexpected = actualAssemblies.Except(expectedAssemblies);
267+
268+
_output.WriteLine("==== missing assemblies from the framework list ====");
269+
_output.WriteLine(string.Join('\n', missing));
270+
_output.WriteLine("==== unexpected assemblies in the framework list ====");
271+
_output.WriteLine(string.Join('\n', unexpected));
272+
273+
Assert.Empty(missing);
274+
Assert.Empty(unexpected);
275+
276+
Assert.All(frameworkListEntries, i =>
277+
{
278+
var assemblyPath = i.Attribute("Path").Value;
279+
var assemblyVersion = i.Attribute("AssemblyVersion").Value;
280+
var fileVersion = i.Attribute("FileVersion").Value;
281+
282+
Assert.True(Version.TryParse(assemblyVersion, out _), $"{assemblyPath} has assembly version {assemblyVersion}. Assembly version must be convertable to System.Version");
283+
Assert.True(Version.TryParse(fileVersion, out _), $"{assemblyPath} has file version {fileVersion}. File version must be convertable to System.Version");
284+
});
285+
}
180286
}
181287
}

0 commit comments

Comments
 (0)