本文整理汇总了C#中TestableRazorPage类的典型用法代码示例。如果您正苦于以下问题:C# TestableRazorPage类的具体用法?C# TestableRazorPage怎么用?C# TestableRazorPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestableRazorPage类属于命名空间,在下文中一共展示了TestableRazorPage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RenderAsync_AsPartial_ActivatesViews_WithThePassedInViewContext
public async Task RenderAsync_AsPartial_ActivatesViews_WithThePassedInViewContext()
{
// Arrange
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
var page = new TestableRazorPage(v =>
{
// viewData is assigned to ViewContext by the activator
Assert.Same(viewData, v.ViewContext.ViewData);
});
var activator = new Mock<IRazorPageActivator>();
var view = new RazorView(Mock.Of<IRazorViewEngine>(),
activator.Object,
CreateViewStartProvider(),
page,
isPartial: true);
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
activator.Verify();
Assert.Same(expectedWriter, viewContext.Writer);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:33,代码来源:RazorViewTest.cs
示例2: RenderAsync_AsPartial_BuffersOutput
public async Task RenderAsync_AsPartial_BuffersOutput()
{
// Arrange
TextWriter actual = null;
var page = new TestableRazorPage(v =>
{
actual = v.Output;
v.HtmlEncoder = new CommonTestEncoder();
v.Write("Hello world");
});
var view = new RazorView(Mock.Of<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
isPartial: true);
var viewContext = CreateViewContext(view);
var expected = viewContext.Writer;
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.NotSame(expected, actual);
Assert.IsAssignableFrom<IBufferedTextWriter>(actual);
Assert.Equal("HtmlEncode[[Hello world]]", viewContext.Writer.ToString());
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:26,代码来源:RazorViewTest.cs
示例3: RenderAsync_WithoutHierarchy_ActivatesViews
public async Task RenderAsync_WithoutHierarchy_ActivatesViews()
{
// Arrange
var page = new TestableRazorPage(v => { });
var activator = new Mock<IRazorPageActivator>();
activator.Setup(a => a.Activate(page, It.IsAny<ViewContext>()))
.Verifiable();
var view = new RazorView(Mock.Of<IRazorPageFactory>(),
activator.Object,
CreateViewStartProvider(),
page,
executeViewHierarchy: false);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
activator.Verify();
}
开发者ID:Nakro,项目名称:Mvc,代码行数:20,代码来源:RazorViewTest.cs
示例4: RenderAsync_WithoutHierarchy_DoesNotCreateOutputBuffer
public async Task RenderAsync_WithoutHierarchy_DoesNotCreateOutputBuffer()
{
// Arrange
TextWriter actual = null;
var page = new TestableRazorPage(v =>
{
actual = v.Output;
v.Write("Hello world");
});
var view = new RazorView(Mock.Of<IRazorPageFactory>(),
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
executeViewHierarchy: false);
var viewContext = CreateViewContext(view);
var expected = viewContext.Writer;
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.Same(expected, actual);
Assert.Equal("Hello world", expected.ToString());
}
开发者ID:Nakro,项目名称:Mvc,代码行数:24,代码来源:RazorViewTest.cs
示例5: RenderAsync_ThrowsIfSectionsWereDefinedButNotRendered
public async Task RenderAsync_ThrowsIfSectionsWereDefinedButNotRendered()
{
// Arrange
var page = new TestableRazorPage(v =>
{
v.DefineSection("head", _nullRenderAsyncDelegate);
v.Layout = LayoutPath;
v.DefineSection("foot", _nullRenderAsyncDelegate);
});
var layout = new TestableRazorPage(v =>
{
v.RenderBodyPublic();
})
{
Path = LayoutPath
};
var viewEngine = new Mock<IRazorViewEngine>();
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), LayoutPath))
.Returns(new RazorPageResult(LayoutPath, layout));
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
// Act and Assert
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => view.RenderAsync(viewContext));
Assert.Equal("The following sections have been defined but have not been rendered by the page "
+ $"at '{LayoutPath}': 'head, foot'.", ex.Message);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:32,代码来源:RazorViewTest.cs
示例6: RenderAsync_ThrowsIfLayoutPageCannotBeFound
public async Task RenderAsync_ThrowsIfLayoutPageCannotBeFound()
{
// Arrange
var expected = string.Join(Environment.NewLine,
"The layout view 'Does-Not-Exist-Layout' could not be located. " +
"The following locations were searched:",
"path1",
"path2");
var layoutPath = "Does-Not-Exist-Layout";
var page = new TestableRazorPage(v =>
{
v.Layout = layoutPath;
});
var viewEngine = new Mock<IRazorViewEngine>();
var activator = new Mock<IRazorPageActivator>();
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
Mock.Of<IViewStartProvider>(),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
viewEngine.Setup(v => v.FindPage(viewContext, layoutPath))
.Returns(new RazorPageResult(layoutPath, new[] { "path1", "path2" }))
.Verifiable();
// Act
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => view.RenderAsync(viewContext));
// Assert
Assert.Equal(expected, ex.Message);
viewEngine.Verify();
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:34,代码来源:RazorViewTest.cs
示例7: RenderAsync_ExecutesLayoutPages
public async Task RenderAsync_ExecutesLayoutPages()
{
// Arrange
var htmlEncoder = new CommonTestEncoder();
var htmlEncodedNewLine = htmlEncoder.HtmlEncode(Environment.NewLine);
var expected = "HtmlEncode[[layout-content" +
Environment.NewLine +
"]]head-content" +
htmlEncodedNewLine +
"body-content" +
htmlEncodedNewLine +
"foot-content";
var page = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.WriteLiteral("body-content");
v.Layout = LayoutPath;
v.DefineSection("head", async writer =>
{
await writer.WriteAsync("head-content");
});
v.DefineSection("foot", async writer =>
{
await writer.WriteAsync("foot-content");
});
});
var layout = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.Write("layout-content" + Environment.NewLine);
v.Write(v.RenderSection("head"));
v.Write(Environment.NewLine);
v.RenderBodyPublic();
v.Write(Environment.NewLine);
v.Write(v.RenderSection("foot"));
});
var activator = new Mock<IRazorPageActivator>();
activator.Setup(a => a.Activate(page, It.IsAny<ViewContext>()))
.Verifiable();
activator.Setup(a => a.Activate(layout, It.IsAny<ViewContext>()))
.Verifiable();
var viewEngine = new Mock<IRazorViewEngine>();
var view = new RazorView(viewEngine.Object,
activator.Object,
CreateViewStartProvider(),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
viewEngine.Setup(p => p.FindPage(viewContext, LayoutPath))
.Returns(new RazorPageResult(LayoutPath, layout))
.Verifiable();
// Act
await view.RenderAsync(viewContext);
// Assert
// Verify the activator was invoked for the primary page and layout page.
activator.Verify();
Assert.Equal(expected, viewContext.Writer.ToString());
viewEngine.Verify();
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:63,代码来源:RazorViewTest.cs
示例8: ViewContext_ExecutingPagePath_ReturnsPathOfRazorPageBeingExecuted
public async Task ViewContext_ExecutingPagePath_ReturnsPathOfRazorPageBeingExecuted()
{
// Arrange
var pagePath = "/my/view";
var paths = new List<string>();
var page = new TestableRazorPage(v =>
{
paths.Add(v.ViewContext.ExecutingFilePath);
Assert.Equal(pagePath, v.ViewContext.View.Path);
})
{
Path = pagePath
};
var viewStart = new TestableRazorPage(v =>
{
v.Layout = LayoutPath;
paths.Add(v.ViewContext.ExecutingFilePath);
Assert.Equal(pagePath, v.ViewContext.View.Path);
})
{
Path = "_ViewStart"
};
var layout = new TestableRazorPage(v =>
{
v.RenderBodyPublic();
paths.Add(v.ViewContext.ExecutingFilePath);
Assert.Equal(pagePath, v.ViewContext.View.Path);
})
{
Path = LayoutPath
};
var activator = Mock.Of<IRazorPageActivator>();
var viewEngine = new Mock<IRazorViewEngine>();
viewEngine.Setup(v => v.FindPage(It.IsAny<ActionContext>(), LayoutPath))
.Returns(new RazorPageResult(LayoutPath, layout));
var view = new RazorView(viewEngine.Object,
activator,
CreateViewStartProvider(viewStart),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
var expectedWriter = viewContext.Writer;
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.Equal(new[] { "_ViewStart", pagePath, LayoutPath }, paths);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:53,代码来源:RazorViewTest.cs
示例9: RenderAsync_UsesPageExecutionFeatureFromRequest_ToGetExecutionContext
public async Task RenderAsync_UsesPageExecutionFeatureFromRequest_ToGetExecutionContext()
{
// Arrange
var writer = new StringWriter();
var executed = false;
var feature = new Mock<IPageExecutionListenerFeature>(MockBehavior.Strict);
var pageContext = Mock.Of<IPageExecutionContext>();
feature.Setup(f => f.GetContext("/MyPartialPage.cshtml", It.IsAny<RazorTextWriter>()))
.Returns(pageContext)
.Verifiable();
feature.Setup(f => f.DecorateWriter(It.IsAny<RazorTextWriter>()))
.Returns((RazorTextWriter r) => r)
.Verifiable();
var page = new TestableRazorPage(v =>
{
v.HtmlEncoder = new CommonTestEncoder();
Assert.IsType<RazorTextWriter>(v.Output);
Assert.Same(pageContext, v.PageExecutionContext);
executed = true;
v.Write("Hello world");
});
page.Path = "/MyPartialPage.cshtml";
var view = new RazorView(Mock.Of<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
Mock.Of<IViewStartProvider>(),
page,
isPartial: true);
var viewContext = CreateViewContext(view);
viewContext.Writer = writer;
viewContext.HttpContext.SetFeature<IPageExecutionListenerFeature>(feature.Object);
// Act
await view.RenderAsync(viewContext);
// Assert
feature.Verify();
Assert.True(executed);
Assert.Equal("HtmlEncode[[Hello world]]", viewContext.Writer.ToString());
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:44,代码来源:RazorViewTest.cs
示例10: RenderAsync_ExecutesNestedLayoutPages
public async Task RenderAsync_ExecutesNestedLayoutPages()
{
// Arrange
var htmlEncoder = new CommonTestEncoder();
var expected = "HtmlEncode[[layout-2" +
Environment.NewLine +
"]]bar-content" +
Environment.NewLine +
"HtmlEncode[[layout-1" +
Environment.NewLine +
"]]foo-content" +
Environment.NewLine +
"body-content";
var page = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.DefineSection("foo", async writer =>
{
await writer.WriteLineAsync("foo-content");
});
v.Layout = "~/Shared/Layout1.cshtml";
v.WriteLiteral("body-content");
});
var layout1 = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.Write("layout-1" + Environment.NewLine);
v.Write(v.RenderSection("foo"));
v.DefineSection("bar", writer => writer.WriteLineAsync("bar-content"));
v.RenderBodyPublic();
v.Layout = "~/Shared/Layout2.cshtml";
});
layout1.Path = "~/Shared/Layout1.cshtml";
var layout2 = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.Write("layout-2" + Environment.NewLine);
v.Write(v.RenderSection("bar"));
v.RenderBodyPublic();
});
layout2.Path = "~/Shared/Layout2.cshtml";
var viewEngine = new Mock<IRazorViewEngine>();
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "~/Shared/Layout1.cshtml"))
.Returns(new RazorPageResult("~/Shared/Layout1.cshtml", layout1));
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "~/Shared/Layout2.cshtml"))
.Returns(new RazorPageResult("~/Shared/Layout2.cshtml", layout2));
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
new CommonTestEncoder(),
isPartial: false);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.Equal(expected, viewContext.Writer.ToString());
}
开发者ID:4myBenefits,项目名称:Mvc,代码行数:64,代码来源:RazorViewTest.cs
示例11: RenderAsync_ThrowsIfBodyWasNotRendered
public async Task RenderAsync_ThrowsIfBodyWasNotRendered()
{
// Arrange
var page = new TestableRazorPage(v =>
{
v.Layout = LayoutPath;
});
var layout = new TestableRazorPage(v =>
{
})
{
Path = LayoutPath
};
var viewEngine = new Mock<IRazorViewEngine>();
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), LayoutPath))
.Returns(new RazorPageResult(LayoutPath, layout));
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
// Act and Assert
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => view.RenderAsync(viewContext));
Assert.Equal($"RenderBody has not been called for the page at '{LayoutPath}'.", ex.Message);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:28,代码来源:RazorViewTest.cs
示例12: RenderAsync_AsPartial_ExecutesLayout_ButNotViewStartPages
public async Task RenderAsync_AsPartial_ExecutesLayout_ButNotViewStartPages()
{
// Arrange
var htmlEncoder = new CommonTestEncoder();
var expected = string.Join(Environment.NewLine,
"HtmlEncode[[layout-content",
"]]HtmlEncode[[page-content]]");
var page = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.Layout = LayoutPath;
v.Write("page-content");
});
var layout = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.Write("layout-content" + Environment.NewLine);
v.RenderBodyPublic();
});
var pageFactory = new Mock<IRazorPageFactory>();
pageFactory.Setup(p => p.CreateInstance(LayoutPath))
.Returns(layout);
var viewEngine = new Mock<IRazorViewEngine>();
viewEngine.Setup(v => v.FindPage(It.IsAny<ActionContext>(), LayoutPath))
.Returns(new RazorPageResult(LayoutPath, layout));
var viewStartProvider = CreateViewStartProvider();
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
viewStartProvider,
page,
isPartial: true);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
Mock.Get(viewStartProvider)
.Verify(v => v.GetViewStartPages(It.IsAny<string>()), Times.Never());
Assert.Equal(expected, viewContext.Writer.ToString());
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:44,代码来源:RazorViewTest.cs
示例13: RenderAsync_CreatesOutputBuffer
public async Task RenderAsync_CreatesOutputBuffer()
{
// Arrange
TextWriter actual = null;
var page = new TestableRazorPage(v =>
{
actual = v.Output;
});
var view = new RazorView(Mock.Of<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
var original = viewContext.Writer;
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.IsType<RazorTextWriter>(actual);
Assert.NotSame(original, actual);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:23,代码来源:RazorViewTest.cs
示例14: IsPartial_IsSetToFalse_ForViewStartPageAndLayoutOfAView
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 viewEngine = new Mock<IRazorViewEngine>();
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "/Layout.cshtml"))
.Returns(new RazorPageResult("Layout", layout));
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(viewStart),
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);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:40,代码来源:RazorViewTest.cs
示例15: IsPartial_IsSetToTrue_ForPartialView
public async Task IsPartial_IsSetToTrue_ForPartialView()
{
// Arrange
bool? isPartialPage = null;
var page = new TestableRazorPage(v =>
{
isPartialPage = v.IsPartial;
});
var view = new RazorView(Mock.Of<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
isPartial: true);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.True(isPartialPage.Value);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:21,代码来源:RazorViewTest.cs
示例16: ResettingLayout_InViewStartCausesItToBeResetInPage
public async Task ResettingLayout_InViewStartCausesItToBeResetInPage()
{
// Arrange
var expected = "Layout";
string actual = null;
var page = new TestableRazorPage(v =>
{
Assert.Null(v.Layout);
});
var viewStart1 = new TestableRazorPage(v =>
{
v.Layout = expected;
});
var viewStart2 = new TestableRazorPage(v =>
{
actual = v.Layout;
v.Layout = null;
});
var viewEngine = Mock.Of<IRazorViewEngine>();
var view = new RazorView(viewEngine,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(viewStart1, viewStart2),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.Equal(expected, actual);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:34,代码来源:RazorViewTest.cs
示例17: RenderAsync_CopiesLayoutPropertyFromViewStart
public async Task RenderAsync_CopiesLayoutPropertyFromViewStart()
{
// Arrange
var expectedViewStart = "Layout1";
var expectedPage = "Layout2";
string actualViewStart = null;
string actualPage = null;
var page = new TestableRazorPage(v =>
{
actualPage = v.Layout;
// Clear it out because we don't care about rendering the layout in this test.
v.Layout = null;
});
var viewStart1 = new TestableRazorPage(v =>
{
v.Layout = expectedViewStart;
});
var viewStart2 = new TestableRazorPage(v =>
{
actualViewStart = v.Layout;
v.Layout = expectedPage;
});
var viewEngine = Mock.Of<IRazorViewEngine>();
var view = new RazorView(viewEngine,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(viewStart1, viewStart2),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.Equal(expectedViewStart, actualViewStart);
Assert.Equal(expectedPage, actualPage);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:38,代码来源:RazorViewTest.cs
示例18: RenderAsync_DoesNotSetExecutionContextWhenListenerIsNotRegistered
public async Task RenderAsync_DoesNotSetExecutionContextWhenListenerIsNotRegistered(bool isPartial)
{
// Arrange
var executed = false;
var page = new TestableRazorPage(v =>
{
Assert.Null(v.PageExecutionContext);
executed = true;
});
var view = new RazorView(Mock.Of<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
Mock.Of<IViewStartProvider>(),
page,
isPartial);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.True(executed);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:23,代码来源:RazorViewTest.cs
示例19: RenderAsync_SucceedsIfNestedSectionsAreRendered
public async Task RenderAsync_SucceedsIfNestedSectionsAreRendered()
{
// Arrange
var expected = string.Join(
Environment.NewLine,
"layout-section-content",
"page-section-content");
var htmlEncoder = new CommonTestEncoder();
var page = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.Layout = "~/Shared/Layout1.cshtml";
v.DefineSection("foo", async writer =>
{
await writer.WriteAsync("page-section-content");
});
});
var nestedLayout = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.Layout = "~/Shared/Layout2.cshtml";
v.RenderBodyPublic();
v.DefineSection("foo", async writer =>
{
await writer.WriteLineAsync("layout-section-content");
await v.RenderSectionAsync("foo");
});
})
{
Path = "/Shared/Layout1.cshtml"
};
var baseLayout = new TestableRazorPage(v =>
{
v.HtmlEncoder = htmlEncoder;
v.RenderBodyPublic();
v.RenderSection("foo");
})
{
Path = "/Shared/Layout2.cshtml"
};
var viewEngine = new Mock<IRazorViewEngine>();
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "~/Shared/Layout1.cshtml"))
.Returns(new RazorPageResult("~/Shared/Layout1.cshtml", nestedLayout));
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "~/Shared/Layout2.cshtml"))
.Returns(new RazorPageResult("~/Shared/Layout2.cshtml", baseLayout));
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.Equal(expected, viewContext.Writer.ToString());
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:61,代码来源:RazorViewTest.cs
示例20: RenderAsync_CopiesBufferedContentToOutput
public async Task RenderAsync_CopiesBufferedContentToOutput()
{
// Arrange
var page = new TestableRazorPage(v =>
{
v.WriteLiteral("Hello world");
});
var view = new RazorView(Mock.Of<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(),
page,
isPartial: false);
var viewContext = CreateViewContext(view);
var original = viewContext.Writer;
// Act
await view.RenderAsync(viewContext);
// Assert
Assert.Equal("Hello world", original.ToString());
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:21,代码来源:RazorViewTest.cs
注:本文中的TestableRazorPage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论