/**
 * @param messageBundleFactory Used for injecting message bundles into gadget output.
 */
  public RenderingContentRewriter()
  {
      messageBundleFactory = DefaultMessageBundleFactory.Instance;
      containerConfig = JsonContainerConfig.Instance;
      featureRegistry = GadgetFeatureRegistry.Instance;
      urlGenerator = DefaultUrlGenerator.Instance;
  }
Example #2
0
 public BundlesHelper_Tests()
 {
     settings = new CassetteSettings();
     bundles = new BundleCollection(settings, Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>(), Mock.Of<IBundleCollectionInitializer>());
     referenceBuilder = new Mock<IReferenceBuilder>();
     var urlModifier = new VirtualDirectoryPrepender("/");
     var urlGenerator = new UrlGenerator(urlModifier, new FakeFileSystem(), "cassette.axd/");
     helper = new BundlesHelper(bundles, settings, urlGenerator, () => referenceBuilder.Object, Mock.Of<IFileAccessAuthorization>(), Mock.Of<IBundleCacheRebuilder>(), new SimpleJsonSerializer());
 }
Example #3
0
        public void InsertsAssetSourceFilenameWithBackSlashesConvertedToForwardSlashes()
        {
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFilename).Returns("~/test/sub/asset.js");
            var app = new UrlGenerator("/");

            var url = app.CreateAssetUrl(asset.Object);

            url.ShouldStartWith("/test/sub/asset.js");
        }
Example #4
0
        public void AppendsHashHexString()
        {
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFilename).Returns("~/test/sub/asset.js");
            asset.SetupGet(a => a.Hash).Returns(new byte[] { 1, 2, 15, 16 });
            var app = new UrlGenerator("/");

            var url = app.CreateAssetUrl(asset.Object);

            url.ShouldEqual("/test/sub/asset.js?01020f10");
        }
