Ejemplo n.º 1
0
        public void WhiteSpacePath_Throws()
        {
            var mockHttp = Mock.Of<HttpContextBase>();
            var file = new BasicFile(ClientDependencyType.Javascript) { FilePath = "  ", };

            Assert.Throws<ArgumentException>(() => file.ResolveFilePath(mockHttp));
        }
Ejemplo n.º 2
0
        public void AbsolutePath_IsUnaltered()
        {
            var mockHttp = Mock.Of<HttpContextBase>();

            var file = new BasicFile(ClientDependencyType.Javascript) { FilePath = "/file.js", };

            var resolvedPath = file.ResolveFilePath(mockHttp);

            Assert.AreEqual("/file.js", resolvedPath);
        }
Ejemplo n.º 3
0
        // those two methods below actually do the work
        // everything else above is just overloads

        /// <summary>
        /// Dynamically registers a dependency into the loader at runtime.
        /// This is similar to ScriptManager.RegisterClientScriptInclude.
        /// Registers a file dependency with the default provider.
        /// </summary>
        /// <param name="group">The dependencies group identifier.</param>
        /// <param name="priority">The dependency priority.</param>
        /// <param name="filePath">The dependency file.</param>
        /// <param name="pathNameAlias">The dependency files path alias.</param>
        /// <param name="type">The type of the dependency.</param>
        public void RegisterDependency(int group, int priority, string filePath, string pathNameAlias, ClientDependencyType type)
        {
            var file = new BasicFile(type)
            {
                Group = group, Priority = priority, FilePath = filePath, PathNameAlias = pathNameAlias
            };

            RegisterClientDependencies(new List <IClientDependencyFile> {
                file
            }, new List <IClientDependencyPath>());                                                                  //send an empty paths collection
        }
Ejemplo n.º 4
0
        public void RelativePath_HasCurrentExecutionPathPrefixed()
        {
            var mockHttp = Mock.Of<HttpContextBase>();
            Mock.Get(mockHttp).DefaultValue = DefaultValue.Mock;
            Mock.Get(mockHttp.Request).Setup(r => r.AppRelativeCurrentExecutionFilePath).Returns("/the/path/page.aspx");

            var file = new BasicFile(ClientDependencyType.Javascript) { FilePath = "file.js", };

            var resolvedPath = file.ResolveFilePath(mockHttp);

            Assert.AreEqual("/the/path/file.js", resolvedPath);
        }
Ejemplo n.º 5
0
        public void TildePath_IsResolved()
        {
            var mockHttp = Mock.Of<HttpContextBase>();
            Mock.Get(mockHttp).DefaultValue = DefaultValue.Mock;
            Mock.Get(mockHttp.Request).Setup(r => r.ApplicationPath).Returns("/");

            var file = new BasicFile(ClientDependencyType.Javascript) { FilePath = "~/file.js", };

            var resolvedPath = file.ResolveFilePath(mockHttp);

            Assert.AreEqual("/file.js", resolvedPath);
        }
Ejemplo n.º 6
0
        public void RegisterDependency(int group, int priority, string filePath, string pathNameAlias, ClientDependencyType type, object htmlAttributes)
        {
            var file = new BasicFile(type)
            {
                Group = group, Priority = priority, FilePath = filePath, PathNameAlias = pathNameAlias
            };

            //now add the attributes to the list
            foreach (var d in htmlAttributes.ToDictionary())
            {
                file.HtmlAttributes.Add(d.Key, d.Value.ToString());
            }

            RegisterClientDependencies(new List <IClientDependencyFile> {
                file
            }, new List <IClientDependencyPath>());                                                                  //send an empty paths collection
        }
Ejemplo n.º 7
0
 protected bool Equals(BasicFile other)
 {
     return(string.Equals(FilePath, other.FilePath, StringComparison.InvariantCultureIgnoreCase) && DependencyType == other.DependencyType && Priority == other.Priority && Group == other.Group && string.Equals(PathNameAlias, other.PathNameAlias, StringComparison.InvariantCultureIgnoreCase) && string.Equals(ForceProvider, other.ForceProvider) && Equals(HtmlAttributes, other.HtmlAttributes));
 }
Ejemplo n.º 8
0
        public void RegisterDependency(int group, int priority, string filePath, string pathNameAlias, ClientDependencyType type, object htmlAttributes, string provider, bool forceBundle)
        {
            var file = new BasicFile(type)
            {
                Group = group,
                Priority = priority,
                FilePath = filePath,
                PathNameAlias = pathNameAlias,
                ForceProvider = provider,
                ForceBundle = forceBundle
            };

            //now add the attributes to the list
            foreach (var d in htmlAttributes.ToDictionary())
            {
                file.HtmlAttributes.Add(d.Key, d.Value.ToString());
            }

            RegisterClientDependencies(new List<IClientDependencyFile> { file }, new List<IClientDependencyPath>()); //send an empty paths collection
        }
