예제 #1
0
        public void GivenDifferentUrls_ThenExternalScriptBundlesNotEqual()
        {
            var b1 = new ExternalScriptBundle("http://test1.com/a", "a");
            var b2 = new ExternalScriptBundle("http://test2.com/a", "a");

            b1.Equals(b2).ShouldBeFalse();
        }
예제 #2
0
        public void GivenProcessedExternalScriptBundleWithFallbackCondition_WhenRender_ThenExternalRendererUsed()
        {
            var urlGenerator = new Mock <IUrlGenerator>();

            urlGenerator
            .Setup(g => g.CreateBundleUrl(It.IsAny <Bundle>()))
            .Returns("/");

            var bundle = new ExternalScriptBundle(Url, "~/test", "condition")
            {
                Renderer = new ScriptBundleHtmlRenderer(urlGenerator.Object),
                Pipeline = Mock.Of <IBundlePipeline <ScriptBundle> >()
            };
            var asset = new Mock <IAsset>();

            asset.SetupGet(a => a.Path).Returns("~/test/asset.js");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            bundle.Assets.Add(asset.Object);
            var settings = new CassetteSettings();

            bundle.Process(settings);

            var html = bundle.Render();

            html.ShouldEqual(@"<script src=""http://test.com/asset.js"" type=""text/javascript""></script>
<script type=""text/javascript"">
if(condition){
document.write('<script src=""/"" type=""text/javascript""><\/script>');
}
</script>");
        }
예제 #3
0
        public void GivenProcessedExternalScriptBundleWithFallbackCondition_WhenRender_ThenExternalRendererUsed()
        {
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator
                .Setup(g => g.CreateBundleUrl(It.IsAny<Bundle>()))
                .Returns("/");

            var bundle = new ExternalScriptBundle(Url, "~/test", "condition")
            {
                Renderer = new ScriptBundleHtmlRenderer(urlGenerator.Object),
                Pipeline = Mock.Of<IBundlePipeline<ScriptBundle>>()
            };
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.Path).Returns("~/test/asset.js");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            bundle.Assets.Add(asset.Object);
            var settings = new CassetteSettings();
            bundle.Process(settings);

            var html = bundle.Render();

            html.ShouldEqual(@"<script src=""http://test.com/asset.js"" type=""text/javascript""></script>
            <script type=""text/javascript"">
            if(condition){
            document.write('<script src=""/"" type=""text/javascript""><\/script>');
            }
            </script>");
        }
예제 #4
0
 void RenderScriptHtml(StringBuilder html, ExternalScriptBundle bundle)
 {
     html.AppendFormat(
         HtmlConstants.ScriptHtml,
         bundle.url,
         bundle.HtmlAttributes.CombinedAttributes
         );
 }
        string Render(ExternalScriptBundle bundle)
        {
            bundle.Renderer = fallbackRenderer.Object;
            bundle.Process(settings);
            var renderer = new ExternalScriptBundle.ExternalScriptBundleRenderer(settings);

            return(renderer.Render(bundle));
        }
예제 #6
0
        public void GetReferencedBundleUrlsReturnExternalUrlForExternalScriptBundle()
        {
            var bundle = new ExternalScriptBundle("http://example.com/", "~/test", "!test");
            bundle.Assets.Add(new StubAsset());

            referenceBuilder.Setup(b => b.GetBundles(null)).Returns(new[] { bundle });
            var urls = helper.GetReferencedBundleUrls<ScriptBundle>(null).ToArray();
            urls.ShouldEqual(new[] { "http://example.com/" });
        }
예제 #7
0
        public void WhenRenderExternalScriptBundle_ThenHtmlIsScriptElement()
        {
            var bundle           = new ExternalScriptBundle("http://test.com/");
            var fallbackRenderer = new Mock <IBundleHtmlRenderer <ScriptBundle> >();

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html     = renderer.Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\"></script>");
        }
 public void GivenManifestFallbackConditionIsNullThenElementHasNoFallbackConditionAttribute()
 {
     bundle = new ExternalScriptBundle("http://example.com/")
     {
         Hash     = new byte[0],
         Renderer = new ConstantHtmlRenderer <ScriptBundle>("", new VirtualDirectoryPrepender("/"))
     };
     SerializeToElement();
     element.Attribute("FallbackCondition").ShouldBeNull();
 }
        public ExternalScriptBundleSerializer_Tests()
        {
            bundle = new ExternalScriptBundle("http://example.com/", "~", "condition")
            {
                Hash = new byte[0],
                Renderer = new ConstantHtmlRenderer<ScriptBundle>("", new VirtualDirectoryPrepender("/"))
            };

            SerializeToElement();
        }
        public void WhenRenderExternalScriptBundle_ThenHtmlIsScriptElement()
        {
            var bundle = new ExternalScriptBundle("http://test.com/")
            {
                Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };
            var html = Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\"></script>");
        }
        public ExternalScriptBundleSerializer_Tests()
        {
            bundle = new ExternalScriptBundle("http://example.com/", "~", "condition")
            {
                Hash     = new byte[0],
                Renderer = new ConstantHtmlRenderer <ScriptBundle>("", new VirtualDirectoryPrepender("/"))
            };

            SerializeToElement();
        }
 public void GivenManifestFallbackConditionIsNullThenElementHasNoFallbackConditionAttribute()
 {
     bundle = new ExternalScriptBundle("http://example.com/")
     {
         Hash = new byte[0],
         Renderer = new ConstantHtmlRenderer<ScriptBundle>("", new VirtualDirectoryPrepender("/"))
     };
     SerializeToElement();
     element.Attribute("FallbackCondition").ShouldBeNull();
 }
        public void WhenRenderExternalScriptBundleWithCondition_ThenHtmlIsScriptElementWithConditional()
        {
            var bundle = new ExternalScriptBundle("http://test.com/") {Condition = "CONDITION"};
            var html = Render(bundle);

            html.ShouldEqual(
                "<!--[if CONDITION]>" + Environment.NewLine +
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<![endif]-->");
        }
예제 #14
0
        public void ProcessCallsProcessor()
        {
            var bundle = new ExternalScriptBundle(Url);
            var processor = new Mock<IBundleProcessor<ScriptBundle>>();
            var settings = new CassetteSettings("");

            bundle.Processor = processor.Object;
            bundle.Process(settings);

            processor.Verify(p => p.Process(bundle, settings));
        }
예제 #15
0
        public void ProcessCallsProcessor()
        {
            var bundle = new ExternalScriptBundle(Url);
            var processor = new Mock<IBundleProcessor<ScriptBundle>>();
            var settings = new CassetteSettings();

            bundle.Processor = processor.Object;
            bundle.Process(settings);

            processor.Verify(p => p.Process(bundle, settings));
        }
 public void GivenManifestFallbackConditionIsNullThenElementHasNoFallbackConditionAttribute()
 {
     bundle = new ExternalScriptBundle("http://example.com/")
     {
         Hash             = new byte[0],
         FallbackRenderer = new ScriptBundleHtmlRenderer(Mock.Of <IUrlGenerator>()),
         Renderer         = new ExternalScriptBundle.ExternalScriptBundleRenderer(new CassetteSettings())
     };
     SerializeToElement();
     element.Attribute("FallbackCondition").ShouldBeNull();
 }
        public ExternalScriptBundleSerializer_Tests()
        {
            bundle = new ExternalScriptBundle("http://example.com/", "~", "condition")
            {
                Hash             = new byte[0],
                FallbackRenderer = new ScriptBundleHtmlRenderer(Mock.Of <IUrlGenerator>()),
                Renderer         = new ExternalScriptBundle.ExternalScriptBundleRenderer(new CassetteSettings())
            };

            SerializeToElement();
        }
예제 #18
0
        public void ProcessCallsProcessor()
        {
            var bundle = new ExternalScriptBundle(Url);
            var pipeline = new Mock<IBundlePipeline<ScriptBundle>>();
            var settings = new CassetteSettings();

            bundle.Pipeline = pipeline.Object;
            bundle.Process(settings);

            pipeline.Verify(p => p.Process(bundle));
        }
예제 #19
0
 void RenderScriptHtmlWithFallback(StringBuilder html, ExternalScriptBundle bundle)
 {
     html.AppendFormat(
         HtmlConstants.ScriptHtmlWithFallback,
         bundle.url,
         bundle.HtmlAttributes.CombinedAttributes,
         bundle.FallbackCondition,
         CreateFallbackScripts(bundle),
         Environment.NewLine
         );
 }
예제 #20
0
        public void ProcessCallsProcessor()
        {
            var bundle   = new ExternalScriptBundle(Url);
            var pipeline = new Mock <IBundlePipeline <ScriptBundle> >();
            var settings = new CassetteSettings();

            bundle.Pipeline = pipeline.Object;
            bundle.Process(settings);

            pipeline.Verify(p => p.Process(bundle));
        }
 public void GivenManifestFallbackConditionIsNullThenElementHasNoFallbackConditionAttribute()
 {
     bundle = new ExternalScriptBundle("http://example.com/")
     {
         Hash = new byte[0],
         FallbackRenderer = new ScriptBundleHtmlRenderer(Mock.Of<IUrlGenerator>()),
         Renderer = new ExternalScriptBundle.ExternalScriptBundleRenderer(new CassetteSettings())
     };
     SerializeToElement();
     element.Attribute("FallbackCondition").ShouldBeNull();
 }
        public ExternalScriptBundleSerializer_Tests()
        {
            bundle = new ExternalScriptBundle("http://example.com/", "~", "condition")
            {
                Hash = new byte[0],
                FallbackRenderer = new ScriptBundleHtmlRenderer(Mock.Of<IUrlGenerator>()),
                Renderer = new ExternalScriptBundle.ExternalScriptBundleRenderer(new CassetteSettings())
            };

            SerializeToElement();
        }
        public void WhenRenderExternalScriptBundleWithHtmlAttributes_ThenHtmlIsScriptElementWithExtraAttributes()
        {
            var bundle = new ExternalScriptBundle("http://test.com/")
            {
                Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };

            bundle.HtmlAttributes["class"] = "foo";

            var html = Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\" class=\"foo\"></script>");
        }
        public void WhenRenderExternalScriptBundleWithNoLocalAssetsAndIsDebugMode_ThenNormalScriptElementIsReturned()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test")
            {
                Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };

            settings.IsDebuggingEnabled = true;

            var html = Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\"></script>");
        }
        public void WhenRenderExternalScriptBundleWithCondition_ThenHtmlIsScriptElementWithConditional()
        {
            var bundle = new ExternalScriptBundle("http://test.com/")
            {
                Condition = "CONDITION", Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };
            var html = Render(bundle);

            html.ShouldEqual(
                "<!--[if CONDITION]>" + Environment.NewLine +
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<![endif]-->");
        }
        public void WhenRenderExternalScriptBundleWithCondition_ThenHtmlIsScriptElementWithConditional()
        {
            var bundle = new ExternalScriptBundle("http://test.com/") {Condition = "CONDITION"};
            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html = renderer.Render(bundle);

            html.ShouldEqual(
                "<!--[if CONDITION]>" + Environment.NewLine +
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<![endif]-->");
        }
예제 #27
0
        public void WhenRenderExternalScriptBundleWithNotIECondition_ThenHtmlIsScriptElementWithConditionalButLeavesScriptVisibleToAllBrowsers()
        {
            var bundle = new ExternalScriptBundle("http://test.com/")
            {
                Condition = "(gt IE 9)|!(IE)", Pipeline = Mock.Of <IBundlePipeline <ScriptBundle> >()
            };

            var html = Render(bundle);

            html.ShouldEqual(
                "<!--[if " + bundle.Condition + "]><!-->" + Environment.NewLine +
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<!-- <![endif]-->");
        }
예제 #28
0
 public ExternalScriptModule(ExternalScriptBundle bundle, IModuleInitializer modules,string baseUrl = null)
 {
     this.modules = modules;
     this.Bundle = bundle;
     this.Path = bundle.Path;
     this.ReferencePaths = bundle.References;
     ModulePath = AssetModule.ConvertAssetPathToModulePath(bundle.Path, baseUrl);
     Alias = AssetModule.ConvertAssetPathToAlias(bundle.Path);
     externalUrl = bundle.ExternalUrl;
     if (externalUrl.EndsWith(".js"))
     {
         externalUrl = externalUrl.Substring(0, externalUrl.Length - 3);
     }
 }
        public void GivenExternalScriptBundleWithFallbackAssetsAndDebugMode_WhenRender_ThenOnlyOutputFallbackScripts()
        {
            settings.IsDebuggingEnabled = true;

            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            bundle.Assets.Add(new StubAsset());

            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns("<script></script>");

            var html = Render(bundle);

            html.ShouldEqual("<script></script>");
        }
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlEscapesFallbackScriptTags()
        {
            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();
            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            var asset = new Mock<IAsset>();
            bundle.Assets.Add(asset.Object);

            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns(("<script></script>"));

            var html = renderer.Render(bundle);

            html.ShouldContain("%3Cscript%3E%3C/script%3E");
        }
        public void WhenRenderExternalScriptBundleWithLocalAssetsAndIsDebugMode_ThenFallbackRendererUsed()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test")
            {
                Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };

            bundle.Assets.Add(new StubAsset());
            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns("FALLBACK");
            settings.IsDebuggingEnabled = true;

            var html = Render(bundle);

            html.ShouldEqual("FALLBACK");
        }
예제 #32
0
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlEscapesFallbackScriptTags()
        {
            var fallbackRenderer = new Mock <IBundleHtmlRenderer <ScriptBundle> >();
            var renderer         = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var bundle           = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            var asset            = new Mock <IAsset>();

            bundle.Assets.Add(asset.Object);

            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns(("<script></script>"));

            var html = renderer.Render(bundle);

            html.ShouldContain("%3Cscript%3E%3C/script%3E");
        }
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlEscapesFallbackScriptTags()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION")
            {
                Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };

            bundle.Assets.Add(new StubAsset());

            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns("<script></script>");

            var html = Render(bundle);

            html.ShouldContain("%3Cscript%3E%3C/script%3E");
        }
예제 #34
0
        public void GivenBundleIsProcessed_WhenRender_ThenExternalRendererUsed()
        {
            var bundle = new ExternalScriptBundle(Url, "~/test", "condition") { Processor = new ScriptPipeline() };
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/asset.js");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            bundle.Assets.Add(asset.Object);
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateBundleUrl(bundle)).Returns("/");
            var settings = new CassetteSettings("") { UrlGenerator = urlGenerator.Object };
            bundle.Process(settings);
            
            var html = bundle.Render();

            html.ShouldContain("condition");
        }
