/// <summary> /// Gets the layout name from template title. This method will strip and replace the special characters. /// </summary> /// <param name="templateTitle">The template title.</param> /// <returns></returns> public virtual string GetLayoutName(string templateTitle) { templateTitle = this.StripPackageNameFromTemplateName(templateTitle); var packagesManager = new PackageManager(); return packagesManager.StripInvalidCharacters(templateTitle); }
/// <summary> /// Registering the scripts for ZoneEditor. /// </summary> /// <param name="event">The event.</param> private void RegisteringScriptsHandler(IScriptsRegisteringEvent @event) { if (@event.Sender.GetType() == typeof(ZoneEditor)) { var scriptRootPath = "~/" + FrontendManager.VirtualPathBuilder.GetVirtualPath(this.GetType().Assembly); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/Angular/angular.min.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/Angular/angular-route.min.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/Bootstrap/js/ui-bootstrap-tpls-0.11.0.min.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Designers/Scripts/page-editor-services.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Designers/Scripts/page-editor.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/Kendo/angular-kendo.js")); var currentPackage = new PackageManager().GetCurrentPackage(); if (!currentPackage.IsNullOrEmpty()) { var packageVar = "var sf_package = '{0}';".Arrange(currentPackage); ((ZoneEditor)@event.Sender).Page.ClientScript.RegisterStartupScript(@event.Sender.GetType(), "sf_package", packageVar + @"Sys.Net.WebRequestManager.add_invokingRequest(function (executor, args) { var url = args.get_webRequest().get_url(); if (url.indexOf('?') == -1) url += '?package=' + encodeURIComponent(sf_package); else url += '&package=' + encodeURIComponent(sf_package); args.get_webRequest().set_url(url); });", addScriptTags: true); } } }
public void EnhanceUrl_NoPackage_AppendsPackageUrlParam() { //Arrange string url = "http://mysite/"; string expectedEnhancedUrl = url; //Act url = new PackageManager().EnhanceUrl(url); //Assert Assert.AreEqual(expectedEnhancedUrl, url, "The URL was modified."); }
/// <summary> /// Registering the scripts for ZoneEditor. /// </summary> /// <param name="event">The event.</param> private void RegisteringScriptsHandler(IScriptsRegisteringEvent @event) { if (@event.Sender.GetType() == typeof(ZoneEditor)) { var scriptRootPath = "~/" + FrontendManager.VirtualPathBuilder.GetVirtualPath(this.GetType().Assembly); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/Angular/angular.min.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/Angular/angular-route.min.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/Bootstrap/js/ui-bootstrap-tpls.min.js")); ////var references = PageManager.GetScriptReferences(ScriptRef.KendoAll); ////foreach (var scriptRef in references) ////{ //// @event.Scripts.Add(scriptRef); ////} @event.Scripts.Add(new ScriptReference(scriptRootPath + "Designers/Scripts/page-editor-services.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Designers/Scripts/page-editor.js")); @event.Scripts.Add(new ScriptReference(scriptRootPath + "Mvc/Scripts/LABjs/LAB.min.js")); var currentPackage = new PackageManager().GetCurrentPackage(); if (!currentPackage.IsNullOrEmpty()) { var sb = new StringBuilder(); sb.AppendLine(@"Sys.Net.WebRequestManager.add_invokingRequest(function (executor, args) {"); sb.AppendLine("var url = args.get_webRequest().get_url();"); sb.AppendLine("if (url.indexOf('?') == -1)"); sb.AppendLine(" url += '?package=' + encodeURIComponent(sf_package);"); sb.AppendLine("else"); sb.AppendLine(" url += '&package=' + encodeURIComponent(sf_package); "); sb.AppendLine("args.get_webRequest().set_url(url); "); sb.AppendLine("});"); var packageVar = "var sf_package = '{0}';".Arrange(currentPackage); ((ZoneEditor)@event.Sender).Page.ClientScript.RegisterStartupScript( @event.Sender.GetType(), "sf_package", packageVar + sb, addScriptTags: true); var zoneEditor = @event.Sender as ZoneEditor; if (zoneEditor != null) { var urlhelper = new UrlHelper(HttpContext.Current.Request.RequestContext); var url = urlhelper.Content("~/ResourcePackages/{0}/assets/dist/css/styles.min.css".Arrange(currentPackage)); var packageStyleMarkup = "<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\">".Arrange(url); var packageStyleLiteralControl = new LiteralControl(packageStyleMarkup); zoneEditor.Page.Header.Controls.Add(packageStyleLiteralControl); } } } }
/// <summary> /// Builds the path from template title. /// </summary> /// <param name="templateTitle">Title of the template.</param> /// <returns> Resolved path will be in the following format: "~/SfLayouts/some_title.master"</returns> public virtual string BuildPathFromTitle(string templateTitle) { var templateFileNameParser = new TemplateTitleParser(); var fileName = templateFileNameParser.GetLayoutName(templateTitle); var layoutVirtualPath = string.Format(System.Globalization.CultureInfo.InvariantCulture, LayoutVirtualPathBuilder.LayoutVirtualPathTemplate, LayoutVirtualPathBuilder.LayoutsPrefix, fileName, LayoutVirtualPathBuilder.LayoutSuffix); var packagesManager = new PackageManager(); var currentPackage = packagesManager.GetCurrentPackage(); layoutVirtualPath = (new VirtualPathBuilder()).AddParams(layoutVirtualPath, currentPackage); return layoutVirtualPath; }
/// <summary> /// Strips the name of the package name from template. /// If there is no existing package presented on the searched location the method will preserve the full template name. /// </summary> /// <param name="templateTitle">Title of the template.</param> /// <returns></returns> private string StripPackageNameFromTemplateName(string templateTitle) { var parts = templateTitle.Split('.'); if (parts.Length > 1) { var packagesManager = new PackageManager(); var packageVirtualPath = packagesManager.GetPackageVirtualPath(parts[0]); var packagePath = HostingEnvironment.MapPath(packageVirtualPath); if (Directory.Exists(packagePath)) templateTitle = string.Join(".", parts, 1, parts.Length - 1); } return templateTitle; }
public void EnhanceUrl_HasPackage_AppendsPackageUrlParam() { // Arrange: Initialize the PackageManager and create fake HttpContextWrapper which has fake request URL with the package name set as query parameter. string url = "http://mysite/"; string expectedEnhancedUrl = url + "?package=testPackageName"; var context = new HttpContextWrapper( new HttpContext( new HttpRequest(null, "http://tempuri.org", "package=testPackageName"), new HttpResponse(null))); // Act: Get the enhanced URL from the package manager. SystemManager.RunWithHttpContext(context, () => { url = new PackageManager().EnhanceUrl(url); }); // Assert: Verify if the manager appends package param. Assert.AreEqual(expectedEnhancedUrl, url, "The URL does not contain the package name."); }
private static IList<Func<string, string>> GetControllerPathTransformations(Controller controller, string customPath) { var packagesManager = new PackageManager(); var currentPackage = packagesManager.GetCurrentPackage(); var pathTransformations = new List<Func<string, string>>(); if (controller.RouteData != null && controller.RouteData.Values.ContainsKey("widgetName")) { var widgetName = (string)controller.RouteData.Values["widgetName"]; var controllerType = FrontendManager.ControllerFactory.ResolveControllerType(widgetName); var widgetVp = FrontendControllerFactory.AppendDefaultPath(FrontendManager.VirtualPathBuilder.GetVirtualPath(controllerType)); pathTransformations.Add(FrontendControllerFactory.GetPathTransformation(widgetVp, currentPackage, widgetName)); } var controllerVp = customPath ?? FrontendControllerFactory.AppendDefaultPath(FrontendManager.VirtualPathBuilder.GetVirtualPath(controller.GetType().Assembly)); pathTransformations.Add(FrontendControllerFactory.GetPathTransformation(controllerVp, currentPackage)); return pathTransformations; }
/// <summary> /// Resolves URL based on the current widget. /// </summary> /// <param name="helper">The URL helper.</param> /// <param name="contentPath">The content path.</param> /// <returns>Resolved URL.</returns> /// <exception cref="System.ArgumentNullException">contentPath</exception> /// <exception cref="System.InvalidOperationException"> /// Could not resolve the given URL because RouteData of the current context is null. /// or /// Could not resolve the given URL because RouteData does not contain \controller\ key. /// </exception> public static string WidgetContent(this UrlHelper helper, string contentPath) { if (contentPath.IsNullOrEmpty()) throw new ArgumentNullException("contentPath"); var packagesManager = new PackageManager(); var packageName = packagesManager.GetCurrentPackage(); if (contentPath.StartsWith("~", StringComparison.Ordinal) || contentPath.StartsWith("/", StringComparison.Ordinal) || contentPath.Contains("://")) { var url = UrlTransformations.AppendParam(contentPath, PackageManager.PackageUrlParameterName, packageName); return helper.Content(url); } if (helper.RequestContext.RouteData == null) throw new InvalidOperationException("Could not resolve the given URL because RouteData of the current context is null."); var contentResolvedPath = string.Empty; object controllerName; // "widgetName" is a parameter in the route of the Designer. It allows us to have a special fallback logic // where we first check for the requested resource in the widget assembly and then fallback to the current controller assembly. if (helper.RequestContext.RouteData.Values.TryGetValue("widgetName", out controllerName)) contentResolvedPath = UrlHelpers.GetResourcePath((string)controllerName, contentPath, PackageManager.PackageUrlParameterName, packageName); if (string.IsNullOrEmpty(contentResolvedPath)) { if (helper.RequestContext.RouteData.Values.TryGetValue("controller", out controllerName)) contentResolvedPath = UrlHelpers.GetResourcePath((string)controllerName, contentPath, PackageManager.PackageUrlParameterName, packageName); else throw new InvalidOperationException("Could not resolve the given URL because RouteData does not contain \"controller\" key."); } if (string.IsNullOrEmpty(contentResolvedPath)) { var url = "~/" + FrontendManager.VirtualPathBuilder.GetVirtualPath(typeof(UrlHelpers).Assembly) + contentPath; contentResolvedPath = UrlTransformations.AppendParam(url, PackageManager.PackageUrlParameterName, packageName); } return helper.Content(contentResolvedPath); }
/// <summary> /// Gets the key to be used in the view engine collection dictionary based on the controller type and the widget name. /// </summary> /// <param name="controller">The controller.</param> private static string GetKey(Controller controller) { const string WidgetNameKey = "widgetName"; var key = controller.GetType().FullName; if (controller.RouteData != null && controller.RouteData.Values != null && controller.RouteData.Values.ContainsKey(WidgetNameKey)) { var widgetName = (string)controller.RouteData.Values[WidgetNameKey]; key = string.Format("{0}-{1}", key, widgetName); } var currentPackage = new PackageManager().GetCurrentPackage(); if (!currentPackage.IsNullOrEmpty()) { key += "-" + currentPackage; } return key; }
/// <summary> /// Gets the path transformations. /// </summary> /// <returns></returns> private IList<Func<string, string>> GetPathTransformations() { var packagesManager = new PackageManager(); var currentPackage = packagesManager.GetCurrentPackage(); var pathTransformations = new List<Func<string, string>>(1); var baseVirtualPath = FrontendManager.VirtualPathBuilder.GetVirtualPath(this.GetType().Assembly); pathTransformations.Add(path => { // {1} is the ControllerName argument in VirtualPathProviderViewEngines var result = path .Replace("{1}", "Layouts") .Replace("~/", "~/{0}Mvc/".Arrange(baseVirtualPath)); result = (new VirtualPathBuilder()).AddParams(result, currentPackage); return result; }); return pathTransformations; }
/// <inheritDoc/> public virtual string GetViewPath() { var currentPackage = new PackageManager().GetCurrentPackage(); if (string.IsNullOrEmpty(currentPackage)) { currentPackage = "default"; } var viewPath = FormsVirtualRazorResolver.Path + currentPackage + "/" + this.FormId.ToString("D") + ".cshtml"; return viewPath; }
/// <summary> /// Populates the script references. /// </summary> /// <param name="widgetName">Name of the widget.</param> /// <param name="viewConfigs">The view configs.</param> protected void PopulateScriptReferences(string widgetName, IEnumerable<KeyValuePair<string, DesignerViewConfigModel>> viewConfigs) { var packagesManager = new PackageManager(); var packageName = packagesManager.GetCurrentPackage(); var designerWidgetName = FrontendManager.ControllerFactory.GetControllerName(typeof(DesignerController)); var viewScriptReferences = new List<string>(this.views.Count()); foreach (var view in this.views) { var scriptFileName = this.GetViewScriptFileName(view); var scriptPath = this.GetScriptPath(scriptFileName, widgetName, packageName); if (VirtualPathManager.FileExists(scriptPath)) { viewScriptReferences.Add(this.GetScriptReferencePath(widgetName, scriptFileName)); } else { scriptPath = this.GetScriptPath(scriptFileName, designerWidgetName, packageName); if (VirtualPathManager.FileExists(scriptPath)) viewScriptReferences.Add(this.GetScriptReferencePath(designerWidgetName, scriptFileName)); } } var configuredScriptReferences = viewConfigs .Where(c => c.Value.Scripts != null) .SelectMany(c => c.Value.Scripts); this.scriptReferences = viewScriptReferences .Union(configuredScriptReferences) .Distinct(); }
/// <summary> /// Adds variable parameters to the virtual path to allow caching of multiple versions based on parameters. /// </summary> /// <param name="layoutVirtualPath">The layout virtual path.</param> /// <returns>The path with appended variables.</returns> protected virtual string AddVariablesToPath(string layoutVirtualPath) { var packagesManager = new PackageManager(); var currentPackage = packagesManager.GetCurrentPackage(); layoutVirtualPath = (new VirtualPathBuilder()).AddParams(layoutVirtualPath, currentPackage ?? "_"); return layoutVirtualPath; }
/// <summary> /// Sends a parsed template that is processed with the Razor engine. /// </summary> /// <param name="context">The context.</param> protected virtual void SendParsedTemplate(HttpContext context) { context.Response.ContentType = "text/html"; var packagesManager = new PackageManager(); var packageName = packagesManager.GetCurrentPackage(); var templatePath = context.Request.Url.AbsolutePath; if (!string.IsNullOrEmpty(packageName)) { templatePath += "#" + packageName; } var output = this.parser.Process(templatePath); this.WriteToOutput(context, context.Response.ContentEncoding.GetBytes(output)); }
public void GetPackageFromUrl_FakeCurrentUrlInHttpContext_VerifyThePackageNameIsCorrect() { //Arrange: Initialize the PackageManager and create fake HttpContextWrapper which has fake request URL with the package name set as query parameter var packageManager = new PackageManager(); string packageName = string.Empty; var context = new HttpContextWrapper(new HttpContext( new HttpRequest(null, "http://tempuri.org", "package=testPackageName"), new HttpResponse(null))); //Act: Get the package name from the request URL query string SystemManager.RunWithHttpContext(context, () => { packageName = packageManager.GetPackageFromUrl(); }); //Assert: Verify if the manager properly strips all invalid characters Assert.AreEqual<string>("testPackageName", packageName, "The package name was not resolved correctly"); }
/// <summary> /// Initializes the widget commands. /// </summary> /// <returns> /// The <see cref="IList"/>. /// </returns> protected virtual IList<WidgetMenuItem> InitializeCommands() { var packageManager = new PackageManager(); var commandsList = new List<WidgetMenuItem>(5); commandsList.Add( new WidgetMenuItem { Text = Res.Get<Labels>().Delete, CommandName = "beforedelete", CssClass = "sfDeleteItm" }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<Labels>().Duplicate, CommandName = "duplicate", CssClass = "sfDuplicateItm" }); if (this.SharedContentID == Guid.Empty) { var shareActionLink = packageManager.EnhanceUrl( RouteHelper.ResolveUrl(string.Format(CultureInfo.InvariantCulture, DesignerTemplate, "Share"), UrlResolveOptions.Rooted)); commandsList.Add( new WidgetMenuItem { Text = Res.Get<ContentBlockResources>().Share, ActionUrl = shareActionLink, NeedsModal = true }); } else { var unshareActionLink = packageManager.EnhanceUrl( RouteHelper.ResolveUrl(string.Format(CultureInfo.InvariantCulture, DesignerTemplate, "Unshare"), UrlResolveOptions.Rooted)); commandsList.Add( new WidgetMenuItem { Text = Res.Get<ContentBlockResources>().Unshare, ActionUrl = unshareActionLink, NeedsModal = true }); } var useSharedActionLink = packageManager.EnhanceUrl( RouteHelper.ResolveUrl(string.Format(CultureInfo.InvariantCulture, DesignerTemplate, "UseShared"), UrlResolveOptions.Rooted)); commandsList.Add( new WidgetMenuItem { Text = Res.Get<ContentBlockResources>().UseShared, ActionUrl = useSharedActionLink, NeedsModal = true }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<Labels>().Permissions, CommandName = "permissions", CssClass = "sfPermItm" }); return commandsList; }
private static IList<Func<string, string>> GetControllerPathTransformations(Controller controller, string customPath) { var packagesManager = new PackageManager(); var currentPackage = packagesManager.GetCurrentPackage(); var pathTransformations = new List<Func<string, string>>(); if (controller.RouteData != null && controller.RouteData.Values.ContainsKey("widgetName")) { var widgetName = (string)controller.RouteData.Values["widgetName"]; var controllerType = FrontendManager.ControllerFactory.ResolveControllerType(widgetName); var widgetVp = AppendDefaultPath(FrontendManager.VirtualPathBuilder.GetVirtualPath(controllerType)); pathTransformations.Add(FrontendControllerFactory.GetPathTransformation(widgetVp, currentPackage, widgetName)); } var controllerVp = customPath ?? AppendDefaultPath(FrontendManager.VirtualPathBuilder.GetVirtualPath(controller.GetType().Assembly)); pathTransformations.Add(FrontendControllerFactory.GetPathTransformation(controllerVp, currentPackage)); FrontendControllerFactory.AddDynamicControllerPathTransformations(controller, controllerVp, currentPackage, pathTransformations); var frontendVp = AppendDefaultPath(FrontendManager.VirtualPathBuilder.GetVirtualPath(typeof(FrontendControllerFactory).Assembly)); if (!string.Equals(controllerVp, frontendVp, StringComparison.OrdinalIgnoreCase)) { pathTransformations.Add(FrontendControllerFactory.GetPathTransformation(frontendVp, currentPackage)); } return pathTransformations; }
/// <summary> /// Initializes the widget commands. /// </summary> /// <returns> /// The <see cref="IList"/>. /// </returns> protected virtual IList<WidgetMenuItem> InitializeCommands() { var packageManager = new PackageManager(); var commandsList = new List<WidgetMenuItem>(); commandsList.Add( new WidgetMenuItem { Text = Res.Get<PageResources>().ZoneEditorAddPersonalizedVersion, CommandName = "addPersonalizedVersion", CssClass = "sfPersonalizeItm" }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<PageResources>().ZoneEditorRemovePersonalizedVersion, CommandName = "removePersonalizedVersion", CssClass = "sfRemPersonalizedItm sfSeparatorDown" }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<PageResources>().ZoneEditorEnablePageOverrideDisplayContenxtMenuInfo, CommandName = "displayWidgetOverrideText", CssClass = "sfDisplayText" }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<Labels>().Delete, CommandName = "beforedelete", CssClass = "sfDeleteItm" }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<Labels>().Duplicate, CommandName = "duplicate", CssClass = "sfDuplicateItm" }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<PageResources>().ZoneEditorEnablePageOverride, CommandName = "widgetOverride", CssClass = "sfWidgetOverrideItm" }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<PageResources>().ZoneEditorDisablePageOverride, CommandName = "widgetDisableOverride", CssClass = "sfWidgetOverrideItm" }); if (this.ResolveCurrentSitemapNode() != null) { commandsList.Add( new WidgetMenuItem { Text = Res.Get<PageResources>().ZoneEditorRollback, CommandName = "rollback", CssClass = "sfDisableWidgetOverrideItm" }); } if (this.SharedContentID == Guid.Empty) { var shareActionLink = packageManager.EnhanceUrl( RouteHelper.ResolveUrl(string.Format(CultureInfo.InvariantCulture, DesignerTemplate, "Share"), UrlResolveOptions.Rooted)); commandsList.Add( new WidgetMenuItem { Text = Res.Get<ContentBlockResources>().Share, ActionUrl = shareActionLink, NeedsModal = true }); } else { var unshareActionLink = packageManager.EnhanceUrl( RouteHelper.ResolveUrl(string.Format(CultureInfo.InvariantCulture, DesignerTemplate, "Unshare"), UrlResolveOptions.Rooted)); commandsList.Add( new WidgetMenuItem { Text = Res.Get<ContentBlockResources>().Unshare, ActionUrl = unshareActionLink, NeedsModal = true }); } var useSharedActionLink = packageManager.EnhanceUrl( RouteHelper.ResolveUrl(string.Format(CultureInfo.InvariantCulture, DesignerTemplate, "UseShared"), UrlResolveOptions.Rooted)); commandsList.Add( new WidgetMenuItem { Text = Res.Get<ContentBlockResources>().UseShared, ActionUrl = useSharedActionLink, NeedsModal = true }); commandsList.Add( new WidgetMenuItem { Text = Res.Get<Labels>().Permissions, CommandName = "permissions", CssClass = "sfPermItm" }); return commandsList; }
/// <summary> /// Gets the processed script. /// </summary> /// <remarks>The result will be cached.</remarks> /// <returns>The processed script.</returns> protected virtual string GetScript() { var currentPackage = new PackageManager().GetCurrentPackage() ?? string.Empty; var currentSiteId = this.GetCurrentSiteId(); var currentUserId = this.CurrentUserId.ToString(); var cacheKey = string.Format(CultureInfo.InvariantCulture, ServerContextHandler.ScriptCacheKeyPattern, currentPackage, currentSiteId, currentUserId); var cache = this.GetCacheManager(); var script = cache[cacheKey] as string; if (script == null) { lock (ServerContextHandler.scriptLock) { if (script == null) { script = this.GetRawScript() .Replace("{{applicationPath}}", this.GetApplicationPath()) .Replace("{{currentPackage}}", currentPackage) .Replace("{{frontendLanguages}}", this.GetFrontendLanguages()) .Replace("{{currentFrontendRootNodeId}}", this.CurrentFrontendRootNodeId.ToString()) .Replace("{{currentUserId}}", currentUserId) .Replace("{{isMultisiteMode}}", SystemManager.CurrentContext.IsMultisiteMode.ToString()); cache.Add( cacheKey, script, CacheItemPriority.Normal, null, this.GetCacheDependency(currentSiteId)); } } } return script; }
public static string WidgetContent(this UrlHelper helper, string contentPath, string assemblyName) { if (contentPath.IsNullOrEmpty()) throw new ArgumentNullException("contentPath"); if (string.IsNullOrEmpty(assemblyName)) return UrlHelpers.WidgetContent(helper, contentPath); var packagesManager = new PackageManager(); var packageName = packagesManager.GetCurrentPackage(); if (contentPath.StartsWith("~", StringComparison.Ordinal) || contentPath.StartsWith("/", StringComparison.Ordinal) || contentPath.Contains("://")) { var url = UrlTransformations.AppendParam(contentPath, PackageManager.PackageUrlParameterName, packageName); return helper.Content(url); } var resourceUrl = string.Format("~/{0}/{1}", FrontendManager.VirtualPathBuilder.GetVirtualPath(assemblyName), contentPath); var contentResolvedPath = UrlTransformations.AppendParam(resourceUrl, PackageManager.PackageUrlParameterName, packageName); return helper.Content(contentResolvedPath); }
public void GetCurrentPackage_FakeContext_VerifyThePackageNameIsCorrect() { //Arrange: Initialize the PackageManager and create fake HttpContextWrapper which has fake package name set as parameter in its parameters collection var packageManager = new PackageManager(); string packageName = string.Empty; var context = new HttpContextWrapper(new HttpContext( new HttpRequest(null, "http://tempuri.org", null), new HttpResponse(null))); context.Items[PackageManager.CurrentPackageKey] = "testPackageName"; //Act: Get the package name from the request parameters collection SystemManager.RunWithHttpContext(context, () => { packageName = packageManager.GetCurrentPackage(); }); //Assert: Verify if the manager properly strips all invalid characters Assert.AreEqual<string>("testPackageName", packageName, "The package name was not resolved correctly"); }
public void GetPackageVirtualPath_GivenPackage_VerifyTheVirtualPathIsCorrect() { //Arrange: Initialize the PackageManager and a fake package name var packageManager = new PackageManager(); string packageName = "fakePackageName"; string packageVirtualpath; //Act: gets the package virtual path packageVirtualpath = packageManager.GetPackageVirtualPath(packageName); //Assert: Verify if the manager throws an error if the parameter is null and if the package virtual path is correct try { packageManager.GetPackageVirtualPath(null); Assert.Fail("Expected exception was not thrown"); } catch { } Assert.AreEqual<string>(string.Format("~/{0}/{1}", PackageManager.PackagesFolder, packageName), packageVirtualpath, "Package virtual path is not correct"); }
public void StripInvalidCharacters_TitleWithInvalidCharacters_VerifyStringIsProperlyInvalidated() { //Arrange: Initialize the PackageManager and a fake package name var packageManager = new PackageManager(); string title = "fake\\/Title<Name>With:Invalid?Chars\"And*Symbols|Included"; string cleanedTitle; //Act: clean the title cleanedTitle = packageManager.StripInvalidCharacters(title); //Assert: Verify if the manager properly strips all invalid characters Assert.AreEqual<string>("fake_Title_Name_With_Invalid_Chars_And_Symbols_Included", cleanedTitle, "Title is not striped correctly"); }