Exemple #1
0
        public void CanRenderCssFileWithImportStatementUppercase()
        {
            string importCss =
                @"
                                    @IMPORT URL(/css/other.css);
                                    #header {
                                        color: #4D926F;
                                    }";

            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(importCss);
            mockFileReaderFactory.SetContentsForFile(@"C:\css\other.css", "#footer{color:#ffffff;}");

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                         .Add("/css/first.css")
                         .ProcessImports()
                         .Render("/css/processed_import_uppercase.css");

            Assert.AreEqual("#footer{color:#fff;}#header{color:#4D926F;}", mockFileWriterFactory.Files[@"C:\css\processed_import_uppercase.css"]);
        }
Exemple #2
0
        public void CanRenderCssFileWithUnprocessedImportStatement()
        {
            string importCss =
                @"
                                    @import url(""/css/other.css"");
                                    #header {
                                        color: #4D926F;
                                    }";

            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(importCss);
            mockFileReaderFactory.SetContentsForFile(@"C:\css\other.css", "#footer{color:#ffffff;}");

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            cssBundle
            .Add("/css/first.css")
            .Render("/css/unprocessed_import.css");

            Assert.AreEqual(@"@import url(""/css/other.css"");#header{color:#4D926F;}", mockFileWriterFactory.Files[@"C:\css\unprocessed_import.css"]);
        }
Exemple #3
0
        public void CanRenderDebugTagsTwice()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(true);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle1 = new CssBundle(mockDebugStatusReader,
                                                  mockFileWriterFactory,
                                                  mockFileReaderFactory);

            ICssBundle cssBundle2 = new CssBundle(mockDebugStatusReader,
                                                  mockFileWriterFactory,
                                                  mockFileReaderFactory);

            string tag1 = cssBundle1
                          .Add("/css/first.css")
                          .Add("/css/second.css")
                          .Render("/css/output.css");

            string tag2 = cssBundle2
                          .Add("/css/first.css")
                          .Add("/css/second.css")
                          .Render("/css/output.css");

            Assert.AreEqual(tag1, "<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/second.css\" />");
            Assert.AreEqual(tag2, "<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/second.css\" />");
        }
        //
        // GET: /ClearCaches/

        public ActionResult Index()
        {
            CssBundle.Clear();
            JavaScriptBundle.Clear();

            return(RedirectToAction("Index", "Home"));
        }
Exemple #5
0
        public void CanRenderOnlyIfFileMissing()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            mockFileReaderFactory.SetFileExists(false);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            cssBundle
            .Add("/css/first.css")
            .RenderOnlyIfOutputFileMissing()
            .Render("~/css/can_render_only_if_file_missing.css");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}", mockFileWriterFactory.Files[@"C:\css\can_render_only_if_file_missing.css"]);

            mockFileReaderFactory.SetContents(css2);
            mockFileReaderFactory.SetFileExists(true);
            cssBundle.ClearCache();

            cssBundle
            .Add("/css/first.css")
            .RenderOnlyIfOutputFileMissing()
            .Render("~/css/can_render_only_if_file_missing.css");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}", mockFileWriterFactory.Files[@"C:\css\can_render_only_if_file_missing.css"]);
        }
Exemple #6
0
        public void CanBundleCssWithLessAndPathRewrites()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            string css =
                @"@brand_color: #4D926F;
                        #header {
                            color: @brand_color;
                            background-image: url(../image/mygif.gif);
                        }
                    ";

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                         .Add("~/css/something/test.less")
                         .Render("~/css/output_less_with_rewrites.css");

            string contents = mockFileWriterFactory.Files[@"C:\css\output_less_with_rewrites.css"];

            Assert.AreEqual("#header{color:#4d926f;background-image:URL(image/mygif.gif);}", contents);
        }
