Exemplo n.º 1
0
        public void ExecuteWithinInitTest()
        {
            AppDomainUtils.RunInSeparateAppDomain(
                () =>
            {
                Utils.CreateHttpRuntime("/subfolder1/website1");
                new HostingEnvironment();
                var stringSet = Activator.CreateInstance(
                    typeof(BuildManager).Assembly.GetType("System.Web.Util.StringSet"),
                    true
                    );
                typeof(BuildManager)
                .GetField(
                    "_forbiddenTopLevelDirectories",
                    BindingFlags.Instance | BindingFlags.NonPublic
                    )
                .SetValue(new MockInitPage().GetBuildManager(), stringSet);
                ;

                var init = new MockInitPage()
                {
                    VirtualPath   = "~/_pagestart.cshtml",
                    ExecuteAction = p => { },
                };
                var page = Utils.CreatePage(p => { });

                Utils.AssignObjectFactoriesAndDisplayModeProvider(page, init);

                var result = Utils.RenderWebPage(page);
            }
                );
        }
Exemplo n.º 2
0
        public void SetGetPropertiesTest()
        {
            var init = new MockInitPage();
            var page = new MockPage();

            init.ChildPage = page;

            // Context
            var context = new Mock <HttpContextBase>().Object;

            init.Context = context;
            Assert.Equal(context, init.Context);
            Assert.Equal(context, page.Context);

            // Profile/Request/Response/Server/Cache/Session/Application
            var profile  = new Mock <ProfileBase>().Object;
            var request  = new Mock <HttpRequestBase>().Object;
            var response = new Mock <HttpResponseBase>().Object;
            var server   = new Mock <HttpServerUtilityBase>().Object;
            var cache    = new Cache();
            var app      = new Mock <HttpApplicationStateBase>().Object;
            var session  = new Mock <HttpSessionStateBase>().Object;

            var contextMock = new Mock <HttpContextBase>();

            contextMock.Setup(c => c.Profile).Returns(profile);
            contextMock.Setup(c => c.Request).Returns(request);
            contextMock.Setup(c => c.Response).Returns(response);
            contextMock.Setup(c => c.Cache).Returns(cache);
            contextMock.Setup(c => c.Server).Returns(server);
            contextMock.Setup(c => c.Application).Returns(app);
            contextMock.Setup(c => c.Session).Returns(session);

            context      = contextMock.Object;
            page.Context = context;
            Assert.Same(profile, init.Profile);
            Assert.Same(request, init.Request);
            Assert.Same(response, init.Response);
            Assert.Same(cache, init.Cache);
            Assert.Same(server, init.Server);
            Assert.Same(session, init.Session);
            Assert.Same(app, init.AppState);
        }
Exemplo n.º 3
0
        public void SetGetPropertiesTest() {

            var init = new MockInitPage();
            var page = new MockPage();
            init.ChildPage = page;

            // Context
            var context = new Mock<HttpContextBase>().Object;
            init.Context = context;
            Assert.AreEqual(context, init.Context);
            Assert.AreEqual(context, page.Context);

            // Request/Response/Server/Cache/Session/Application
            var request = new Mock<HttpRequestBase>().Object;
            var response = new Mock<HttpResponseBase>().Object;
            var server = new Mock<HttpServerUtilityBase>().Object;
            var cache = new System.Web.Caching.Cache();
            var app = new Mock<HttpApplicationStateBase>().Object;
            var session = new Mock<HttpSessionStateBase>().Object;

            var contextMock = new Mock<HttpContextBase>();
            contextMock.Setup(c => c.Request).Returns(request);
            contextMock.Setup(c => c.Response).Returns(response);
            contextMock.Setup(c => c.Cache).Returns(cache);
            contextMock.Setup(c => c.Server).Returns(server);
            contextMock.Setup(c => c.Application).Returns(app);
            contextMock.Setup(c => c.Session).Returns(session);

            context = contextMock.Object;
            page.Context = context;
            Assert.AreEqual(request, init.Request);
            Assert.AreEqual(response, init.Response);
            Assert.AreEqual(cache, init.Cache);
            Assert.AreEqual(server, init.Server);
            Assert.AreEqual(session, init.Session);
            Assert.AreEqual(app, init.AppState);
        }
Exemplo n.º 4
0
        public void ExecuteWithinInitTest() {
            AppDomainUtils.RunInSeparateAppDomain(() => {
                Utils.CreateHttpRuntime("/subfolder1/website1");
                new System.Web.Hosting.HostingEnvironment();
                var stringSet = Activator.CreateInstance(typeof(BuildManager).Assembly.GetType("System.Web.Util.StringSet"), true);
                typeof(BuildManager).GetField("_forbiddenTopLevelDirectories", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(new MockInitPage().GetBuildManager(), stringSet); ;

                var init = new MockInitPage() {
                    VirtualPath = "~/_pagestart.cshtml",
                    ExecuteAction = p => { },
                };
                var page = Utils.CreatePage(p => { });
                page.PageInstances["~/_pagestart.cshtml"] = init;

                var result = Utils.RenderWebPage(page);
            });
        }