parent
e5da44a82f
commit
f4a86f5511
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||
{
|
||||
public static class MvcRazorDiagnosticSourceExtensions
|
||||
{
|
||||
public static void BeforeViewPage(
|
||||
this DiagnosticSource diagnosticSource,
|
||||
IRazorPage page,
|
||||
ViewContext viewContext)
|
||||
{
|
||||
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage"))
|
||||
{
|
||||
diagnosticSource.Write(
|
||||
"Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage",
|
||||
new
|
||||
{
|
||||
page = page,
|
||||
viewContext = viewContext,
|
||||
actionDescriptor = viewContext.ActionDescriptor,
|
||||
httpContext = viewContext.HttpContext,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void AfterViewPage(
|
||||
this DiagnosticSource diagnosticSource,
|
||||
IRazorPage page,
|
||||
ViewContext viewContext)
|
||||
{
|
||||
if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.AfterViewPage"))
|
||||
{
|
||||
diagnosticSource.Write(
|
||||
"Microsoft.AspNetCore.Mvc.Razor.AfterViewPage",
|
||||
new
|
||||
{
|
||||
page = page,
|
||||
viewContext = viewContext,
|
||||
actionDescriptor = viewContext.ActionDescriptor,
|
||||
httpContext = viewContext.HttpContext,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Razor.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor
|
||||
|
|
@ -23,6 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
private readonly IRazorViewEngine _viewEngine;
|
||||
private readonly IRazorPageActivator _pageActivator;
|
||||
private readonly HtmlEncoder _htmlEncoder;
|
||||
private readonly DiagnosticSource _diagnosticSource;
|
||||
private IViewBufferScope _bufferScope;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -34,12 +36,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
/// </param>
|
||||
/// <param name="razorPage">The <see cref="IRazorPage"/> instance to execute.</param>
|
||||
/// <param name="htmlEncoder">The HTML encoder.</param>
|
||||
/// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
|
||||
public RazorView(
|
||||
IRazorViewEngine viewEngine,
|
||||
IRazorPageActivator pageActivator,
|
||||
IReadOnlyList<IRazorPage> viewStartPages,
|
||||
IRazorPage razorPage,
|
||||
HtmlEncoder htmlEncoder)
|
||||
HtmlEncoder htmlEncoder,
|
||||
DiagnosticSource diagnosticSource)
|
||||
{
|
||||
if (viewEngine == null)
|
||||
{
|
||||
|
|
@ -66,11 +70,17 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
throw new ArgumentNullException(nameof(htmlEncoder));
|
||||
}
|
||||
|
||||
if (diagnosticSource == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(diagnosticSource));
|
||||
}
|
||||
|
||||
_viewEngine = viewEngine;
|
||||
_pageActivator = pageActivator;
|
||||
ViewStartPages = viewStartPages;
|
||||
RazorPage = razorPage;
|
||||
_htmlEncoder = htmlEncoder;
|
||||
_diagnosticSource = diagnosticSource;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -152,11 +162,21 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
}
|
||||
}
|
||||
|
||||
private Task RenderPageCoreAsync(IRazorPage page, ViewContext context)
|
||||
private async Task RenderPageCoreAsync(IRazorPage page, ViewContext context)
|
||||
{
|
||||
page.ViewContext = context;
|
||||
_pageActivator.Activate(page, context);
|
||||
return page.ExecuteAsync();
|
||||
|
||||
_diagnosticSource.BeforeViewPage(page, context);
|
||||
|
||||
try
|
||||
{
|
||||
await page.ExecuteAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_diagnosticSource.AfterViewPage(page, context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RenderViewStartsAsync(ViewContext context)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
private readonly ILogger _logger;
|
||||
private readonly RazorViewEngineOptions _options;
|
||||
private readonly RazorProject _razorProject;
|
||||
private readonly DiagnosticSource _diagnosticSource;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RazorViewEngine" />.
|
||||
|
|
@ -54,7 +55,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
HtmlEncoder htmlEncoder,
|
||||
IOptions<RazorViewEngineOptions> optionsAccessor,
|
||||
RazorProject razorProject,
|
||||
ILoggerFactory loggerFactory)
|
||||
ILoggerFactory loggerFactory,
|
||||
DiagnosticSource diagnosticSource)
|
||||
{
|
||||
_options = optionsAccessor.Value;
|
||||
|
||||
|
|
@ -77,6 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
_htmlEncoder = htmlEncoder;
|
||||
_logger = loggerFactory.CreateLogger<RazorViewEngine>();
|
||||
_razorProject = razorProject;
|
||||
_diagnosticSource = diagnosticSource;
|
||||
ViewLookupCache = new MemoryCache(new MemoryCacheOptions());
|
||||
}
|
||||
|
||||
|
|
@ -466,7 +469,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
viewStarts[i] = viewStartItem.PageFactory();
|
||||
}
|
||||
|
||||
var view = new RazorView(this, _pageActivator, viewStarts, page, _htmlEncoder);
|
||||
var view = new RazorView(this, _pageActivator, viewStarts, page, _htmlEncoder, _diagnosticSource);
|
||||
return ViewEngineResult.Found(viewName, view);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
{
|
||||
private readonly IRazorViewEngine _razorViewEngine;
|
||||
private readonly IRazorPageActivator _razorPageActivator;
|
||||
private readonly DiagnosticSource _diagnosticSource;
|
||||
private readonly HtmlEncoder _htmlEncoder;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -42,6 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
_razorViewEngine = razorViewEngine;
|
||||
_htmlEncoder = htmlEncoder;
|
||||
_razorPageActivator = razorPageActivator;
|
||||
_diagnosticSource = diagnosticSource;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -76,7 +78,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
_razorPageActivator,
|
||||
viewStarts,
|
||||
new RazorPageAdapter(result.Page),
|
||||
_htmlEncoder);
|
||||
_htmlEncoder,
|
||||
_diagnosticSource);
|
||||
|
||||
return ExecuteAsync(viewContext, result.ContentType, result.StatusCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -1350,7 +1351,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Test
|
|||
new HtmlTestEncoder(),
|
||||
GetOptionsAccessor(expanders: null),
|
||||
new FileProviderRazorProject(new TestFileProvider()),
|
||||
loggerFactory);
|
||||
loggerFactory,
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
|
||||
// Act
|
||||
var result = viewEngine.CreateCacheResult(null, relativePath, false);
|
||||
|
|
@ -1881,7 +1883,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Test
|
|||
IRazorPageFactoryProvider pageFactory,
|
||||
IOptions<RazorViewEngineOptions> optionsAccessor,
|
||||
RazorProject razorProject)
|
||||
: base(pageFactory, Mock.Of<IRazorPageActivator>(), new HtmlTestEncoder(), optionsAccessor, razorProject, NullLoggerFactory.Instance)
|
||||
: base(pageFactory, Mock.Of<IRazorPageActivator>(), new HtmlTestEncoder(), optionsAccessor, razorProject, NullLoggerFactory.Instance, new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -45,7 +46,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
var expected = viewContext.Writer;
|
||||
|
||||
|
|
@ -74,7 +76,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
activator.Object,
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
|
||||
var viewContext = CreateViewContext(view);
|
||||
var expectedWriter = viewContext.Writer;
|
||||
|
|
@ -95,6 +98,55 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Assert.Same(expectedWriter, viewContext.Writer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RenderAsync_AsPartial_ActivatesViews_WritesBeforeAndAfterRazorViewEventDiagnostics()
|
||||
{
|
||||
// Arrange
|
||||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());
|
||||
var page = new TestableRazorPageForDiagnostics(v =>
|
||||
{
|
||||
// viewData is assigned to ViewContext by the activator
|
||||
Assert.Same(viewData, v.ViewContext.ViewData);
|
||||
});
|
||||
var activator = new Mock<IRazorPageActivator>();
|
||||
|
||||
var adapter = new TestDiagnosticListener();
|
||||
var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor");
|
||||
diagnosticSource.SubscribeWithAdapter(adapter);
|
||||
|
||||
var view = new RazorView(
|
||||
Mock.Of<IRazorViewEngine>(),
|
||||
activator.Object,
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder(),
|
||||
diagnosticSource);
|
||||
|
||||
var viewContext = CreateViewContext(view);
|
||||
var expectedWriter = viewContext.Writer;
|
||||
activator
|
||||
.Setup(a => a.Activate(page, It.IsAny<ViewContext>()))
|
||||
.Callback((IRazorPage p, ViewContext c) =>
|
||||
{
|
||||
Assert.Same(c, viewContext);
|
||||
c.ViewData = viewData;
|
||||
})
|
||||
.Verifiable();
|
||||
|
||||
// Act
|
||||
await view.RenderAsync(viewContext);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(adapter.BeforeViewPage?.Page);
|
||||
Assert.NotNull(adapter.BeforeViewPage?.ViewContext);
|
||||
Assert.NotNull(adapter.BeforeViewPage?.ActionDescriptor);
|
||||
Assert.NotNull(adapter.BeforeViewPage?.HttpContext);
|
||||
Assert.NotNull(adapter.AfterViewPage?.Page);
|
||||
Assert.NotNull(adapter.AfterViewPage?.ViewContext);
|
||||
Assert.NotNull(adapter.AfterViewPage?.ActionDescriptor);
|
||||
Assert.NotNull(adapter.AfterViewPage?.HttpContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ViewContext_ExecutingPagePath_ReturnsPathOfRazorPageBeingExecuted()
|
||||
{
|
||||
|
|
@ -143,7 +195,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
activator,
|
||||
new[] { viewStart },
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
|
||||
var viewContext = CreateViewContext(view);
|
||||
var expectedWriter = viewContext.Writer;
|
||||
|
|
@ -169,7 +222,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
activator.Object,
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -216,7 +270,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -240,7 +295,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
var original = viewContext.Writer;
|
||||
|
||||
|
|
@ -265,7 +321,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
var original = viewContext.Writer;
|
||||
|
||||
|
|
@ -293,7 +350,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
activator.Object,
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -348,7 +406,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
activator.Object,
|
||||
new[] { viewStart1, viewStart2 },
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -391,7 +450,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var context = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -444,7 +504,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new[] { viewStart },
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var context = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -477,7 +538,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewEngine
|
||||
.Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath))
|
||||
|
|
@ -519,7 +581,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewEngine
|
||||
.Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath))
|
||||
|
|
@ -563,7 +626,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewEngine
|
||||
.Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath))
|
||||
|
|
@ -638,7 +702,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
activator.Object,
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -678,7 +743,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -744,7 +810,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -812,7 +879,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -874,7 +942,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -942,7 +1011,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -976,7 +1046,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -1043,7 +1114,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1116,7 +1188,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1156,7 +1229,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -1209,7 +1283,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -1278,7 +1353,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1335,7 +1411,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1389,7 +1466,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1419,7 +1497,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -1465,7 +1544,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new IRazorPage[0],
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act and Assert
|
||||
|
|
@ -1509,7 +1589,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new[] { viewStart1, viewStart2 },
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1566,7 +1647,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new[] { viewStart1, viewStart2 },
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1610,7 +1692,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new[] { viewStart1, viewStart2 },
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1651,7 +1734,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
new[] { viewStart1, viewStart2 },
|
||||
page,
|
||||
new HtmlTestEncoder());
|
||||
new HtmlTestEncoder(),
|
||||
new DiagnosticListener("Microsoft.AspNetCore.Mvc.Razor"));
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
// Act
|
||||
|
|
@ -1678,6 +1762,28 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
new HtmlHelperOptions());
|
||||
}
|
||||
|
||||
public class TestableRazorPageForDiagnostics : RazorPage
|
||||
{
|
||||
private readonly Action<TestableRazorPageForDiagnostics> _executeAction;
|
||||
|
||||
public TestableRazorPageForDiagnostics(Action<TestableRazorPageForDiagnostics> executeAction)
|
||||
{
|
||||
_executeAction = executeAction;
|
||||
HtmlEncoder = new HtmlTestEncoder();
|
||||
}
|
||||
|
||||
public void RenderBodyPublic()
|
||||
{
|
||||
Write(RenderBody());
|
||||
}
|
||||
|
||||
public override Task ExecuteAsync()
|
||||
{
|
||||
_executeAction(this);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
|
||||
private class TestableRazorPage : RazorPage
|
||||
{
|
||||
private readonly Action<TestableRazorPage> _executeAction;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc
|
||||
{
|
||||
public interface IProxyPage
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -221,6 +221,58 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
};
|
||||
}
|
||||
|
||||
public class OnBeforeViewPageEventData
|
||||
{
|
||||
public IProxyPage Page { get; set; }
|
||||
public IProxyViewContext ViewContext { get; set; }
|
||||
public IProxyActionDescriptor ActionDescriptor { get; set; }
|
||||
public IProxyHttpContext HttpContext { get; set; }
|
||||
}
|
||||
|
||||
public OnBeforeViewPageEventData BeforeViewPage { get; set; }
|
||||
|
||||
[DiagnosticName("Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage")]
|
||||
public virtual void OnBeforeViewPage(
|
||||
IProxyPage page,
|
||||
IProxyViewContext viewContext,
|
||||
IProxyActionDescriptor actionDescriptor,
|
||||
IProxyHttpContext httpContext)
|
||||
{
|
||||
BeforeViewPage = new OnBeforeViewPageEventData()
|
||||
{
|
||||
Page = page,
|
||||
ViewContext = viewContext,
|
||||
ActionDescriptor = actionDescriptor,
|
||||
HttpContext = httpContext,
|
||||
};
|
||||
}
|
||||
|
||||
public class OnAfterViewPageEventData
|
||||
{
|
||||
public IProxyPage Page { get; set; }
|
||||
public IProxyViewContext ViewContext { get; set; }
|
||||
public IProxyActionDescriptor ActionDescriptor { get; set; }
|
||||
public IProxyHttpContext HttpContext { get; set; }
|
||||
}
|
||||
|
||||
public OnAfterViewPageEventData AfterViewPage { get; set; }
|
||||
|
||||
[DiagnosticName("Microsoft.AspNetCore.Mvc.Razor.AfterViewPage")]
|
||||
public virtual void OnAfterViewPage(
|
||||
IProxyPage page,
|
||||
IProxyViewContext viewContext,
|
||||
IProxyActionDescriptor actionDescriptor,
|
||||
IProxyHttpContext httpContext)
|
||||
{
|
||||
AfterViewPage = new OnAfterViewPageEventData()
|
||||
{
|
||||
Page = page,
|
||||
ViewContext = viewContext,
|
||||
ActionDescriptor = actionDescriptor,
|
||||
HttpContext = httpContext,
|
||||
};
|
||||
}
|
||||
|
||||
public class OnBeforeViewComponentEventData
|
||||
{
|
||||
public IProxyActionDescriptor ActionDescriptor { get; set; }
|
||||
|
|
|
|||
Loading…
Reference in New Issue