Ejemplo n.º 9
0
		// those two methods below actually do the work
		// everything else above is just overloads

		/// <summary>
		/// Dynamically registers a dependency into the loader at runtime.
		/// This is similar to ScriptManager.RegisterClientScriptInclude.
		/// Registers a file dependency with the default provider.
		/// </summary>
		/// <param name="group">The dependencies group identifier.</param>
		/// <param name="priority">The dependency priority.</param>
		/// <param name="filePath">The dependency file.</param>
		/// <param name="pathNameAlias">The dependency files path alias.</param>
		/// <param name="type">The type of the dependency.</param>
		public void RegisterDependency(int group, int priority, string filePath, string pathNameAlias, ClientDependencyType type)
        {
            var file = new BasicFile(type) { Group = group, Priority = priority, FilePath = filePath, PathNameAlias = pathNameAlias };
            RegisterClientDependencies(new List<IClientDependencyFile> { file }, new List<IClientDependencyPath>()); //send an empty paths collection
        }
Ejemplo n.º 10
0
        public void NonCanonicalAbsolutePath_IsCanonicalized()
        {
            var mockHttp = Mock.Of<HttpContextBase>();
            var file = new BasicFile(ClientDependencyType.Javascript) { FilePath = "/website/folder/../js.js", };

            var resolvedPath = file.ResolveFilePath(mockHttp);

            Assert.AreEqual("/website/js.js", resolvedPath);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Replaces the content with the new js/css paths
        /// </summary>
        /// <param name="html"></param>
        /// <param name="namedGroup"></param>
        /// <param name="extensions"></param>
        /// <param name="type"></param>
        /// <param name="regex"></param>
        /// <param name="http"></param>
        /// <returns></returns>
        /// <remarks>
        /// For some reason ampersands that aren't html escaped are not compliant to HTML standards when they exist in 'link' or 'script' tags in URLs,
        /// we need to replace the ampersands with &amp; . This is only required for this one w3c compliancy, the URL itself is a valid URL.
        /// </remarks>
        private static string ReplaceContent(string html, string namedGroup, string[] extensions,
            ClientDependencyType type, string regex, HttpContextBase http)
        {
            html = Regex.Replace(html, regex,
                (m) =>
                {
                    var grp = m.Groups[namedGroup];

                    //if there is no namedGroup group name or it doesn't end with a js/css extension or it's already using the composite handler,
                    //the return the existing string.
                    if (grp == null
                        || string.IsNullOrEmpty(grp.ToString())
                        || !grp.ToString().EndsWithOneOf(extensions)
                        || grp.ToString().StartsWith(ClientDependencySettings.Instance.CompositeFileHandlerPath))
                        return m.ToString();

                    
                    //make sure that it's an internal request, though we can deal with external 
                    //requests, we'll leave that up to the developer to register an external request
                    //explicitly if they want to include in the composite scripts.
                    try
                    {
                        var url = new Uri(grp.ToString(), UriKind.RelativeOrAbsolute);
                        if (!url.IsLocalUri(http))
                            return m.ToString(); //not a local uri        
                        else
                        {
                           
                            var dependency = new BasicFile(type) { FilePath = grp.ToString() };

                            var file = new[] { new BasicFile(type) { FilePath = dependency.ResolveFilePath(http) } };

                            var resolved = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.ProcessCompositeList(
                                file,
                                type,
								http).Single();

                            return m.ToString().Replace(grp.ToString(), resolved.Replace("&", "&amp;"));
                        }
                    }
                    catch (UriFormatException)
                    {
                        //malformed url, let's exit
                        return m.ToString();
                    }

                },
                RegexOptions.Compiled);

            return html;
        }
Ejemplo n.º 12
0
 protected bool Equals(BasicFile other)
 {
     return string.Equals(FilePath, other.FilePath, StringComparison.InvariantCultureIgnoreCase) && DependencyType == other.DependencyType && Priority == other.Priority && Group == other.Group && string.Equals(PathNameAlias, other.PathNameAlias, StringComparison.InvariantCultureIgnoreCase) && string.Equals(ForceProvider, other.ForceProvider) && Equals(HtmlAttributes, other.HtmlAttributes);
 }