Exemple #7
0
 public void CanMarkCssBundleAsPackageable()
 {
     ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                          mockFileWriterFactory,
                                          cssMockFileReaderFactory);
     string tag = cssBundle
                  .Add("/css/first.css")
                  .Add("/css/second.css")
                  .AsPackageable()
                  .Render("/css/render_differently_if_packaged_#.css");
 }
        public static void RegisterBundles(BundleCollection bundles)
        {
            Assets.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled;

            var jsBundle = new JsBundle("~/bundles/js");

            //jsBundle.Include("~/Scripts", "jquery-*");
            //jsBundle.Include("~/Scripts", "jquery-ui*");
            //jsBundle.Include("~/Scripts", "jquery.unobtrusive*");
            //jsBundle.Include("~/Scripts", "jquery.validate*");
            jsBundle.Include("~/Scripts/AjaxLogin.js");
            bundles.Add(jsBundle);

            var mobileJsBundle = new JsBundle("~/bundles/mobileJs");

            mobileJsBundle.Include("~/Scripts", "jquery.mobile*");
            bundles.Add(mobileJsBundle);

            var cssBundle = new CssBundle("~/Content/css");

            cssBundle.Include("~/Content/site.css");
            bundles.Add(cssBundle);

            var mobileCssBundle = new CssBundle("~/Content/mobileCss");

            mobileCssBundle.Include("~/Content", "jquery.mobile*");
            bundles.Add(mobileCssBundle);

            var themePath   = "~/Content/themes/base/";
            var themeBundle = new CssBundle(themePath + "css");

            themeBundle.Include(themePath + "jquery.ui.core.css");
            themeBundle.Include(themePath + "jquery.ui.resizable.css");
            themeBundle.Include(themePath + "jquery.ui.selectable.css");
            themeBundle.Include(themePath + "jquery.ui.accordion.css");
            themeBundle.Include(themePath + "jquery.ui.autocomplete.css");
            themeBundle.Include(themePath + "jquery.ui.button.css");
            themeBundle.Include(themePath + "jquery.ui.dialog.css");
            themeBundle.Include(themePath + "jquery.ui.slider.css");
            themeBundle.Include(themePath + "jquery.ui.tabs.css");
            themeBundle.Include(themePath + "jquery.ui.datepicker.css");
            themeBundle.Include(themePath + "jquery.ui.progressbar.css");
            themeBundle.Include(themePath + "jquery.ui.theme.css");
            bundles.Add(themeBundle);
        }
Exemple #9
0
        public void CanBundleCssWithQueryStringParameter()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .Render("/css/output_querystring.css?v=1");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/output_querystring.css?v=1&r=AE4C10DB94E5420AD54BD0A0BE9F02C2\" />", tag);
        }
Exemple #10
0
        public void CanBundleCss()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();
            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                            .Add("/css/first.css")
                            .Add("/css/second.css")
                            .Render("/css/output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/output.css?r=AE4C10DB94E5420AD54BD0A0BE9F02C2\" />", tag);
            Assert.AreEqual(1, mockFileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}", mockFileWriterFactory.Files["/css/output.css"]);
        }
Exemple #11
0
        public void CanRenderDebugTagsWithMediaAttribute()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(true);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithMedia("screen")
                         .Render("/css/output.css");

            Assert.AreEqual(tag, "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/second.css\" />");
        }
Exemple #12
0
        public void CanCreateNamedBundle()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            cssBundle
            .Add("~/css/temp.css")
            .AsNamed("Test", "~/css/output.css");

            string tag = cssBundle.RenderNamed("Test");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}", mockFileWriterFactory.Files[@"C:\css\output.css"]);
            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"css/output.css?r=A757BD759BA228D91481798C2C49A8DC\" />", tag);
        }
Exemple #13
0
        public void CanCreateNamedBundleWithDebug()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(true);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            cssBundle
            .Add("~/css/temp1.css")
            .Add("~/css/temp2.css")
            .AsNamed("TestWithDebug", "~/css/output.css");

            string tag = cssBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"css/temp1.css\" /><link rel=\"stylesheet\" type=\"text/css\"  href=\"css/temp2.css\" />", tag);
        }
Exemple #14
0
        public void CanBundleCssWithLessWithLessDotCssFileExtension()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(cssLess);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                         .Add("~/css/test.less.css")
                         .Render("~/css/output_less_dot_css.css");

            string contents = mockFileWriterFactory.Files[@"C:\css\output_less_dot_css.css"];

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"css/output_less_dot_css.css?r=350F6DC1A87E2503EE6D4AE414C4A479\" />", tag);
            Assert.AreEqual("#header,h2{color:#4d926f;}", contents);
        }
