public void TestUrlSkinName() { Console.WriteLine("After TestUrlSkinName"); Mockery mock = new Mockery(); IInputContext context = mock.NewMock<IInputContext>(); XmlDocument siteconfig = new XmlDocument(); siteconfig.LoadXml("<SITECONFIG />"); ISite site = mock.NewMock<ISite>(); Stub.On(site).GetProperty("Config").Will(Return.Value(String.Empty)); User user = new User(context); Stub.On(context).Method("IsPreviewMode").Will(Return.Value(false)); Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(user)); Stub.On(context).GetProperty("UserAgent").Will(Return.Value("Mozilla+blah+blah")); Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(site)); Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value(true)); Stub.On(context).Method("GetParamStringOrEmpty").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value("randomskin")); WholePage page = new WholePage(context); page.InitialisePage("TEST"); Assert.IsNotNull(page.RootElement); Assert.AreEqual(page.RootElement.FirstChild.Name, "H2G2"); XmlNodeList nodes = page.RootElement.SelectNodes("H2G2/VIEWING-USER"); Assert.IsNotNull(nodes); Assert.AreEqual(nodes.Count, 1, "Only expecting one Viewing User element"); nodes = page.RootElement.SelectNodes("H2G2/URLSKINNAME"); Assert.IsNotNull(nodes); Assert.AreEqual(nodes.Count, 1, "Only expecting one URLSKINNAME element"); XmlNode node = nodes[0]; Assert.AreEqual(node.InnerText, "randomskin", "Expected 'randomskin' for the skin name in the URLSKINNAME element"); context = mock.NewMock<IInputContext>(); Stub.On(context).Method("IsPreviewMode").Will(Return.Value(false)); Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(user)); Stub.On(context).GetProperty("UserAgent").Will(Return.Value("Mozilla+blah+blah")); Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(site)); Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value(false)); Stub.On(context).Method("GetParamStringOrEmpty").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value("")); page = new WholePage(context); page.InitialisePage("TEST"); Assert.IsNotNull(page.RootElement); Assert.AreEqual(page.RootElement.FirstChild.Name, "H2G2"); nodes = page.RootElement.SelectNodes("H2G2/VIEWING-USER"); Assert.IsNotNull(nodes); Assert.AreEqual(nodes.Count, 1, "Only expecting one Viewing User element"); nodes = page.RootElement.SelectNodes("H2G2/URLSKINNAME"); Assert.IsNotNull(nodes); Assert.AreEqual(nodes.Count, 0, "Not expecting one URLSKINNAME element"); Console.WriteLine("After TestUrlSkinName"); }
/// <summary> /// Initialises the page by setting up all the member vairables /// </summary> /// <returns>True if ok, false if not</returns> private void InitialisePage() { CreateViewingUser(); _page = new WholePage(this); _page.InitialisePage(PageType); if (_dnapage.IncludeTopFives) { RecentActivity topFives = RecentActivity.GetSiteRecentActivity(CurrentSite.SiteID, AppContext.ReaderCreator, Diagnostics, AppContext.DnaCacheManager); _page.SerialiseAndAppend(topFives, "//H2G2"); } //Ultimate Choice of skin may include users preferences. _skinSelector.Initialise(this, this); }
/// <summary> /// This is the place where all the actual work is done /// Please add all new code here, and not in the main Page_Load method /// </summary> private void DoPageLoad() { Stopwatch requesttimer = new Stopwatch(); requesttimer.Start(); InitialiseRequest(); // Check to see which sign in method we need to create if (_debugUserID.Length > 0) { SetupDebugUserSignin(); } else if (CurrentSite.UseIdentitySignInSystem) { // Create a new Identity web service object string identityWebServiceConnetionDetails = GetConnectionDetails["IdentityURL"].ConnectionString; Diagnostics.WriteTimedEventToLog("IDENTITY", "Started with " + identityWebServiceConnetionDetails); string clientIPAddress = GetParamStringOrEmpty("__ip__", "Client IP Address"); _signInComponent = new DnaIdentityWebServiceProxy.IdentityRestSignIn(identityWebServiceConnetionDetails, clientIPAddress); _signInComponent.SetService(CurrentSite.IdentityPolicy); Diagnostics.WriteTimedEventToLog("IDENTITY", "Finished"); } else { // Create a new profileAPI signin object throw new NotSupportedException("The ProfileAPI is nolonger supported. Please set the site to use Identity as the Signin System."); } // If we have cached output available for this request, don't do any more work if (IsCachedOutputAvailable()) { return; } CheckForForbiddenUserAgents(UserAgent, BannedUserAgents); int curRequests = Interlocked.Increment(ref _currentRequestCount); try { if (curRequests > MaximumRequestCount && _dnapage.PageType.Equals("SERVERTOOBUSY") == false ) { AddServerBusy(); Server.Transfer("ServerTooBusyPage.aspx"); //_viewingUser = new User(this); //_page = new WholePage(this); //_page.InitialisePage("SERVERTOOBUSY"); //_page.AddTextTag(_page.RootElement.FirstChild, "REQUESTTYPE", PageType); //_skinSelector.Initialise(this, this); } InitialisePage(); // Intialise the page Statistics.AddRawRequest(); if (!IsDnaUserAllowed() && !_useDotNetRendering ) {//not logged in if (!_skinSelector.IsPureXml(this)) { _skinSelector.SkinName = "admin"; _skinSelector.SkinSet = "vanilla"; } _page = new WholePage(this); _page.InitialisePage("ERROR"); _page.AddErrorXml("Authorization", "You are not authorised to view this page.", _page.RootElement.FirstChild); } else if (!IsSecureAccessAllowed()) {//logged in but not secure if (!_skinSelector.IsPureXml(this)) { _skinSelector.SkinName = "admin"; _skinSelector.SkinSet = "vanilla"; } _page = new WholePage(this); _page.InitialisePage("ERROR"); _page.AddErrorXml("NotSecure", "You must access this page be secure methods.", _page.RootElement.FirstChild); } else { // Now call the add components _dnapage.OnPageLoad(); AddComponent(new SkinParams(this)); _page.ProcessRequest(); // Update any data source controls on the page _dnapage.UpdateDataSourceControls(); // Allow the page to do any post process request actions. _dnapage.OnPostProcessRequest(); } //Finish off other related BasePage stuff FinalisePage(); Statistics.AddRequestDuration((int)requesttimer.ElapsedMilliseconds); _page.AddTimeForPage(Diagnostics.ElapsedMilliseconds); _page.AddInside(_tracker, "H2G2"); } finally { Interlocked.Decrement(ref _currentRequestCount); } }
/// <summary> /// This is where the page is initialised and all components get added. /// </summary> /// <param name="sender">The object that sent the request</param> /// <param name="e">Arguments passed in</param> public void Page_Load(object sender, EventArgs e) { // Create the param tracker and request objects for this request _tracker = new ParameterTracker(this); if (WebConfigurationManager.AppSettings["aspneterrors"] == "1") { DoPageLoad(); } else { bool wasExceptionCaught = false; try { DoPageLoad(); } catch (Exception ex) { if (ex.GetType() == typeof(HttpException) && ex.Message == _botNotAllowedMessage) { throw; } wasExceptionCaught = true; if (Diagnostics != null) { Diagnostics.WriteExceptionToLog(ex); } } // Initialise an error page here if we don't have one already to stop a further error // masking the real one. if (_page == null) { if (_viewingUser == null) { _viewingUser = new User(this); } _page = new WholePage(this); _page.InitialisePage("ERROR"); } if (wasExceptionCaught && _page != null) { XmlNode h2g2 = _page.RootElement.FirstChild; XmlNode errornode = _page.AddTextTag(h2g2, "ERROR", "An unknown error has occurred"); _page.AddAttribute(errornode, "REQUESTID", _requestId.ToString()); _page.AddAttribute(errornode, "TIME", DateTime.Now.ToString("dd MMMM yyyy, HH:mm:ss")); string originalType = h2g2.Attributes["TYPE"].InnerText; _page.AddAttribute(errornode, "ORIGINALPAGETYPE", originalType); // This will fail if there's no TYPE attribute - but that's a fatal bug at this point anyway h2g2.Attributes["TYPE"].InnerText = "ERROR"; } } }