1+ using Microsoft . CodeAnalysis ;
12using Microsoft . CodeAnalysis . CSharp ;
23using System ;
34using System . IO ;
@@ -9,83 +10,66 @@ namespace Basic.Reference.Assemblies.UnitTests
910 public class SanityUnitTests
1011 {
1112 [ Fact ]
12- public void NetCoreApp31Tests ( )
13- {
14- foreach ( var portableRef in NetCoreApp31 . All )
15- {
16- Assert . NotNull ( portableRef ) ;
17- }
18- Assert . True ( NetCoreApp31 . All . Count ( ) > 50 ) ;
19- }
20-
21- [ Fact ]
22- public void NetCoreApp31Compilation ( )
13+ public void AllCanCompile ( )
2314 {
2415 var source = @"
2516using System;
2617
27- class Program
18+ public class C
2819{
20+ public Exception Exception;
21+
2922 static void Main()
3023 {
3124 Console.WriteLine(""Hello World"");
3225 }
3326}" ;
34- var compilation = CSharpCompilation . Create (
35- "Example" ,
36- new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
37- references : NetCoreApp31 . All ) ;
38-
39- Assert . Empty ( compilation . GetDiagnostics ( ) ) ;
40- using var stream = new MemoryStream ( ) ;
41- var emitResult = compilation . Emit ( stream ) ;
42- Assert . True ( emitResult . Success ) ;
43- Assert . Empty ( emitResult . Diagnostics ) ;
44- }
4527
46- [ Fact ]
47- public void Net50Tests ( )
48- {
49- foreach ( var portableRef in Net50 . All )
28+ foreach ( var kind in Enum . GetValues < ReferenceAssemblyKind > ( ) )
5029 {
51- Assert . NotNull ( portableRef ) ;
30+ var compilation = CSharpCompilation . Create (
31+ "Example" ,
32+ new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
33+ references : ReferenceAssemblies . Get ( kind ) ) ;
34+
35+ Assert . Empty ( compilation . GetDiagnostics ( ) ) ;
36+ using var stream = new MemoryStream ( ) ;
37+ var emitResult = compilation . Emit ( stream ) ;
38+ Assert . True ( emitResult . Success ) ;
39+ Assert . Empty ( emitResult . Diagnostics ) ;
5240 }
53- Assert . True ( Net50 . All . Count ( ) > 50 ) ;
5441 }
5542
5643 [ Fact ]
57- public void Net50Compilation ( )
44+ public void AllCanCompile2 ( )
5845 {
5946 var source = @"
6047using System;
6148
62- class Program
49+ public class C
6350{
51+ public Exception Exception;
52+
6453 static void Main()
6554 {
6655 Console.WriteLine(""Hello World"");
6756 }
6857}" ;
69- var compilation = CSharpCompilation . Create (
70- "Example" ,
71- new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
72- references : Net50 . All ) ;
7358
74- Assert . Empty ( compilation . GetDiagnostics ( ) ) ;
75- using var stream = new MemoryStream ( ) ;
76- var emitResult = compilation . Emit ( stream ) ;
77- Assert . True ( emitResult . Success ) ;
78- Assert . Empty ( emitResult . Diagnostics ) ;
79- }
80-
81- [ Fact ]
82- public void NetStandard20Tests ( )
83- {
84- foreach ( var portableRef in NetStandard20 . All )
59+ foreach ( var kind in Enum . GetValues < ReferenceAssemblyKind > ( ) )
8560 {
86- Assert . NotNull ( portableRef ) ;
61+ var compilation = CSharpCompilation . Create (
62+ "Example" ,
63+ new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
64+ references : Array . Empty < MetadataReference > ( ) ) ;
65+ compilation = compilation . WithReferenceAssemblies ( kind ) ;
66+
67+ Assert . Empty ( compilation . GetDiagnostics ( ) ) ;
68+ using var stream = new MemoryStream ( ) ;
69+ var emitResult = compilation . Emit ( stream ) ;
70+ Assert . True ( emitResult . Success ) ;
71+ Assert . Empty ( emitResult . Diagnostics ) ;
8772 }
88- Assert . True ( NetStandard20 . All . Count ( ) > 50 ) ;
8973 }
9074 }
9175}
0 commit comments