예제 #35
0
        public void WhenRenderExternalScriptBundleWithLocalAssetsAndIsDebugMode_ThenFallbackRendererUsed()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test");

            bundle.Assets.Add(Mock.Of <IAsset>());
            var fallbackRenderer = new Mock <IBundleHtmlRenderer <ScriptBundle> >();

            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns(("FALLBACK"));
            settings.IsDebuggingEnabled = true;

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html     = renderer.Render(bundle);

            html.ShouldEqual("FALLBACK");
        }
예제 #36
0
        public void GivenBundleIsProcessed_WhenRender_ThenExternalRendererUsed()
        {
            var bundle = new ExternalScriptBundle(Url, "~/test", "condition");
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/asset.js");
            asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
            bundle.Assets.Add(asset.Object);
            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateBundleUrl(bundle)).Returns("/");
            var settings = new CassetteSettings { UrlGenerator = urlGenerator.Object };
            bundle.Process(settings);

            var html = bundle.Render();

            html.ShouldContain("condition");
        }
        public void GivenExternalScriptBundleWithFallbackAssetsAndDebugMode_WhenRender_ThenOnlyOutputFallbackScripts()
        {
            settings.IsDebuggingEnabled = true;

            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            var asset = new Mock<IAsset>();
            bundle.Assets.Add(asset.Object);

            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();
            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns(("<script></script>"));

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html = renderer.Render(bundle);

            html.ShouldEqual("<script></script>");
        }
        public void GivenExternalScriptBundleWithFallbackAssetsAndDebugMode_WhenRender_ThenOnlyOutputFallbackScripts()
        {
            settings.IsDebuggingEnabled = true;

            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION")
            {
                Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };

            bundle.Assets.Add(new StubAsset());

            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns("<script></script>");

            var html = Render(bundle);

            html.ShouldEqual("<script></script>");
        }
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlContainsFallbackScript()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION") { Pipeline = Mock.Of<IBundlePipeline<ScriptBundle>>() };
            bundle.Assets.Add(new StubAsset());

            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns("FALLBACK");

            var html = Render(bundle);
            html.ShouldEqual(
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<script type=\"text/javascript\">" + Environment.NewLine +
                "if(CONDITION){" + Environment.NewLine +
                "document.write('FALLBACK');" + Environment.NewLine +
                "}" + Environment.NewLine +
                "</script>"
            );
        }
