public void GetStylesheetHrefPathRendersAppropriatePath(string src, string virtualDir, string skinPath, string expected)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "Anything", virtualDir);

            Style style = new Style();
            style.Href = src;

            string stylePath = StyleSheetElementCollectionRenderer.GetStylesheetHrefPath(skinPath, style);
            Assert.AreEqual(stylePath, expected, "The rendered style path was not what we expected.");
        }
 public static bool CanStyleBeMerged(Style style)
 {
     if(!String.IsNullOrEmpty(style.Conditional))
     {
         return false;
     }
     if(!string.IsNullOrEmpty(style.Title))
     {
         return false;
     }
     if(IsStyleRemote(style))
     {
         return false;
     }
     return true;
 }
 /// <summary>
 /// Gets the stylesheet href path.
 /// </summary>
 /// <param name="skinPath">The skin path.</param>
 /// <param name="style">The style.</param>
 /// <returns></returns>
 public static string GetStylesheetHrefPath(string skinPath, Style style)
 {
     if(style.Href.StartsWith("~"))
     {
         return HttpHelper.ExpandTildePath(style.Href);
     }
     return style.Href.StartsWith("/") || style.Href.StartsWith("http://") || style.Href.StartsWith("https://")
                ? style.Href
                : skinPath + style.Href;
 }
        private static string RenderStyleElement(string skinPath, Style style, string skinName, string cssRequestParam)
        {
            string element = string.Empty;

            if(!String.IsNullOrEmpty(style.Conditional))
            {
                element = string.Format(CultureInfo.InvariantCulture, "<!--[{0}]>{1}", style.Conditional,
                                        Environment.NewLine);
            }

            element += "<link";
            if(!string.IsNullOrEmpty(style.Media) &&
               !style.Media.Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                element += RenderStyleAttribute("media", style.Media);
            }

            element +=
                RenderStyleAttribute("type", "text/css") +
                RenderStyleAttribute("rel", "stylesheet") +
                RenderStyleAttribute("title", style.Title);

            if(string.IsNullOrEmpty(skinName))
            {
                element +=
                    string.Format("{0} />{1}", RenderStyleAttribute("href", GetStylesheetHrefPath(skinPath, style)), Environment.NewLine);
            }
            else
            {
                element +=
                    string.Format("{0} />{1}", RenderStyleAttribute("href", GetStylesheetHrefPath(skinPath, style, skinName, cssRequestParam)), Environment.NewLine);
            }

            if(!String.IsNullOrEmpty(style.Conditional))
            {
                element += string.Format("<![endif]-->{0}", Environment.NewLine);
            }

            return element;
        }
 private static string RenderStyleElement(string skinPath, Style style)
 {
     return RenderStyleElement(skinPath, style, string.Empty, string.Empty);
 }
 private static bool IsStyleRemote(Style style)
 {
     if(style.Href.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
        style.Href.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
     {
         return true;
     }
     return false;
 }
        private static string BuildStyleKey(Style style)
        {
            var keyBuilder = new StringBuilder();
            if(!String.IsNullOrEmpty(style.Media) && !style.Media.Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                keyBuilder.AppendFormat("media={0}&", style.Media);
            }
            if(!String.IsNullOrEmpty(style.Title))
            {
                keyBuilder.AppendFormat("title={0}&", style.Title);
            }
            if(!String.IsNullOrEmpty(style.Conditional))
            {
                keyBuilder.AppendFormat("conditional={0}&", HttpUtility.UrlEncode(style.Conditional));
            }

            string key = keyBuilder.ToString();
            if(key.Length > 0)
            {
                return key.Substring(0, key.Length - 1);
            }
            return
                string.Empty;
        }
 /// <summary>
 /// Gets the stylesheet href path.
 /// </summary>
 /// <param name="skinName">The skin name as in the key.</param>
 /// <param name="skinPath">The skin path.</param>
 /// <param name="style">The style.</param>
 /// <param name="cssRequestParam">The parameters used to request the css via the css handler.</param>
 /// <returns></returns>
 public static string GetStylesheetHrefPath(string skinPath, Style style, string skinName, string cssRequestParam)
 {
     if(IsStyleRemote(style))
     {
         return style.Href;
     }
     return string.Format("{0}css.axd?name={1}&{2}", skinPath, skinName, cssRequestParam);
 }
        public void StyleToBeMergedAreCorrectlyDetected(string conditional, string media, string title, string href,
            bool canBeMerged)
        {
            var style = new Style();
            style.Conditional = conditional;
            style.Media = media;
            style.Href = href;
            style.Title = title;

            bool isMergeable = StyleSheetElementCollectionRenderer.CanStyleBeMerged(style);
            if(canBeMerged)
            {
                Assert.IsTrue(isMergeable, "Expected to be mergeable");
            }
            else
            {
                Assert.IsFalse(isMergeable, "Expected not to be mergeable");
            }
        }
 private static string RenderStyleElement(string skinPath, Style style)
 {
     return(RenderStyleElement(skinPath, style, string.Empty, string.Empty));
 }
 /// <summary>
 /// Gets the stylesheet href path.
 /// </summary>
 /// <param name="skinPath">The skin path.</param>
 /// <param name="style">The style.</param>
 /// <returns></returns>
 public static string GetStylesheetHrefPath(string skinPath, Style style)
 {
     if (style.Href.StartsWith("~"))
     {
         return HttpHelper.ExpandTildePath(style.Href);
     }
     else if (IsStyleRemote(style) == true)
     {
         return style.Href;
     }
     else
     {
         return skinPath + style.Href;
     }
 }