Exemplo n.º 1
0
        public void GivenRendererWithUrlGenerator_WhenRenderModule_ThenScriptHtmlIsReturned()
        {
            var urlGenerator = new Mock<IUrlGenerator>();
            var renderer = new ScriptModuleHtmlRenderer(urlGenerator.Object);
            var module = new ScriptModule("~/test");
            urlGenerator.Setup(g => g.CreateModuleUrl(module))
                        .Returns("URL");

            var html = renderer.Render(module).ToHtmlString();

            html.ShouldEqual("<script src=\"URL\" type=\"text/javascript\"></script>");
        }
Exemplo n.º 2
0
        public void GivenLocationAlreadyRendered_WhenAddReferenceToThatLocation_ThenExceptionThrown()
        {
            var module = new ScriptModule("~/test");
            moduleContainer.Setup(c => c.FindModuleContainingPath("~/test"))
                           .Returns(module);

            builder.Render("test");

            Assert.Throws<InvalidOperationException>(delegate
            {
                builder.Reference("~/test", "test");
            });
        }
Exemplo n.º 3
0
        public void GivenLocationAlreadyRenderedButHtmlRewrittingEnabled_WhenAddReferenceToThatLocation_ThenModuleStillAdded()
        {
            application.SetupGet(a => a.HtmlRewritingEnabled)
                       .Returns(true);
            var module = new ScriptModule("~/test");
            moduleContainer.Setup(c => c.FindModuleContainingPath("~/test"))
                           .Returns(module);
            builder.Render("test");

            builder.Reference("~/test", "test");

            builder.GetModules("test").First().ShouldBeSameAs(module);
        }
        public void GivenModuleWithTransformedAsset_WhenRenderModule_ThenScriptElementHasCompiledUrl()
        {
            var module = new ScriptModule("~/test");
            var asset = new Mock<IAsset>();
            module.Assets.Add(asset.Object);
            asset.SetupGet(a => a.HasTransformers)
                 .Returns(true);

            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(g => g.CreateAssetCompileUrl(module, asset.Object))
                        .Returns("COMPILED-URL");

            var renderer = new DebugScriptModuleHtmlRenderer(urlGenerator.Object);

            var html = renderer.Render(module).ToHtmlString();
            html.ShouldEqual("<script src=\"COMPILED-URL\" type=\"text/javascript\"></script>");
        }
        public void GivenModuleWithTwoAssets_WhenRenderModule_ThenScriptsElementReturnedForEachAsset()
        {
            var module = new ScriptModule("~/test");
            module.AddAssets(new[] { Mock.Of<IAsset>(), Mock.Of<IAsset>() }, true);

            var urlGenerator = new Mock<IUrlGenerator>();
            var assetUrls = new Queue<string>(new[] { "asset1", "asset2" });
            urlGenerator.Setup(g => g.CreateAssetUrl(It.IsAny<IAsset>()))
                        .Returns(assetUrls.Dequeue);

            var renderer = new DebugScriptModuleHtmlRenderer(urlGenerator.Object);

            var html = renderer.Render(module).ToHtmlString();

            html.ShouldEqual(
                "<script src=\"asset1\" type=\"text/javascript\"></script>" +
                Environment.NewLine +
                "<script src=\"asset2\" type=\"text/javascript\"></script>"
            );
        }
Exemplo n.º 6
0
        public void GivenModuleAReferencesModuleB_WhenAddReferenceToModuleA_ThenGetModulesReturnsBoth()
        {
            var moduleA = new ScriptModule("~/a");
            var moduleB = new ScriptModule("~/b");

            moduleContainer.Setup(c => c.FindModuleContainingPath("~/a"))
                           .Returns(moduleA);
            moduleContainer.Setup(c => c.IncludeReferencesAndSortModules(It.IsAny<IEnumerable<Module>>()))
                           .Returns(new[] { moduleB, moduleA });

            builder.Reference("a", null);

            builder.GetModules(null).SequenceEqual(new[] { moduleB, moduleA }).ShouldBeTrue();
        }
Exemplo n.º 7
0
        public void WhenAddReferenceWithLocation_ThenGetModulesForThatLocationReturnsTheModule()
        {
            var module = new ScriptModule("~/test");
            moduleContainer.Setup(c => c.FindModuleContainingPath("~/test"))
                           .Returns(module);
            moduleContainer.Setup(c => c.IncludeReferencesAndSortModules(It.IsAny<IEnumerable<Module>>()))
                           .Returns(new[] { module });
            builder.Reference("test", "body");

            builder.GetModules("body").SequenceEqual(new[] { module}).ShouldBeTrue();
        }
Exemplo n.º 8
0
        public void WhenAddReferenceToModuleDirectory_ThenGetModulesReturnTheModule()
        {
            var module = new ScriptModule("~/test");
            moduleContainer.Setup(c => c.FindModuleContainingPath("~/test"))
                           .Returns(module);
            moduleContainer.Setup(c => c.IncludeReferencesAndSortModules(It.IsAny<IEnumerable<Module>>()))
                           .Returns(new[] { module })
                           .Verifiable();
            builder.Reference("test", null);

            var modules = builder.GetModules(null).ToArray();

            modules[0].ShouldBeSameAs(module);
            moduleContainer.Verify();
        }
Exemplo n.º 9
0
        public void OnlyModulesMatchingLocationAreReturnedByGetModules()
        {
            var module1 = new ScriptModule("~/test1");
            var module2 = new ScriptModule("~/test2");
            module1.Location = "body";
            moduleContainer.Setup(c => c.FindModuleContainingPath("~/test1"))
                           .Returns(module1);
            moduleContainer.Setup(c => c.FindModuleContainingPath("~/test2"))
                           .Returns(module2);
            moduleContainer.Setup(c => c.IncludeReferencesAndSortModules(It.IsAny<IEnumerable<Module>>()))
                           .Returns(new[] { module1 });
            builder.Reference("test1", null);
            builder.Reference("test2", null);

            var modules = builder.GetModules("body").ToArray();
            modules.Length.ShouldEqual(1);
            modules[0].ShouldBeSameAs(module1);
        }
Exemplo n.º 10
0
 ScriptModule StubScriptModule(string path)
 {
     var module = new ScriptModule(path);
     var asset = new Mock<IAsset>();
     asset.SetupGet(a => a.Hash).Returns(new byte[] { 1, 2, 3 });
     module.Assets.Add(asset.Object);
     return module;
 }