Exemple #15
0
        public void CanBundleCss()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .Render("/css/output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/output.css?r=AE4C10DB94E5420AD54BD0A0BE9F02C2\" />", tag);
            Assert.AreEqual(1, mockFileWriterFactory.Files.Count);
            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}", mockFileWriterFactory.Files[@"C:\css\output.css"]);
        }
        public static void RegisterBundles(BundleCollection bundles)
        {
            Assets.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled;

            var jsBundle = new JsBundle("~/bundles/js");
            jsBundle.Include("~/Scripts", "jquery-*");
            jsBundle.Include("~/Scripts", "jquery-ui*");
            jsBundle.Include("~/Scripts", "jquery.unobtrusive*");
            jsBundle.Include("~/Scripts", "jquery.validate*");
            jsBundle.Include("~/Scripts/AjaxLogin.js");
            bundles.Add(jsBundle);

            var mobileJsBundle = new JsBundle("~/bundles/mobileJs");
            mobileJsBundle.Include("~/Scripts", "jquery.mobile*");
            bundles.Add(mobileJsBundle);

            var cssBundle = new CssBundle("~/Content/css");
            cssBundle.Include("~/Content/site.css");
            bundles.Add(cssBundle);

            var mobileCssBundle = new CssBundle("~/Content/mobileCss");
            mobileCssBundle.Include("~/Content", "jquery.mobile*");
            bundles.Add(mobileCssBundle);

            var themePath = "~/Content/themes/base/";
            var themeBundle = new CssBundle(themePath + "css");
            themeBundle.Include(themePath + "jquery.ui.core.css");
            themeBundle.Include(themePath + "jquery.ui.resizable.css");
            themeBundle.Include(themePath + "jquery.ui.selectable.css");
            themeBundle.Include(themePath + "jquery.ui.accordion.css");
            themeBundle.Include(themePath + "jquery.ui.autocomplete.css");
            themeBundle.Include(themePath + "jquery.ui.button.css");
            themeBundle.Include(themePath + "jquery.ui.dialog.css");
            themeBundle.Include(themePath + "jquery.ui.slider.css");
            themeBundle.Include(themePath + "jquery.ui.tabs.css");
            themeBundle.Include(themePath + "jquery.ui.datepicker.css");
            themeBundle.Include(themePath + "jquery.ui.progressbar.css");
            themeBundle.Include(themePath + "jquery.ui.theme.css");
            bundles.Add(themeBundle);
        }
Exemple #17
0
        public void CanBundleCssWithNullCompressorAttribute()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();

            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                         .Add("/css/first.css")
                         .Add("/css/second.css")
                         .WithCompressor(CssCompressors.NullCompressor)
                         .Render("/css/css_with_null_compressor_output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/css_with_null_compressor_output.css?r=9650CBE3E753DF5F9146A2AF738A8272\" />", tag);
            Assert.AreEqual(1, mockFileWriterFactory.Files.Count);
            Assert.AreEqual(css + css, mockFileWriterFactory.Files[@"C:\css\css_with_null_compressor_output.css"]);
        }
Exemple #18
0
        /// <summary>
        /// Adds a CSS link to the given header using the given order and parameters. If a link with the given order already exists new link is added right after.
        /// </summary>
        /// <param name="header">Page header</param>
        /// <param name="cssPath">Path of CSS file</param>
        /// <param name="order">Desired order of CSS link</param>
        /// <param name="allowBundlingIfEnabled"></param>
        /// <param name="control">Source control, optional. It will be used to find the current CacheablePortlet and the script reference to it too.</param>
        public static void AddStyleSheetToHeader(Control header, string cssPath, int order, string rel, string type, string media, string title, bool allowBundlingIfEnabled = true, Control control = null)
        {
            if (header == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(cssPath))
            {
                return;
            }

            // Take care of folders
            if (ServiceTools.RecurseFilesInVirtualPath(SkinManager.Resolve(cssPath), true, p => AddStyleSheetToHeader(header, p, order, rel, type, media, title, allowBundlingIfEnabled, control)))
            {
                return;
            }

            var resolvedPath = SkinManager.Resolve(cssPath);

            if (allowBundlingIfEnabled && rel == "stylesheet" && type == "text/css" && PortalBundleOptions.Current.AllowCssBundling)
            {
                if (!string.IsNullOrEmpty(title))
                {
                    throw new Exception("The title attribute on link tags is not supported when CSS bundling is enabled.");
                }

                PortalBundleOptions.Current.EnableCssBundling(header);

                // If this is CSS stylesheet and bundling is enabled, add it to the bundle

                // Find the bundle object for the current media
                var bundle = PortalBundleOptions.Current.CssBundles.SingleOrDefault(x => x.Media == media);

                if (bundle == null)
                {
                    bundle = new CssBundle()
                    {
                        Media = media,
                    };
                    PortalBundleOptions.Current.CssBundles.Add(bundle);
                }

                // Add the current resolved path to the bundle
                if (PortalBundleOptions.CssIsBlacklisted(resolvedPath))
                {
                    bundle.AddPostponedPath(resolvedPath);
                }
                else
                {
                    bundle.AddPath(resolvedPath, order);
                }
            }
            else
            {
                // If bundling is disabled, fallback to the old behaviour

                var cssLink = new HtmlLink();
                cssLink.ID = "cssLink_" + resolvedPath.GetHashCode().ToString();

                // link already added to header
                if (header.FindControl(cssLink.ID) != null)
                {
                    return;
                }

                cssLink.Href = resolvedPath;
                cssLink.Attributes["rel"]      = rel;
                cssLink.Attributes["type"]     = type;
                cssLink.Attributes["media"]    = media;
                cssLink.Attributes["title"]    = title;
                cssLink.Attributes["cssorder"] = order.ToString();

                // find next control with higher order
                var  index = -1;
                bool found = false;
                foreach (Control headerControl in header.Controls)
                {
                    index++;

                    var link = headerControl as HtmlLink;
                    if (link == null)
                    {
                        continue;
                    }

                    var orderStr = link.Attributes["cssorder"];
                    if (string.IsNullOrEmpty(orderStr))
                    {
                        continue;
                    }

                    int linkOrder = Int32.MinValue;
                    if (Int32.TryParse(orderStr, out linkOrder) && linkOrder > order)
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    // add link right before higher order link
                    header.Controls.AddAt(index, cssLink);
                }
                else
                {
                    // add link at end of header's controlcollection
                    header.Controls.Add(cssLink);
                }
            }

            // Add stylesheet reference to cacheable portlet if possible, to
            // be able to add references even if the portlet html is cached.
            var cb = GetCacheablePortlet(control);

            if (cb != null)
            {
                cb.AddStyleSheet(new StyleSheetReference
                {
                    CssPath = cssPath,
                    Media   = media,
                    Order   = order,
                    Rel     = rel,
                    Title   = title,
                    Type    = type,
                    AllowBundlingIfEnabled = allowBundlingIfEnabled
                });
            }
        }
