parent
ba8b91646a
commit
b8d30f29c6
|
|
@ -44,6 +44,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Layout { get; set; }
|
string Layout { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value that determines if the current instance of <see cref="IRazorPage"/> is being executed
|
||||||
|
/// from a partial view.
|
||||||
|
/// </summary>
|
||||||
|
bool IsPartial { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a <see cref="IPageExecutionContext"/> instance used to instrument the page execution.
|
/// Gets or sets a <see cref="IPageExecutionContext"/> instance used to instrument the page execution.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Layout { get; set; }
|
public string Layout { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool IsPartial { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IPageExecutionContext PageExecutionContext { get; set; }
|
public IPageExecutionContext PageExecutionContext { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
|
|
||||||
private async Task RenderPageCoreAsync(IRazorPage page, ViewContext context)
|
private async Task RenderPageCoreAsync(IRazorPage page, ViewContext context)
|
||||||
{
|
{
|
||||||
|
page.IsPartial = _isPartial;
|
||||||
page.ViewContext = context;
|
page.ViewContext = context;
|
||||||
if (EnableInstrumentation)
|
if (EnableInstrumentation)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -788,6 +788,69 @@ section-content-2";
|
||||||
Assert.Equal(expected, actual);
|
Assert.Equal(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task IsPartial_IsSetToFalse_ForViewStartPageAndLayoutOfAView()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
bool? isPartialPage = null;
|
||||||
|
bool? isPartialLayout = null;
|
||||||
|
bool? isPartialViewStart = null;
|
||||||
|
|
||||||
|
var page = new TestableRazorPage(v =>
|
||||||
|
{
|
||||||
|
isPartialPage = v.IsPartial;
|
||||||
|
});
|
||||||
|
var viewStart = new TestableRazorPage(v =>
|
||||||
|
{
|
||||||
|
v.Layout = "/Layout.cshtml";
|
||||||
|
isPartialViewStart = v.IsPartial;
|
||||||
|
});
|
||||||
|
var layout = new TestableRazorPage(v =>
|
||||||
|
{
|
||||||
|
isPartialLayout = v.IsPartial;
|
||||||
|
v.RenderBodyPublic();
|
||||||
|
});
|
||||||
|
var pageFactory = new Mock<IRazorPageFactory>();
|
||||||
|
pageFactory.Setup(p => p.CreateInstance("/Layout.cshtml"))
|
||||||
|
.Returns(layout);
|
||||||
|
|
||||||
|
var view = new RazorView(pageFactory.Object,
|
||||||
|
Mock.Of<IRazorPageActivator>(),
|
||||||
|
CreateViewStartProvider(viewStart));
|
||||||
|
view.Contextualize(page, isPartial: false);
|
||||||
|
var viewContext = CreateViewContext(view);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await view.RenderAsync(viewContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.False(isPartialPage.Value);
|
||||||
|
Assert.False(isPartialLayout.Value);
|
||||||
|
Assert.False(isPartialViewStart.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task IsPartial_IsSetToTrue_ForPartialView()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
bool? isPartialPage = null;
|
||||||
|
var page = new TestableRazorPage(v =>
|
||||||
|
{
|
||||||
|
isPartialPage = v.IsPartial;
|
||||||
|
});
|
||||||
|
var view = new RazorView(Mock.Of<IRazorPageFactory>(),
|
||||||
|
Mock.Of<IRazorPageActivator>(),
|
||||||
|
CreateViewStartProvider());
|
||||||
|
view.Contextualize(page, isPartial: true);
|
||||||
|
var viewContext = CreateViewContext(view);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await view.RenderAsync(viewContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.True(isPartialPage.Value);
|
||||||
|
}
|
||||||
|
|
||||||
private static TextWriter CreateBufferedWriter()
|
private static TextWriter CreateBufferedWriter()
|
||||||
{
|
{
|
||||||
var mockWriter = new Mock<TextWriter>();
|
var mockWriter = new Mock<TextWriter>();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue