1212
1313namespace RazorEngineCore . Tests
1414{
15+ using System . Runtime . InteropServices ;
16+
1517 [ TestClass ]
1618 public class TestCompileAndRun
1719 {
@@ -21,7 +23,7 @@ public void TestCompile()
2123 RazorEngine razorEngine = new RazorEngine ( ) ;
2224 razorEngine . Compile ( "Hello @Model.Name" ) ;
2325 }
24-
26+
2527 [ TestMethod ]
2628 public Task TestCompileAsync ( )
2729 {
@@ -53,7 +55,7 @@ public async Task TestCompileAndRun_HtmlLiteralAsync()
5355 {
5456 Name = "Alex"
5557 } ) ;
56-
58+
5759 Assert . AreEqual ( "<h1>Hello Alex</h1>" , actual ) ;
5860 }
5961
@@ -405,7 +407,7 @@ public async Task TestCompileAndRun_TypedModel2Async()
405407 C = "Alex"
406408 } ) ;
407409 } ) ;
408-
410+
409411 Assert . AreEqual ( "Hello -=Alex=-" , actual ) ;
410412 }
411413
@@ -486,13 +488,7 @@ public static string GetGreeting(string name)
486488 {
487489 CSharpSyntaxTree . ParseText ( greetingClass )
488490 } ,
489- new List < MetadataReference > ( )
490- {
491- MetadataReference . CreateFromFile ( typeof ( object ) . Assembly . Location ) ,
492- MetadataReference . CreateFromFile ( Assembly . Load ( new AssemblyName ( "Microsoft.CSharp" ) ) . Location ) ,
493- MetadataReference . CreateFromFile ( Assembly . Load ( new AssemblyName ( "netstandard" ) ) . Location ) ,
494- MetadataReference . CreateFromFile ( Assembly . Load ( new AssemblyName ( "System.Runtime" ) ) . Location )
495- } ,
491+ GetMetadataReferences ( ) ,
496492 new CSharpCompilationOptions ( OutputKind . DynamicallyLinkedLibrary )
497493 ) ;
498494
@@ -526,8 +522,34 @@ @using TestAssembly
526522<p>Hello, Name!</p>
527523" ;
528524 string actual = await template . RunAsync ( ) ;
529-
525+
530526 Assert . AreEqual ( expected , actual ) ;
531527 }
528+
529+ private static List < MetadataReference > GetMetadataReferences ( )
530+ {
531+ if ( RuntimeInformation . FrameworkDescription . StartsWith (
532+ ".NET Framework" ,
533+ StringComparison . OrdinalIgnoreCase ) )
534+ {
535+ return new List < MetadataReference > ( )
536+ {
537+ MetadataReference . CreateFromFile ( typeof ( object ) . Assembly . Location ) ,
538+ MetadataReference . CreateFromFile ( Assembly . Load ( new AssemblyName ( "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ) ) . Location ) ,
539+ MetadataReference . CreateFromFile ( Assembly . Load (
540+ new AssemblyName (
541+ "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" ) ) . Location ) ,
542+ MetadataReference . CreateFromFile ( typeof ( System . Runtime . GCSettings ) . Assembly . Location )
543+ } ;
544+ }
545+
546+ return new List < MetadataReference > ( )
547+ {
548+ MetadataReference . CreateFromFile ( typeof ( object ) . Assembly . Location ) ,
549+ MetadataReference . CreateFromFile ( Assembly . Load ( new AssemblyName ( "Microsoft.CSharp" ) ) . Location ) ,
550+ MetadataReference . CreateFromFile ( Assembly . Load ( new AssemblyName ( "netstandard" ) ) . Location ) ,
551+ MetadataReference . CreateFromFile ( Assembly . Load ( new AssemblyName ( "System.Runtime" ) ) . Location )
552+ } ;
553+ }
532554 }
533555}
0 commit comments