예제 #40
0
        public void GivenExternalScriptBundleWithFallbackAssetsAndDebugMode_WhenRender_ThenOnlyOutputFallbackScripts()
        {
            settings.IsDebuggingEnabled = true;

            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            var asset  = new Mock <IAsset>();

            bundle.Assets.Add(asset.Object);

            var fallbackRenderer = new Mock <IBundleHtmlRenderer <ScriptBundle> >();

            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns(("<script></script>"));

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html     = renderer.Render(bundle);

            html.ShouldEqual("<script></script>");
        }
예제 #41
0
            public string Render(ExternalScriptBundle bundle)
            {
                if (settings.IsDebuggingEnabled && bundle.Assets.Any())
                {
                    return(bundle.FallbackRenderer.Render(bundle));
                }

                var conditionalRenderer = new ConditionalRenderer();

                return(conditionalRenderer.Render(bundle.Condition, html =>
                {
                    if (bundle.Assets.Any())
                    {
                        RenderScriptHtmlWithFallback(html, bundle);
                    }
                    else
                    {
                        RenderScriptHtml(html, bundle);
                    }
                }));
            }
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlContainsFallbackScript()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            var asset = new Mock<IAsset>();
            bundle.Assets.Add(asset.Object);

            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();
            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns(("FALLBACK"));

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html = renderer.Render(bundle);

            html.ShouldEqual(
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<script type=\"text/javascript\">" + Environment.NewLine +
                "if(CONDITION){" + Environment.NewLine +
                "document.write(unescape('FALLBACK'));" + Environment.NewLine +
                "}" + Environment.NewLine +
                "</script>"
            );
        }
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlContainsFallbackScript()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION")
            {
                Processor = Mock.Of <IBundleProcessor <ScriptBundle> >()
            };

            bundle.Assets.Add(new StubAsset());

            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns("FALLBACK");

            var html = Render(bundle);

            html.ShouldEqual(
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<script type=\"text/javascript\">" + Environment.NewLine +
                "if(CONDITION){" + Environment.NewLine +
                "document.write(unescape('FALLBACK'));" + Environment.NewLine +
                "}" + Environment.NewLine +
                "</script>"
                );
        }