Example #5
0
        public void CreateAssetCompileUrlReturnsCompileUrl()
        {
            var module = new Module("~/test");
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFilename).Returns("~/test/asset.coffee");
            asset.SetupGet(a => a.Hash).Returns(new byte[] { 1, 2, 15, 16 });
            var app = new UrlGenerator("/");

            var url = app.CreateAssetCompileUrl(module, asset.Object);

            url.ShouldEqual("/_assets/get/test/asset.coffee?01020f10");
        }
        public static TreeView CreateTreeView(HtmlTextWriter writer, ITreeViewHtmlBuilder renderer, IClientSideObjectWriter clientSideObjectWriter)
        {
            Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            if (writer != null)
            {
                httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(writer);
            }

            urlGenerator = new UrlGenerator();
            authorization = new Mock<INavigationItemAuthorization>();

            Mock<ITreeViewHtmlBuilderFactory> TreeViewRendererFactory = new Mock<ITreeViewHtmlBuilderFactory>();

            Mock<IViewDataContainer> viewDataContainer = new Mock<IViewDataContainer>();

            var viewDataDinctionary = new ViewDataDictionary();
            viewDataDinctionary.Add("sample", TestHelper.CreateXmlSiteMap());

            viewDataContainer.SetupGet(container => container.ViewData).Returns(viewDataDinctionary);

            // needed for testing serialization
            Mock<IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<IClientSideObjectWriterFactory>();

            viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = viewDataDinctionary;

            clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextWriter>())).Returns(clientSideObjectWriter);

            viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = viewDataDinctionary;

            authorization.Setup(a => a.IsAccessibleToUser(viewContext.RequestContext, It.IsAny<INavigatable>())).Returns(true);

            TreeView TreeView = new TreeView(viewContext, clientSideObjectWriterFactory.Object, urlGenerator, authorization.Object, TreeViewRendererFactory.Object);

            renderer = renderer ?? new TreeViewHtmlBuilder(TreeView, new Mock<IActionMethodCache>().Object);
            TreeViewRendererFactory.Setup(f => f.Create(It.IsAny<TreeView>())).Returns(renderer);

            return TreeView;
        }
        public static PanelBar CreatePanelbar(HtmlTextWriter writer, INavigationComponentHtmlBuilder<PanelBarItem> renderer)
        {
            Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            if (writer != null)
            {
               httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(writer);
            }

            Mock<INavigationComponentHtmlBuilderFactory<PanelBar, PanelBarItem>> panelBarRendererFactory = new Mock<INavigationComponentHtmlBuilderFactory<PanelBar, PanelBarItem>>();

            Mock<IViewDataContainer> viewDataContainer = new Mock<IViewDataContainer>();
            var viewDataDinctionary = new ViewDataDictionary();
            viewDataDinctionary.Add("sample", TestHelper.CreateXmlSiteMap());

            viewDataContainer.SetupGet(container => container.ViewData).Returns(viewDataDinctionary);

            Mock<IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<IClientSideObjectWriterFactory>();
            clientSideObjectWriter = new Mock<IClientSideObjectWriter>();
            IUrlGenerator urlGeneratorObject = new UrlGenerator();
            Mock<INavigationItemAuthorization> authorization = new Mock<INavigationItemAuthorization>();

            TestHelper.RegisterDummyRoutes();

            ViewContext viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = viewDataDinctionary;

            authorization.Setup(a => a.IsAccessibleToUser(viewContext.RequestContext, It.IsAny<INavigatable>())).Returns(true);
            clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextWriter>())).Returns(clientSideObjectWriter.Object);

            PanelBar panelBar = new PanelBar(viewContext, clientSideObjectWriterFactory.Object, urlGeneratorObject, authorization.Object, panelBarRendererFactory.Object);

            renderer = renderer ?? new PanelBarHtmlBuilder(panelBar, new Mock<IActionMethodCache>().Object);
            panelBarRendererFactory.Setup(f => f.Create(It.IsAny<PanelBar>())).Returns(renderer);

            return panelBar;
        }
        public static Menu CreateMenu(HtmlTextWriter writer, INavigationComponentHtmlBuilder<MenuItem> renderer)
        {
            Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            if (writer != null)
            {
                httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(writer);
            }

            Mock<INavigationComponentHtmlBuilderFactory<Menu, MenuItem>> menuRendererFactory = new Mock<INavigationComponentHtmlBuilderFactory<Menu, MenuItem>>();

            Mock<IViewDataContainer> viewDataContainer = new Mock<IViewDataContainer>();
            var viewDataDinctionary = new ViewDataDictionary();
            viewDataDinctionary.Add("sample", TestHelper.CreateXmlSiteMap());

            viewDataContainer.SetupGet(container => container.ViewData).Returns(viewDataDinctionary);

            // needed for testing serialization
            Mock<ClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<ClientSideObjectWriterFactory>();

            UrlGenerator urlGeneratorObject = new UrlGenerator();
            Mock<INavigationItemAuthorization> authorization = new Mock<INavigationItemAuthorization>();

            TestHelper.RegisterDummyRoutes();

            ViewContext viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = viewDataDinctionary;

            authorization.Setup(a => a.IsAccessibleToUser(viewContext.RequestContext, It.IsAny<INavigatable>())).Returns(true);

            Menu menu = new Menu(viewContext, clientSideObjectWriterFactory.Object, urlGeneratorObject, authorization.Object, menuRendererFactory.Object);

            renderer = renderer ?? new MenuHtmlBuilder(menu, new Mock<IActionMethodCache>().Object);
            menuRendererFactory.Setup(f => f.Create(It.IsAny<Menu>())).Returns(renderer);

            return menu;
        }
Example #9
0
 public void ArgumentExceptionThrownWhenFilenameDoesNotStartWithTilde()
 {
     var generator = new UrlGenerator("/");
     Assert.Throws<ArgumentException>(delegate
     {
         generator.CreateRawFileUrl("fail.png", "hash");
     });
 }
Example #10
0
 public void InsertsModuleDirectoryWithBackSlashesConvertedToForwardSlashes()
 {
     var app = new UrlGenerator("/");
     var url = app.CreateModuleUrl(StubScriptModule("~\\test\\foo\\bar"));
     url.ShouldStartWith("/_assets/scripts/test/foo/bar");
 }
Example #11
0
 public void InsertsLowercasedPluralisedStylesheetModuleTypeName()
 {
     var app = new UrlGenerator("/");
     var url = app.CreateModuleUrl(StubStylesheetModule("~/test"));
     url.ShouldStartWith("/_assets/stylesheets/");
 }
