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,10 +27,66 @@ public TargetingPackTests(ITestOutputHelper output)
26
27
{
27
28
_output = output ;
28
29
_expectedRid = TestData . GetSharedFxRuntimeIdentifier ( ) ;
30
+ _targetingPackTfm = "netcoreapp" + TestData . GetSharedFxVersion ( ) . Substring ( 0 , 3 ) ;
29
31
_targetingPackRoot = Path . Combine ( TestData . GetTestDataValue ( "TargetingPackLayoutRoot" ) , "packs" , "Microsoft.AspNetCore.App.Ref" , TestData . GetTestDataValue ( "TargetingPackVersion" ) ) ;
30
32
_isTargetingPackBuilding = bool . Parse ( TestData . GetTestDataValue ( "IsTargetingPackBuilding" ) ) ;
31
33
}
32
34
35
+ [ Fact ]
36
+ public void TargetingPackContainsListedAssemblies ( )
37
+ {
38
+ if ( ! _isTargetingPackBuilding )
39
+ {
40
+ return ;
41
+ }
42
+
43
+ var actualAssemblies = Directory . GetFiles ( Path . Combine ( _targetingPackRoot , "ref" , _targetingPackTfm ) , "*.dll" )
44
+ . Select ( Path . GetFileNameWithoutExtension )
45
+ . ToHashSet ( ) ;
46
+ var listedTargetingPackAssemblies = TestData . ListedTargetingPackAssemblies . Keys . ToHashSet ( ) ;
47
+
48
+ _output . WriteLine ( "==== actual assemblies ====" ) ;
49
+ _output . WriteLine ( string . Join ( '\n ' , actualAssemblies . OrderBy ( i => i ) ) ) ;
50
+ _output . WriteLine ( "==== expected assemblies ====" ) ;
51
+ _output . WriteLine ( string . Join ( '\n ' , listedTargetingPackAssemblies . OrderBy ( i => i ) ) ) ;
52
+
53
+ var missing = listedTargetingPackAssemblies . Except ( actualAssemblies ) ;
54
+ var unexpected = actualAssemblies . Except ( listedTargetingPackAssemblies ) ;
55
+
56
+ _output . WriteLine ( "==== missing assemblies from the framework ====" ) ;
57
+ _output . WriteLine ( string . Join ( '\n ' , missing ) ) ;
58
+ _output . WriteLine ( "==== unexpected assemblies in the framework ====" ) ;
59
+ _output . WriteLine ( string . Join ( '\n ' , unexpected ) ) ;
60
+
61
+ Assert . Empty ( missing ) ;
62
+ Assert . Empty ( unexpected ) ;
63
+ }
64
+
65
+ [ Fact ]
66
+ public void RefAssembliesHaveExpectedAssemblyVersions ( )
67
+ {
68
+ if ( ! _isTargetingPackBuilding )
69
+ {
70
+ return ;
71
+ }
72
+
73
+ IEnumerable < string > dlls = Directory . GetFiles ( Path . Combine ( _targetingPackRoot , "ref" , _targetingPackTfm ) , "*.dll" , SearchOption . AllDirectories ) ;
74
+ Assert . NotEmpty ( dlls ) ;
75
+
76
+ Assert . All ( dlls , path =>
77
+ {
78
+ var fileName = Path . GetFileNameWithoutExtension ( path ) ;
79
+ var assemblyName = AssemblyName . GetAssemblyName ( path ) ;
80
+ using var fileStream = File . OpenRead ( path ) ;
81
+ using var peReader = new PEReader ( fileStream , PEStreamOptions . Default ) ;
82
+ var reader = peReader . GetMetadataReader ( MetadataReaderOptions . Default ) ;
83
+ var assemblyDefinition = reader . GetAssemblyDefinition ( ) ;
84
+
85
+ TestData . ListedTargetingPackAssemblies . TryGetValue ( fileName , out var expectedVersion ) ;
86
+ Assert . Equal ( expectedVersion , assemblyDefinition . Version . ToString ( ) ) ;
87
+ } ) ;
88
+ }
89
+
33
90
[ Fact ]
34
91
public void AssembliesAreReferenceAssemblies ( )
35
92
{
@@ -131,5 +188,61 @@ public void PlatformManifestListsAllFiles()
131
188
Assert . True ( Version . TryParse ( parts [ 3 ] , out _ ) , "File version must be convertable to System.Version" ) ;
132
189
} ) ;
133
190
}
191
+
192
+ [ Fact ]
193
+ public void FrameworkListListsContainsCorrectEntries ( )
194
+ {
195
+ if ( ! _isTargetingPackBuilding )
196
+ {
197
+ return ;
198
+ }
199
+
200
+ var frameworkListPath = Path . Combine ( _targetingPackRoot , "data" , "FrameworkList.xml" ) ;
201
+ var expectedAssemblies = TestData . GetTargetingPackDependencies ( )
202
+ . Split ( ';' , StringSplitOptions . RemoveEmptyEntries )
203
+ . ToHashSet ( ) ;
204
+ expectedAssemblies . Remove ( "aspnetcorev2_inprocess" ) ;
205
+
206
+ AssertEx . FileExists ( frameworkListPath ) ;
207
+
208
+ var frameworkListDoc = XDocument . Load ( frameworkListPath ) ;
209
+ var frameworkListEntries = frameworkListDoc . Root . Descendants ( ) ;
210
+
211
+ _output . WriteLine ( "==== file contents ====" ) ;
212
+ _output . WriteLine ( string . Join ( '\n ' , frameworkListEntries . Select ( i => i . Attribute ( "Path" ) . Value ) . OrderBy ( i => i ) ) ) ;
213
+ _output . WriteLine ( "==== expected assemblies ====" ) ;
214
+ _output . WriteLine ( string . Join ( '\n ' , expectedAssemblies . OrderBy ( i => i ) ) ) ;
215
+
216
+ var actualAssemblies = frameworkListEntries
217
+ . Select ( i =>
218
+ {
219
+ var fileName = i . Attribute ( "Path" ) . Value ;
220
+ return fileName . EndsWith ( ".dll" , StringComparison . Ordinal )
221
+ ? fileName . Substring ( 0 , fileName . Length - 4 )
222
+ : fileName ;
223
+ } )
224
+ . ToHashSet ( ) ;
225
+
226
+ var missing = expectedAssemblies . Except ( actualAssemblies ) ;
227
+ var unexpected = actualAssemblies . Except ( expectedAssemblies ) ;
228
+
229
+ _output . WriteLine ( "==== missing assemblies from the framework list ====" ) ;
230
+ _output . WriteLine ( string . Join ( '\n ' , missing ) ) ;
231
+ _output . WriteLine ( "==== unexpected assemblies in the framework list ====" ) ;
232
+ _output . WriteLine ( string . Join ( '\n ' , unexpected ) ) ;
233
+
234
+ Assert . Empty ( missing ) ;
235
+ Assert . Empty ( unexpected ) ;
236
+
237
+ Assert . All ( frameworkListEntries , i =>
238
+ {
239
+ var assemblyPath = i . Attribute ( "Path" ) . Value ;
240
+ var assemblyVersion = i . Attribute ( "AssemblyVersion" ) . Value ;
241
+ var fileVersion = i . Attribute ( "FileVersion" ) . Value ;
242
+
243
+ Assert . True ( Version . TryParse ( assemblyVersion , out _ ) , $ "{ assemblyPath } has assembly version { assemblyVersion } . Assembly version must be convertable to System.Version") ;
244
+ Assert . True ( Version . TryParse ( fileVersion , out _ ) , $ "{ assemblyPath } has file version { fileVersion } . File version must be convertable to System.Version") ;
245
+ } ) ;
246
+ }
134
247
}
135
248
}
0 commit comments