public void Css_Global_Then_Style()
        {
            var stylePreprocessor = new StubStylePreprocessor();
            var globalPreprocessor = new StubGlobalPreprocessor();

            using(new StylePreprocessorScope<StubStylePreprocessor>(stylePreprocessor))
            using(new GlobalPreprocessorScope<StubGlobalPreprocessor>(globalPreprocessor))
            {
                CSSBundle cssBundle = cssBundleFactory
                    .WithHasher(hasher)
                    .WithDebuggingEnabled(false)
                    .WithContents("start")
                    .Create();

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

                string contents =
                    cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")];

                Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=hash\" />", tag);
                Assert.AreEqual("styley", contents);

                Assert.AreEqual("globey", stylePreprocessor.CalledWith);
                Assert.AreEqual("start", globalPreprocessor.CalledWith);
            }
        }
        public void Js_Global_Then_Style()
        {
            var scriptPreprocessor = new StubScriptPreprocessor();
            var globalPreprocessor = new StubGlobalPreprocessor();

            using(new ScriptPreprocessorScope<StubScriptPreprocessor>(scriptPreprocessor))
            using(new GlobalPreprocessorScope<StubGlobalPreprocessor>(globalPreprocessor))
            {
                JavaScriptBundle javaScriptBundle = javaScriptBundleFactory
                    .WithHasher(hasher)
                    .WithDebuggingEnabled(false)
                    .WithContents("start")
                    .Create();

                string tag = javaScriptBundle
                    .Add("~/js/test.script.global")
                    .Render("~/js/output.js");

                string contents =
                    javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")];

                Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=hash\"></script>", tag);
                Assert.AreEqual("scripty;\n", contents);

                Assert.AreEqual("globey", scriptPreprocessor.CalledWith);
                Assert.AreEqual("start", globalPreprocessor.CalledWith);
            }
        }
        public void Js_Skips_Extensions_With_No_Preprocessors()
        {
            var scriptPreprocessor = new StubScriptPreprocessor();
            var globalPreprocessor = new StubGlobalPreprocessor();

            using(new ScriptPreprocessorScope<StubScriptPreprocessor>(scriptPreprocessor))
            using(new GlobalPreprocessorScope<StubGlobalPreprocessor>(globalPreprocessor))
            {
                JavaScriptBundle javaScriptBundle = javaScriptBundleFactory
                    .WithHasher(hasher)
                    .WithDebuggingEnabled(false)
                    .WithContents("start")
                    .Create();

                string tag = javaScriptBundle
                    .Add("~/js/test.script.fake.global.bogus")
                    .Render("~/js/output.js");

                string contents =
                    javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")];

                Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=A87E7F7EA72FD18FC3E75FACD850E2EB\"></script>", tag);
                Assert.AreEqual("scripty", contents);

                Assert.AreEqual("globey", scriptPreprocessor.CalledWith);
                Assert.AreEqual("start", globalPreprocessor.CalledWith);
            }
        }
        public void WithPreprocessor_Uses_Instance_Preprocessors()
        {
            var stylePreprocessor = new StubStylePreprocessor();
            var globalPreprocessor = new StubGlobalPreprocessor();

            CSSBundle cssBundle = cssBundleFactory
                .WithHasher(hasher)
                .WithDebuggingEnabled(false)
                .WithContents("start")
                .Create();

            string tag = cssBundle
                .Add("~/css/test.style.global")
                .WithPreprocessor(stylePreprocessor)
                .WithPreprocessor(globalPreprocessor)
                .Render("~/css/output.css");

            string contents =
                cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")];

            Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/output.css?r=hash\" />", tag);
            Assert.AreEqual("styley", contents);

            Assert.AreEqual("globey", stylePreprocessor.CalledWith);
            Assert.AreEqual("start", globalPreprocessor.CalledWith);

            Assert.IsEmpty(Bundle.Preprocessors.Where(x => !(x is NullPreprocessor)));
        }
        public void WithPreprocessor_Uses_Instance_Preprocessors()
        {
            var scriptPreprocessor = new StubScriptPreprocessor();
            var globalPreprocessor = new StubGlobalPreprocessor();

            JavaScriptBundle javaScriptBundle = javaScriptBundleFactory
                .WithHasher(hasher)
                .WithDebuggingEnabled(false)
                .WithContents("start")
                .Create();

            string tag = javaScriptBundle
                .WithPreprocessor(scriptPreprocessor)
                .WithPreprocessor(globalPreprocessor)
                .Add("~/js/test.script.fake.global.bogus")
                .Render("~/js/output.js");

            string contents =
                javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")];

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=hash\"></script>", tag);
            Assert.AreEqual("scripty;\n", contents);

            Assert.AreEqual("globey", scriptPreprocessor.CalledWith);
            Assert.AreEqual("start", globalPreprocessor.CalledWith);

            Assert.IsEmpty(Bundle.Preprocessors);
        }