11using Microsoft . CodeAnalysis ;
22using Microsoft . CodeAnalysis . CSharp ;
33using System ;
4+ using System . Collections . Generic ;
45using System . IO ;
56using System . Linq ;
67using Xunit ;
@@ -9,8 +10,9 @@ namespace Basic.Reference.Assemblies.UnitTests
910{
1011 public class SanityUnitTests
1112 {
12- [ Fact ]
13- public void AllCanCompile ( )
13+ [ Theory ]
14+ [ MemberData ( nameof ( TestData . ApplicationReferences ) , MemberType = typeof ( TestData ) ) ]
15+ public void AllAppCanCompile ( string targetFramework , IEnumerable < MetadataReference > references )
1416 {
1517 var source = @"
1618using System;
@@ -25,30 +27,22 @@ static void Main()
2527 }
2628}" ;
2729
28- foreach ( var kind in Enum . GetValues < ReferenceAssemblyKind > ( ) )
29- {
30- var compilation = CSharpCompilation . Create (
31- "Example" ,
32- new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
33- references : ReferenceAssemblies . Get ( kind ) ) ;
34-
35- // NetStandard1.3 comes with several no warn options we need here
36- if ( kind == ReferenceAssemblyKind . NetStandard13 )
37- {
38- compilation = NoWarn ( compilation , "CS1702" ) ;
39- compilation = NoWarn ( compilation , "CS1701" ) ;
40- }
30+ var compilation = CSharpCompilation . Create (
31+ "Example" ,
32+ new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
33+ references : references ) ;
4134
42- Assert . Empty ( compilation . GetDiagnostics ( ) ) ;
43- using var stream = new MemoryStream ( ) ;
44- var emitResult = compilation . Emit ( stream ) ;
45- Assert . True ( emitResult . Success ) ;
46- Assert . Empty ( emitResult . Diagnostics ) ;
47- }
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 ) ;
40+ Assert . NotEmpty ( targetFramework ) ;
4841 }
4942
50- [ Fact ]
51- public void AllCanCompile2 ( )
43+ [ Theory ]
44+ [ MemberData ( nameof ( TestData . AllReferences ) , MemberType = typeof ( TestData ) ) ]
45+ public void AllLibraryCanCompile ( string targetFramework , IEnumerable < MetadataReference > references )
5246 {
5347 var source = @"
5448using System;
@@ -63,27 +57,25 @@ static void Main()
6357 }
6458}" ;
6559
66- foreach ( var kind in Enum . GetValues < ReferenceAssemblyKind > ( ) )
67- {
68- var compilation = CSharpCompilation . Create (
69- "Example" ,
70- new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
71- references : Array . Empty < MetadataReference > ( ) ) ;
72- compilation = compilation . WithReferenceAssemblies ( kind ) ;
60+ var options = new CSharpCompilationOptions ( OutputKind . DynamicallyLinkedLibrary ) ;
61+ var compilation = CSharpCompilation . Create (
62+ "Example" ,
63+ new [ ] { CSharpSyntaxTree . ParseText ( source ) } ,
64+ options : options ,
65+ references : references ) ;
7366
74- // NetStandard1.3 comes with several no warn options we need here
75- if ( kind == ReferenceAssemblyKind . NetStandard13 )
76- {
77- compilation = NoWarn ( compilation , "CS1702" ) ;
78- compilation = NoWarn ( compilation , "CS1701" ) ;
79- }
80-
81- Assert . Empty ( compilation . GetDiagnostics ( ) ) ;
82- using var stream = new MemoryStream ( ) ;
83- var emitResult = compilation . Emit ( stream ) ;
84- Assert . True ( emitResult . Success ) ;
85- Assert . Empty ( emitResult . Diagnostics ) ;
67+ // NetStandard1.3 comes with several no warn options we need here
68+ if ( targetFramework == "netstandard1.3" )
69+ {
70+ compilation = NoWarn ( compilation , "CS1702" ) ;
71+ compilation = NoWarn ( compilation , "CS1701" ) ;
8672 }
73+
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 ) ;
8779 }
8880
8981 private static CSharpCompilation NoWarn ( CSharpCompilation compilation , string id )
0 commit comments