Skip to content

Commit a882ccb

Browse files
committed
Change unit tests to target .NET 4.7.2 as well
1 parent feab2fc commit a882ccb

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

RazorEngineCore.Tests/RazorEngineCore.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

RazorEngineCore.Tests/TestCompileAndRun.cs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace 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

Comments
 (0)