forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebPageContextTest.cs
More file actions
62 lines (55 loc) · 3.02 KB
/
Copy pathWebPageContextTest.cs
File metadata and controls
62 lines (55 loc) · 3.02 KB
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
60
61
62
// 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.Collections.Generic;
using System.IO;
using Microsoft.TestCommon;
using Moq;
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(basePageContext.ModelState, subPageContext.ModelState);
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(basePageContext.ModelState, subPageContext.ModelState);
Assert.Equal(pageDataDictionary, subPageContext.PageData);
Assert.Equal(model, subPageContext.Model);
Assert.Equal(sectionWritersStack, subPageContext.SectionWritersStack);
Assert.Equal(bodyAction, subPageContext.BodyAction);
}
}
}