Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions RazorEngineCore.Tests/TestCompileAndRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,27 @@ public void TestCompileAndRun_IncludeDebuggingForTypedAnonymous_EnabledDebugging
Assert.AreEqual("<h1>Hello Alex</h1>", actual);
}

[TestMethod]
public void TestCompileAndRun_ProjectEngineBuilderAction_IsInvoked()
{
var builderActionIsInvoked = false;
RazorEngine razorEngine = new RazorEngine();
IRazorEngineCompiledTemplate template = razorEngine.Compile("<h1>Hello @Model.Name</h1>", builder =>
{
builder.IncludeDebuggingInfo();
builder.Options.ProjectEngineBuilderAction = (x) => builderActionIsInvoked = true;
});

template.EnableDebugging();

string actual = template.Run(new
{
Name = "Alex"
});

Assert.IsTrue(builderActionIsInvoked);
}

[TestMethod]
public void TestCompileAndRun_Typed_EnabledDebuggingThrowsException()
{
Expand Down
1 change: 1 addition & 0 deletions RazorEngineCore/RazorEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
(builder) =>
{
builder.SetNamespace(options.TemplateNamespace);
options.ProjectEngineBuilderAction?.Invoke(builder);
});

RazorSourceDocument document = RazorSourceDocument.Create(templateSource, fileName);
Expand Down
2 changes: 2 additions & 0 deletions RazorEngineCore/RazorEngineCompilationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using System;
using Microsoft.AspNetCore.Razor.Language;

namespace RazorEngineCore
{
Expand All @@ -22,6 +23,7 @@ public class RazorEngineCompilationOptions
"System.Collections",
"System.Collections.Generic"
};
public Action<RazorProjectEngineBuilder> ProjectEngineBuilderAction { get; set; }

public RazorEngineCompilationOptions()
{
Expand Down