public void EnsureNonVirtualPathsDoNotThrowTest()
        {
            BundleCollection col      = new BundleCollection();
            BundleResolver   resolver = new BundleResolver(col);

            Assert.IsFalse(resolver.IsBundleVirtualPath("missingTilde"));
            Assert.IsNull(resolver.GetBundleContents("missingTilde"));
            Assert.IsNull(resolver.GetBundleUrl("missingTilde"));
        }
        public void EnsureEmptyVirtualPathsDoNotThrowTest()
        {
            BundleCollection col      = new BundleCollection();
            BundleResolver   resolver = new BundleResolver(col);

            Assert.IsFalse(resolver.IsBundleVirtualPath(String.Empty));
            Assert.IsNull(resolver.GetBundleContents(String.Empty));
            Assert.IsNull(resolver.GetBundleUrl(String.Empty));
        }
        public void NonBundleValidUrlTest()
        {
            BundleCollection col = new BundleCollection();

            col.Add(new Bundle("~/js"));
            BundleResolver resolver = new BundleResolver(col);

            Assert.IsFalse(resolver.IsBundleVirtualPath("~/nope"));
            Assert.IsNull(resolver.GetBundleContents("~/nope"));
            Assert.IsNull(resolver.GetBundleUrl("~/nope"));
        }
        public static IHtmlString Render(string path)
        {
            if (BundleTable.EnableOptimizations)
            {
                return(Styles.Render(path));
            }

            var resolver = new BundleResolver(BundleTable.Bundles);
            var url      = resolver.GetBundleUrl(path);
            var styles   = string.Format("<link href=\"{0}\" rel=\"Stylesheet\"/>", url);

            return(new MvcHtmlString(styles));
        }
示例#5
0
        private static IHtmlString GenerateVersion(string html, string[] paths)
        {
            BundleResolver bundle = new BundleResolver(BundleTable.Bundles);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            var context = new HttpContextWrapper(HttpContext.Current);

            foreach (var p in paths)
            {
                var    list = new List <string>();
                string parm = "", path = p;
                if (p.Contains("?"))
                {
                    parm = p.Substring(p.LastIndexOf("?"));
                    path = p.Replace(parm, "");
                }
                if (BundleTable.EnableOptimizations)
                {
                    var b = bundle.GetBundleUrl(path);//取压缩
                    if (b == null)
                    {
                        b = path;
                    }
                    else if (!string.IsNullOrWhiteSpace(parm))
                    {
                        parm = parm.Replace("?", "&");
                    }

                    list.Add(b);
                }
                else
                {
                    var bs = bundle.GetBundleContents(path);//取原路径
                    if (bs == null)
                    {
                        list.Add(path);
                    }
                    else
                    {
                        list.AddRange(bs);
                    }
                }
                foreach (var bc in list)
                {
                    var u = UrlHelper.GenerateContentUrl(bc, context);
                    sb.AppendFormat(html, u + parm);
                    sb.Append(Environment.NewLine);
                }
            }
            return(new HtmlString(sb.ToString()));
        }