Exemple #19
0
        public void CanBundleCssWithLess()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();
            mockFileReaderFactory.SetContents(cssLess);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                .Add("~/css/test.less")
                .Render("~/css/output.css");

            string contents = mockFileWriterFactory.Files["~/css/output.css"];

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"css/output.css?r=350F6DC1A87E2503EE6D4AE414C4A479\" />", tag);
            Assert.AreEqual("#header,h2{color:#4d926f;}", contents);
        }
Exemple #20
0
        public void CanRenderDebugTagsWithMediaAttribute()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(true);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();
            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                .Add("/css/first.css")
                .Add("/css/second.css")
                .WithMedia("screen")
                .Render("/css/output.css");

            Assert.AreEqual(tag, "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/css/second.css\" />");
        }
Exemple #21
0
        public void CanRenderDebugTagsTwice()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(true);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();
            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle1 = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            ICssBundle cssBundle2 = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag1 = cssBundle1
                .Add("/css/first.css")
                .Add("/css/second.css")
                .Render("/css/output.css");

            string tag2 = cssBundle2
                .Add("/css/first.css")
                .Add("/css/second.css")
                .Render("/css/output.css");

            Assert.AreEqual(tag1, "<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/second.css\" />");
            Assert.AreEqual(tag2, "<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/first.css\" /><link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/second.css\" />");
        }
Exemple #22
0
        public void CanCreateNamedBundleWithMediaAttribute()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();
            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            cssBundle
                    .Add("~/css/temp.css")
                    .WithMedia("screen")
                    .AsNamed("TestWithMedia", "~/css/output.css");

            string tag = cssBundle.RenderNamed("TestWithMedia");

            Assert.AreEqual("li{margin-bottom:.1em;margin-left:0;margin-top:.1em;}th{font-weight:normal;vertical-align:bottom;}.FloatRight{float:right;}.FloatLeft{float:left;}", mockFileWriterFactory.Files["~/css/output.css"]);
            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"css/output.css?r=A757BD759BA228D91481798C2C49A8DC\" />", tag);
        }
Exemple #23
0
        public void CanCreateNamedBundleWithDebug()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(true);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();
            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            cssBundle
                    .Add("~/css/temp1.css")
                    .Add("~/css/temp2.css")
                    .AsNamed("TestWithDebug", "~/css/output.css");

            string tag = cssBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"css/temp1.css\" /><link rel=\"stylesheet\" type=\"text/css\"  href=\"css/temp2.css\" />", tag);
        }
Exemple #24
0
        public void CanBundleCssWithNullCompressorAttribute()
        {
            var mockDebugStatusReader = new StubDebugStatusReader(false);
            var mockFileWriterFactory = new StubFileWriterFactory();
            var mockFileReaderFactory = new StubFileReaderFactory();
            mockFileReaderFactory.SetContents(css);

            ICssBundle cssBundle = new CssBundle(mockDebugStatusReader,
                                                 mockFileWriterFactory,
                                                 mockFileReaderFactory);

            string tag = cssBundle
                            .Add("/css/first.css")
                            .Add("/css/second.css")
                            .WithCompressor(CssCompressors.NullCompressor)
                            .Render("/css/css_with_null_compressor_output.css");

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\"  href=\"/css/css_with_null_compressor_output.css?r=9650CBE3E753DF5F9146A2AF738A8272\" />", tag);
            Assert.AreEqual(1, mockFileWriterFactory.Files.Count);
            Assert.AreEqual(css + css, mockFileWriterFactory.Files["/css/css_with_null_compressor_output.css"]);
        }