From 7be4480254d0ae3ebc096e80ed0dc172923f7d5e Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 29 Aug 2012 07:47:16 +0700 Subject: [PATCH] added HasValue unit test, removed the default.aspx file from the Web project, it now only exists in the UI project but the codebehind still exist in the web for backwards compatibility. Updated the logging so that the LogHelper can now write to a TraceContext specified if debugging which is handy if we want to write to the normal trace. --- src/Umbraco.Core/Logging/LogHelper.cs | 19 +++++++++++- .../DynamicDocumentTestsBase.cs | 12 ++++++++ .../umbraco.presentation/default.aspx | 2 -- .../umbraco.presentation/default.aspx.cs | 29 +++++++++---------- .../default.aspx.designer.cs | 22 -------------- 5 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 src/Umbraco.Web/umbraco.presentation/default.aspx delete mode 100644 src/Umbraco.Web/umbraco.presentation/default.aspx.designer.cs diff --git a/src/Umbraco.Core/Logging/LogHelper.cs b/src/Umbraco.Core/Logging/LogHelper.cs index 4d91ea88f2..964a9f3b9c 100644 --- a/src/Umbraco.Core/Logging/LogHelper.cs +++ b/src/Umbraco.Core/Logging/LogHelper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; +using System.Web; using log4net; namespace Umbraco.Core.Logging @@ -190,7 +191,7 @@ namespace Umbraco.Core.Logging } /// - /// Debugs a message, only generating the message if tracing is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled. + /// Debugs a message, only generating the message if debug is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled. /// /// /// The generate message format. @@ -200,6 +201,22 @@ namespace Umbraco.Core.Logging { Debug(typeof(T), generateMessageFormat, formatItems); } + + /// + /// Debugs a message and also writes to the TraceContext specified, useful for when you would like the debug + /// output also displayed in the Http trace output. + /// + /// + /// + /// + /// + public static void Debug(string generateMessageFormat, TraceContext trace, params Func[] formatItems) + { + if (trace == null) throw new ArgumentNullException("trace"); + trace.Write(string.Format(generateMessageFormat, formatItems.Select(x => x()))); + Debug(typeof(T), generateMessageFormat, formatItems); + } + #endregion } diff --git a/src/Umbraco.Tests/DynamicDocument/DynamicDocumentTestsBase.cs b/src/Umbraco.Tests/DynamicDocument/DynamicDocumentTestsBase.cs index b2760d4f94..8dc6b37091 100644 --- a/src/Umbraco.Tests/DynamicDocument/DynamicDocumentTestsBase.cs +++ b/src/Umbraco.Tests/DynamicDocument/DynamicDocumentTestsBase.cs @@ -59,6 +59,18 @@ namespace Umbraco.Tests.DynamicDocument } + [Test] + public void HasValue() + { + var asDynamic = GetDynamicNode(1173); + + var hasValue = asDynamic.HasValue("umbracoUrlAlias"); + var noValue = asDynamic.HasValue("blahblahblah"); + + Assert.IsTrue(hasValue); + Assert.IsFalse(noValue); + } + [Test] public void Take() { diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx b/src/Umbraco.Web/umbraco.presentation/default.aspx deleted file mode 100644 index 458dc34d73..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/default.aspx +++ /dev/null @@ -1,2 +0,0 @@ -<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="True" Inherits="umbraco.UmbracoDefault" trace="true" validateRequest="false" %> - diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs index f5d8698001..4b0c63f25a 100644 --- a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using System.Web; using System.Web.Routing; @@ -6,6 +6,7 @@ using System.Web.UI; using System.IO; using System.Xml; using System.Text.RegularExpressions; +using Umbraco.Core.Logging; using Umbraco.Web; using Umbraco.Web.Routing; using Umbraco.Core.Configuration; @@ -16,17 +17,18 @@ using umbraco.cms.businesslogic; namespace umbraco { /// - /// Summary description for WebForm1. + /// The codebehind class for the main default.aspx page that does the webforms rendering in Umbraco /// - /// - public partial class UmbracoDefault : Page + /// + /// We would move this to the UI project but there is a public API property and some protected properties which people may be using so + /// we cannot move it. + /// + public class UmbracoDefault : Page { private page _upage = null; private DocumentRequest _docRequest = null; bool _validateRequest = true; - const string TraceCategory = "UmbracoDefault"; - /// /// To turn off request validation set this to false before the PageLoad event. This equivalent to the validateRequest page directive /// and has nothing to do with "normal" validation controls. Default value is true. @@ -40,8 +42,7 @@ namespace umbraco // fixme - switch over to OnPreInit override void Page_PreInit(Object sender, EventArgs e) { - Trace.Write(TraceCategory, "Begin PreInit"); - + //TODO: This still a bunch of routing stuff being handled here, this all needs to be handled in the HttpModule instead // get the document request @@ -111,12 +112,10 @@ namespace umbraco } // reset the friendly path so it's used by forms, etc. - Trace.Write(TraceCategory, string.Format("Reset url to \"{0}\"", UmbracoContext.Current.RequestUrl)); + LogHelper.Debug(string.Format("Reset url to \"{0}\"", UmbracoContext.Current.RequestUrl)); Context.RewritePath(UmbracoContext.Current.RequestUrl.PathAndQuery); Context.Items.Add("pageElements", _upage.Elements); // legacy - fixme - - Trace.Write(TraceCategory, "End PreInit"); } void OnPreInitLegacy() @@ -153,7 +152,7 @@ namespace umbraco if (cultureAlias != null) { - UmbracoContext.Current.HttpContext.Trace.Write("default.aspx", "Culture changed to " + cultureAlias); + LogHelper.Debug("Culture changed to " + cultureAlias, Context.Trace); var culture = new System.Globalization.CultureInfo(cultureAlias); Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = culture; } @@ -191,7 +190,7 @@ namespace umbraco // filter / add preview banner if (UmbracoContext.Current.InPreviewMode) { - Trace.Write("Runtime Engine", "Umbraco is running in preview mode."); + LogHelper.Debug("Umbraco is running in preview mode.", Context.Trace); if (Response.ContentType == "text/HTML") // ASP.NET default value { @@ -200,8 +199,8 @@ namespace umbraco { string htmlBadge = String.Format(UmbracoSettings.PreviewBadge, - umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco), - umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco_client), + IOHelper.ResolveUrl(SystemDirectories.Umbraco), + IOHelper.ResolveUrl(SystemDirectories.UmbracoClient), Server.UrlEncode(UmbracoContext.Current.HttpContext.Request.Path)); text = text.Substring(0, pos) + htmlBadge + text.Substring(pos, text.Length - pos); diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/default.aspx.designer.cs deleted file mode 100644 index 95c38cf310..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/default.aspx.designer.cs +++ /dev/null @@ -1,22 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.1434 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace umbraco { - - - /// - /// UmbracoDefault class. - /// - /// - /// Auto-generated class. - /// - public partial class UmbracoDefault { - } -}