예제 #44
0
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlContainsFallbackScript()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            var asset  = new Mock <IAsset>();

            bundle.Assets.Add(asset.Object);

            var fallbackRenderer = new Mock <IBundleHtmlRenderer <ScriptBundle> >();

            fallbackRenderer.Setup(r => r.Render(bundle))
            .Returns(("FALLBACK"));

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html     = renderer.Render(bundle);

            html.ShouldEqual(
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<script type=\"text/javascript\">" + Environment.NewLine +
                "if(CONDITION){" + Environment.NewLine +
                "document.write(unescape('FALLBACK'));" + Environment.NewLine +
                "}" + Environment.NewLine +
                "</script>"
                );
        }
 public void WhenRenderExternalScriptBundle_ThenHtmlIsScriptElement()
 {
     var bundle = new ExternalScriptBundle("http://test.com/");
     var html = Render(bundle);
     html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\"></script>");
 }
 string Render(ExternalScriptBundle bundle)
 {
     bundle.Process(settings);
     bundle.FallbackRenderer = fallbackRenderer.Object;
     return(bundle.Render());
 }
        public void WhenRenderExternalScriptBundle_ThenHtmlIsScriptElement()
        {
            var bundle = new ExternalScriptBundle("http://test.com/");
            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html = renderer.Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\"></script>");
        }
        public void WhenRenderExternalScriptBundleWithLocalAssetsAndIsDebugMode_ThenFallbackRendererUsed()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test");
            bundle.Assets.Add(Mock.Of<IAsset>());
            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();
            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns(("FALLBACK"));
            settings.IsDebuggingEnabled = true;

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html = renderer.Render(bundle);

            html.ShouldEqual("FALLBACK");
        }
        public void WhenRenderExternalScriptBundleWithHtmlAttributes_ThenHtmlIsScriptElementWithExtraAttributes()
        {
            var bundle = new ExternalScriptBundle("http://test.com/");
            bundle.HtmlAttributes["class"] = "foo";
            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();

            var renderer = new ExternalScriptBundleHtmlRenderer(fallbackRenderer.Object, settings);
            var html = renderer.Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\" class=\"foo\"></script>");
        }
