コード例 #1
0
        public void PageIsBuiltUpOnPreInit()
        {
            MockWebClientApplication application = new MockWebClientApplication();
            MockHttpContext mockContext = new MockHttpContext();
            mockContext.Request = new HttpRequest("page.aspx", "http://application/page.aspx", null);
            mockContext.ApplicationInstance = application;
            application.SetTestCurrentContext(mockContext);
            MockPage page = new MockPage();

            Assert.IsFalse(page.OnBuiltUpCalled);

            page.FireOnPreInit();

            Assert.IsTrue(page.OnBuiltUpCalled);
        }
        public void TestUserIsAuthorizedIfNotRuleIsDefinedForUrl()
        {
            MockWebClientApplication mockApplication = new MockWebClientApplication();
            MockAuthorizationRuleCatalogService mockRulesCatalog =
                mockApplication.RootContainer.Services.AddNew<MockAuthorizationRuleCatalogService, IAuthorizationRulesService>();
            MockVirtualPathUtility mockVirtualPathUtility =
                mockApplication.RootContainer.Services.AddNew<MockVirtualPathUtility, IVirtualPathUtilityService>();
            mockVirtualPathUtility.ToAppRelativeResult = "~/files.asx";
            MockHttpContext mockContext = new MockHttpContext();
            mockContext.Request = new HttpRequest("file.aspx", "http://MyWebApp/files.aspx", null);

            TestableWebClientAuthorizationModule module = new TestableWebClientAuthorizationModule();
            module.TestHandleAuthorization(mockApplication, mockContext);

            Assert.AreEqual("~/files.asx", mockRulesCatalog.LastGetRuleUrl);
        }
コード例 #3
0
        public void UserControlIsBuiltUpOnInit()
        {
            MockWebClientApplication application = new MockWebClientApplication();
            MockHttpContext mockContext = new MockHttpContext();
            mockContext.Request = new HttpRequest("page.aspx", "http://application/page.aspx", null);
            mockContext.ApplicationInstance = application;
            application.SetTestCurrentContext(mockContext);
            System.Web.UI.Page page = new System.Web.UI.Page();
            MockUserControl uc = (MockUserControl) page.LoadControl(typeof (MockUserControl), null);
            page.Controls.Add(uc);

            Assert.IsFalse(uc.OnBuiltUpCalled);

            uc.FireOnInit();

            Assert.IsTrue(uc.OnBuiltUpCalled);
        }
        public void TestWebAuthorizationExceptionThrownIfNotAuthorized()
        {
            MockWebClientApplication mockApplication = new MockWebClientApplication();
            MockAuthorizationService mockAuthorizationService =
                mockApplication.RootContainer.Services.AddNew<MockAuthorizationService, IAuthorizationService>();
            MockVirtualPathUtility mockVirtualPathUtility =
                mockApplication.RootContainer.Services.AddNew<MockVirtualPathUtility, IVirtualPathUtilityService>();
            mockVirtualPathUtility.ToAppRelativeResult = "~/files.asx";
            mockAuthorizationService.ShouldAuthorize = false;
            MockAuthorizationRuleCatalogService mockRulesCatalog =
                mockApplication.RootContainer.Services.AddNew<MockAuthorizationRuleCatalogService, IAuthorizationRulesService>();
            mockRulesCatalog.GetRuleReturnValue = new string[] {"AuthorizationRule"};
            MockHttpContext mockContext = new MockHttpContext();
            mockContext.Request = new HttpRequest("file.aspx", "http://MyWebApp/files.aspx", null);

            TestableWebClientAuthorizationModule module = new TestableWebClientAuthorizationModule();
            module.TestHandleAuthorization(mockApplication, mockContext);
        }