9
9
using System . Reflection . Metadata ;
10
10
using System . Reflection . PortableExecutable ;
11
11
using System . Runtime . CompilerServices ;
12
- using Newtonsoft . Json . Linq ;
12
+ using System . Xml . Linq ;
13
13
using Xunit ;
14
14
using Xunit . Abstractions ;
15
15
@@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore
18
18
public class TargetingPackTests
19
19
{
20
20
private readonly string _expectedRid ;
21
+ private readonly string _targetingPackTfm ;
21
22
private readonly string _targetingPackRoot ;
22
23
private readonly ITestOutputHelper _output ;
23
24
private readonly bool _isTargetingPackBuilding ;
@@ -26,12 +27,62 @@ public TargetingPackTests(ITestOutputHelper output)
26
27
{
27
28
_output = output ;
28
29
_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" ) )
30
32
? Path . Combine ( TestData . GetTestDataValue ( "TargetingPackLayoutRoot" ) , "packs" , "Microsoft.AspNetCore.App.Ref" , TestData . GetTestDataValue ( "TargetingPackVersion" ) )
31
33
: Path . Combine ( Environment . GetEnvironmentVariable ( "HELIX_WORKITEM_ROOT" ) , "Microsoft.AspNetCore.App.Ref" ) ;
32
34
_isTargetingPackBuilding = bool . Parse ( TestData . GetTestDataValue ( "IsTargetingPackBuilding" ) ) ;
33
35
}
34
36
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
+
35
86
[ Fact ]
36
87
public void PackageOverridesContainsCorrectEntries ( )
37
88
{
@@ -75,7 +126,6 @@ public void PackageOverridesContainsCorrectEntries()
75
126
}
76
127
}
77
128
78
-
79
129
[ Fact ]
80
130
public void AssembliesAreReferenceAssemblies ( )
81
131
{
@@ -177,5 +227,61 @@ public void PlatformManifestListsAllFiles()
177
227
Assert . True ( Version . TryParse ( parts [ 3 ] , out _ ) , "File version must be convertable to System.Version" ) ;
178
228
} ) ;
179
229
}
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
+ }
180
286
}
181
287
}
0 commit comments