1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.IO;
using Moq;
using Xunit;
namespace System.Web.WebPages.Test
{
public class WebPageContextTest
{
[Fact]
public void CreateNestedPageContextCopiesPropertiesFromParentPageContext()
{
// Arrange
var httpContext = new Mock<HttpContextBase>();
var pageDataDictionary = new Dictionary<object, dynamic>();
var model = new { Hello = "World" };
Action<TextWriter> bodyAction = writer => { };
var sectionWritersStack = new Stack<Dictionary<string, SectionWriter>>();
var basePageContext = new WebPageContext(httpContext.Object, null, null) { BodyAction = bodyAction, SectionWritersStack = sectionWritersStack };
// Act
var subPageContext = WebPageContext.CreateNestedPageContext(basePageContext, pageDataDictionary, model, isLayoutPage: false);
// Assert
Assert.Equal(basePageContext.HttpContext, subPageContext.HttpContext);
Assert.Equal(basePageContext.OutputStack, subPageContext.OutputStack);
Assert.Equal(basePageContext.Validation, subPageContext.Validation);
Assert.Equal(pageDataDictionary, subPageContext.PageData);
Assert.Equal(model, subPageContext.Model);
Assert.Null(subPageContext.BodyAction);
}
[Fact]
public void CreateNestedPageCopiesBodyActionAndSectionWritersWithOtherPropertiesFromParentPageContext()
{
// Arrange
var httpContext = new Mock<HttpContextBase>();
var pageDataDictionary = new Dictionary<object, dynamic>();
var model = new { Hello = "World" };
Action<TextWriter> bodyAction = writer => { };
var sectionWritersStack = new Stack<Dictionary<string, SectionWriter>>();
var basePageContext = new WebPageContext(httpContext.Object, null, null) { BodyAction = bodyAction, SectionWritersStack = sectionWritersStack };
// Act
var subPageContext = WebPageContext.CreateNestedPageContext(basePageContext, pageDataDictionary, model, isLayoutPage: true);
// Assert
Assert.Equal(basePageContext.HttpContext, subPageContext.HttpContext);
Assert.Equal(basePageContext.OutputStack, subPageContext.OutputStack);
Assert.Equal(basePageContext.Validation, subPageContext.Validation);
Assert.Equal(pageDataDictionary, subPageContext.PageData);
Assert.Equal(model, subPageContext.Model);
Assert.Equal(sectionWritersStack, subPageContext.SectionWritersStack);
Assert.Equal(bodyAction, subPageContext.BodyAction);
}
}
}
|