Example #12
0
 public void AppendsSlashToVirtualDirectoryWhenMissingFromEnd()
 {
     var app = new UrlGenerator("/myapp");
     var url = app.CreateModuleUrl(StubScriptModule("~/test"));
     url.ShouldStartWith("/myapp/");
 }
Example #13
0
 public void AppendsModuleHashHexString()
 {
     var app = new UrlGenerator("/");
     var url = app.CreateModuleUrl(StubScriptModule("~\\test\\foo\\bar"));
     url.ShouldEqual("/_assets/scripts/test/foo/bar_010203");
 }
Example #14
0
 public void CreateImageUrlPrependsHandlerRoute()
 {
     var generator = new UrlGenerator("/");
     var url = generator.CreateRawFileUrl("~/test.png", "hash");
     url.ShouldStartWith("/_assets/images/");
 }
Example #15
0
 public void CreateImageUrlConvertsFileExtensinDotToUnderscore()
 {
     var generator = new UrlGenerator("/");
     var url = generator.CreateRawFileUrl("~/test.png", "hash");
     url.ShouldStartWith("/_assets/images/test_hash_png");
 }
Example #16
0
 public void ConvertsToForwardSlashes()
 {
     var generator = new UrlGenerator("/");
     var url = generator.CreateRawFileUrl("~\\test\\foo.png", "hash");
     url.ShouldEqual("/_assets/images/test/foo_hash_png");
 }
Example #17
0
        public void InsertsModuleDirectory()
        {
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFilename).Returns("~/test/asset.js");
            var app = new UrlGenerator("/myapp");

            var url = app.CreateAssetUrl(asset.Object);

            url.ShouldStartWith("/myapp/test/");
        }
Example #18
0
 public void Inserts_assetsPrefix()
 {
     var app = new UrlGenerator("/");
     var url = app.CreateModuleUrl(StubScriptModule("~/test"));
     url.ShouldStartWith("/_assets/");
 }
Example #19
0
        protected UrlGenerator_Tests()
        {
            UrlModifier.Setup(m => m.Modify(It.IsAny<string>()))
                       .Returns<string>(url => url);

            var container = new Mock<ICassetteApplicationContainer<ICassetteApplication>>();
            container.SetupGet(c => c.Application.Bundles).Returns(Enumerable.Empty<Bundle>());
            UrlGenerator = new UrlGenerator(UrlModifier.Object, "_cassette");
        }
Example #20
0
 public void UrlStartsWithApplicationVirtualDirectory()
 {
     var app = new UrlGenerator("/");
     var url = app.CreateModuleUrl(StubScriptModule("~/test"));
     url.ShouldStartWith("/");
 }
Example #21
0
 public void GetImageRouteUrl_ReturnsRouteUrlWithPathParameter()
 {
     var app = new UrlGenerator("/");
     var url = app.GetRawFileRouteUrl();
     url.ShouldEqual("_assets/file/{*path}");
 }
Example #22
0
 public void GetModuleRouteUrl_InsertsConventionalHtmlTemplateModuleName()
 {
     var app = new UrlGenerator("/");
     var url = app.GetModuleRouteUrl<HtmlTemplateModule>();
     url.ShouldEqual("_assets/htmltemplates/{*path}");
 }
Example #23
0
 public RawFileCopier(string absoluteSourceDirectory, string outputDirectory)
 {
     this.absoluteSourceDirectory = absoluteSourceDirectory;
     urlGenerator = new UrlGenerator(new CombinePathWithUrl(outputDirectory), new FileSystemDirectory(absoluteSourceDirectory), "");
 }
Example #24
0
 public void GetModuleRouteUrl_InsertsConventionalStylesheetModuleName()
 {
     var app = new UrlGenerator("/");
     var url = app.GetModuleRouteUrl<StylesheetModule>();
     url.ShouldEqual("_assets/stylesheets/{*path}");
 }
        public UrlGeneratorTests()
        {
            TestHelper.RegisterDummyRoutes();

            _urlGenerator = new UrlGenerator();
        }
Example #26
0
        public void StartsWithApplicationVirtualDirectoryEndingInSlash()
        {
            var asset = new Mock<IAsset>();
            asset.SetupGet(a => a.SourceFilename).Returns("~/test/asset.js");
            var app = new UrlGenerator("/myapp");

            var url = app.CreateAssetUrl(asset.Object);

            url.ShouldStartWith("/myapp/");
        }