예제 #50
0
 public void GivenBundleHasPathAndUrl_WhenContainsPathUrl_ThenReturnTrue()
 {
     var bundle = new ExternalScriptBundle(Url, "path");
     bundle.ContainsPath(Url).ShouldBeTrue();
 }
예제 #51
0
 public void GivenBundleHasName_ContainsPathOfThatNameReturnsTrue()
 {
     var bundle = new ExternalScriptBundle(Url, "~/path");
     bundle.ContainsPath("~/path").ShouldBeTrue();
 }
        public void WhenRenderExternalScriptBundleWithHtmlAttributes_ThenHtmlIsScriptElementWithExtraAttributes()
        {
            var bundle = new ExternalScriptBundle("http://test.com/");
            bundle.HtmlAttributes["class"] = "foo";

            var html = Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\" class=\"foo\"></script>");
        }
예제 #53
0
 public void GivenBundleHasPathAndUrl_WhenContainsPathUrl_ThenReturnTrue()
 {
     var bundle = new ExternalScriptBundle(Url, "path");
     bundle.ContainsPath(Url).ShouldBeTrue();
 }
예제 #54
0
 public void SortBundlesToleratesExternalBundlesWhichAreNotInTheContainer()
 {
     var externalBundle1 = new ExternalScriptBundle("http://test.com/test1.js");
     var externalBundle2 = new ExternalScriptBundle("http://test.com/test2.js");
     var container = new BundleContainer(Enumerable.Empty<ScriptBundle>());
     var results = container.IncludeReferencesAndSortBundles(new[] { externalBundle1, externalBundle2 });
     results.SequenceEqual(new[] { externalBundle1, externalBundle2 }).ShouldBeTrue();
 }
        public void WhenRenderExternalScriptBundleWithLocalAssetsAndIsDebugMode_ThenFallbackRendererUsed()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test");
            bundle.Assets.Add(new StubAsset());
            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns("FALLBACK");
            settings.IsDebuggingEnabled = true;

            var html = Render(bundle);

            html.ShouldEqual("FALLBACK");
        }
        public void WhenRenderExternalScriptBundleWithNoLocalAssetsAndIsDebugMode_ThenNormalScriptElementIsReturned()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test");
            settings.IsDebuggingEnabled = true;

            var html = Render(bundle);

            html.ShouldEqual("<script src=\"http://test.com/\" type=\"text/javascript\"></script>");
        }
        public void WhenRenderExternalScriptBundleWithFallbackAsset_ThenHtmlEscapesFallbackScriptTags()
        {
            var bundle = new ExternalScriptBundle("http://test.com/", "test", "CONDITION");
            bundle.Assets.Add(new StubAsset());

            fallbackRenderer.Setup(r => r.Render(bundle))
                            .Returns("<script></script>");

            var html = Render(bundle);

            html.ShouldContain("%3Cscript%3E%3C/script%3E");
        }
        public void WhenRenderExternalScriptBundleWithNotIECondition_ThenHtmlIsScriptElementWithConditionalButLeavesScriptVisibleToAllBrowsers()
        {
            var bundle = new ExternalScriptBundle("http://test.com/") { Condition = "(gt IE 9)|!(IE)" };
            var fallbackRenderer = new Mock<IBundleHtmlRenderer<ScriptBundle>>();

            var html = bundle.Render(bundle);

            html.ShouldEqual(
                "<!--[if " + bundle.Condition + "]><!-->" + Environment.NewLine +
                "<script src=\"http://test.com/\" type=\"text/javascript\"></script>" + Environment.NewLine +
                "<!-- <![endif]-->");
        }
 void DeserializeToBundle()
 {
     bundle = reader.Deserialize(element, directory);
 }
 string Render(ExternalScriptBundle bundle)
 {
     bundle.Process(settings);
     bundle.FallbackRenderer = fallbackRenderer.Object;
     return bundle.Render();
 }