Skip to content

Commit edd5e67

Browse files
author
John Luo
committed
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 8e52f69 commit edd5e67

File tree

4 files changed

+404
-3
lines changed

4 files changed

+404
-3
lines changed

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

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

9292
<AssemblyAttribute Include="Microsoft.AspNetCore.TestData">

src/Framework/test/SharedFxTests.cs

Lines changed: 24 additions & 1 deletion
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;
@@ -26,6 +25,30 @@ public SharedFxTests(ITestOutputHelper output)
2625
_sharedFxRoot = Path.Combine(TestData.GetTestDataValue("SharedFrameworkLayoutRoot"), "shared", "Microsoft.AspNetCore.App", TestData.GetTestDataValue("RuntimePackageVersion"));
2726
}
2827

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

src/Framework/test/TargetingPackTests.cs

Lines changed: 108 additions & 1 deletion
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,10 +27,60 @@ public TargetingPackTests(ITestOutputHelper output)
2627
{
2728
_output = output;
2829
_expectedRid = TestData.GetSharedFxRuntimeIdentifier();
30+
_targetingPackTfm = "netcoreapp" + TestData.GetSharedFxVersion().Substring(0, 3);
2931
_targetingPackRoot = Path.Combine(TestData.GetTestDataValue("TargetingPackLayoutRoot"), "packs", "Microsoft.AspNetCore.App.Ref", TestData.GetTestDataValue("TargetingPackVersion"));
3032
_isTargetingPackBuilding = bool.Parse(TestData.GetTestDataValue("IsTargetingPackBuilding"));
3133
}
3234

35+
[Fact]
36+
public void TargetingPackContainsListedAssemblies()
37+
{
38+
var actualAssemblies = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll")
39+
.Select(Path.GetFileNameWithoutExtension)
40+
.ToHashSet();
41+
42+
_output.WriteLine("==== actual assemblies ====");
43+
_output.WriteLine(string.Join('\n', actualAssemblies.OrderBy(i => i)));
44+
_output.WriteLine("==== expected assemblies ====");
45+
_output.WriteLine(string.Join('\n', TestData.ListedTargetingPackAssemblies.OrderBy(i => i)));
46+
47+
var missing = TestData.ListedTargetingPackAssemblies.Except(actualAssemblies);
48+
var unexpected = actualAssemblies.Except(TestData.ListedTargetingPackAssemblies);
49+
50+
_output.WriteLine("==== missing assemblies from the framework ====");
51+
_output.WriteLine(string.Join('\n', missing));
52+
_output.WriteLine("==== unexpected assemblies in the framework ====");
53+
_output.WriteLine(string.Join('\n', unexpected));
54+
55+
Assert.Empty(missing);
56+
Assert.Empty(unexpected);
57+
}
58+
59+
[Fact]
60+
public void AssembliesHavePatchVersion0()
61+
{
62+
if (!_isTargetingPackBuilding)
63+
{
64+
return;
65+
}
66+
67+
IEnumerable<string> dlls = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll", SearchOption.AllDirectories);
68+
Assert.NotEmpty(dlls);
69+
70+
Assert.All(dlls, path =>
71+
{
72+
var assemblyName = AssemblyName.GetAssemblyName(path);
73+
using var fileStream = File.OpenRead(path);
74+
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
75+
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
76+
var assemblyDefinition = reader.GetAssemblyDefinition();
77+
78+
Assert.True(
79+
assemblyDefinition.Version.Revision == 0 && assemblyDefinition.Version.Build == 0,
80+
$"{path} has version {assemblyDefinition.Version} should have a 0.0 revision number and build number version, e.g. major.minor.0.0");
81+
});
82+
}
83+
3384
[Fact]
3485
public void AssembliesAreReferenceAssemblies()
3586
{
@@ -131,5 +182,61 @@ public void PlatformManifestListsAllFiles()
131182
Assert.True(Version.TryParse(parts[3], out _), "File version must be convertable to System.Version");
132183
});
133184
}
185+
186+
[Fact]
187+
public void FrameworkListListsContainsCorrectEntries()
188+
{
189+
if (!_isTargetingPackBuilding)
190+
{
191+
return;
192+
}
193+
194+
var frameworkListPath = Path.Combine(_targetingPackRoot, "data", "FrameworkList.xml");
195+
var expectedAssemblies = TestData.GetTargetingPackDependencies()
196+
.Split(';', StringSplitOptions.RemoveEmptyEntries)
197+
.ToHashSet();
198+
expectedAssemblies.Remove("aspnetcorev2_inprocess");
199+
200+
AssertEx.FileExists(frameworkListPath);
201+
202+
var frameworkListDoc = XDocument.Load(frameworkListPath);
203+
var frameworkListEntries = frameworkListDoc.Root.Descendants();
204+
205+
_output.WriteLine("==== file contents ====");
206+
_output.WriteLine(string.Join('\n', frameworkListEntries.Select(i => i.Attribute("Path").Value).OrderBy(i => i)));
207+
_output.WriteLine("==== expected assemblies ====");
208+
_output.WriteLine(string.Join('\n', expectedAssemblies.OrderBy(i => i)));
209+
210+
var actualAssemblies = frameworkListEntries
211+
.Select(i =>
212+
{
213+
var fileName = i.Attribute("Path").Value;
214+
return fileName.EndsWith(".dll", StringComparison.Ordinal)
215+
? fileName.Substring(0, fileName.Length - 4)
216+
: fileName;
217+
})
218+
.ToHashSet();
219+
220+
var missing = expectedAssemblies.Except(actualAssemblies);
221+
var unexpected = actualAssemblies.Except(expectedAssemblies);
222+
223+
_output.WriteLine("==== missing assemblies from the framework list ====");
224+
_output.WriteLine(string.Join('\n', missing));
225+
_output.WriteLine("==== unexpected assemblies in the framework list ====");
226+
_output.WriteLine(string.Join('\n', unexpected));
227+
228+
Assert.Empty(missing);
229+
Assert.Empty(unexpected);
230+
231+
Assert.All(frameworkListEntries, i =>
232+
{
233+
var assemblyPath = i.Attribute("Path").Value;
234+
var assemblyVersion = i.Attribute("AssemblyVersion").Value;
235+
var fileVersion = i.Attribute("FileVersion").Value;
236+
237+
Assert.True(Version.TryParse(assemblyVersion, out _), $"{assemblyPath} has assembly version {assemblyVersion}. Assembly version must be convertable to System.Version");
238+
Assert.True(Version.TryParse(fileVersion, out _), $"{assemblyPath} has file version {fileVersion}. File version must be convertable to System.Version");
239+
});
240+
}
134241
}
135242
}

0 commit comments

Comments
 (0)