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,60 @@ 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
+ 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
+
33
84
[ Fact ]
34
85
public void AssembliesAreReferenceAssemblies ( )
35
86
{
@@ -131,5 +182,61 @@ public void PlatformManifestListsAllFiles()
131
182
Assert . True ( Version . TryParse ( parts [ 3 ] , out _ ) , "File version must be convertable to System.Version" ) ;
132
183
} ) ;
133
184
}
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
+ }
134
241
}
135
242
}
0 commit comments