public void HasLengthTests() { Assert.IsFalse(StringUtils.HasLength(null)); Assert.IsFalse(StringUtils.HasLength("")); Assert.IsTrue(StringUtils.HasLength(" ")); Assert.IsTrue(StringUtils.HasLength("Hello")); }
/// <summary> /// Returns absolute path that can be referenced within plain HTML. /// </summary> /// <remarks> /// <p> /// If relative path starts with '/' (forward slash), no concatenation will occur /// and it will be assumed that the relative path specified is indeed the absolute path /// and will be returned verbatim.</p> /// <p> /// Otherwise, relative path will be appended to the application path, while making sure that /// path separators are not duplicated between the paths.</p> /// </remarks> /// <param name="applicationPath">Application path.</param> /// <param name="relativePath">Relative path to combine with the application path.</param> /// <returns>Absolute path.</returns> public static string CreateAbsolutePath(string applicationPath, string relativePath) { if (StringUtils.HasLength(relativePath)) { if (relativePath.ToLower().StartsWith("http://") || relativePath.ToLower().StartsWith("https://")) { return(relativePath); } if (relativePath.StartsWith("/")) { return(relativePath); } if (relativePath.StartsWith("~/")) { relativePath = relativePath.Substring(2); } } applicationPath = (applicationPath == null) ? "" : applicationPath.TrimEnd('/'); return(string.Format("{0}/{1}", applicationPath, relativePath)); }